retaining updated date which was initialized to current date and then changed

I'm in a quandry,  my JSP ( Lead Entry form requesting name , address, phone....& contact Date)  sets Contact Date to the current date; users have the option of back-dating.  If there are no page errors issued via Struts Validator , this works well.  BUT, when errors occur ( ex: need phone number ) the date is reset back to current date because of the date initialialization at the top of the page.   Please let me know how i can retain this changed date.   Here's my code and please be explicit because I'm a beginner. THANKS for your time.. ( i've eliminated most of the code to make it easier for you to review)


Beginning of Page
 
<%
      java.util.Date cntctDate = new Date(); //gets the current date
      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM-dd-yyyy");
      String dateAsString = sdf.format(cntctDate );
%>


function keepContactDate() {
      leadForm.KeepContactDate.value = leadForm.contactDate;
}

function checkContactDate() {
      leadForm.contactDate = leadForm.KeepContactDate.value;
}

Contact Date
<td class="label">Contact Date</td>
<td>                                                                  <input type=text class="textBox" name="contactDate"   maxlength="10" size="10" tabindex="32" value="<%=dateAsString%>" onchange="keepContactDate()" />                                          
</td>

                                                
</html:form>
<script language="JavaScript">
        var   dummy1 = checkContactDate();
</script>
</body>
</html:html>




VKopaczAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

KuldeepchaturvediCommented:
<%
String dateAsString =yourbean.getContactDate();
if(dateAsString==null || dateAsString.length()<=0)
{
     java.util.Date cntctDate = new Date(); //gets the current date
     java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM-dd-yyyy");
dateAsString = sdf.format(cntctDate );
}
%>

bloodredsunCommented:
I would take the scriptlet out of the JSP and do the Date initialisation in the actionform constructor. This means that the first time it is called, the date will be displayed but then if the page fails validation, the new updated value is displayed which avoids your issue witht the date being replaced :-)
bloodredsunCommented:
Sorry, I've just realised that I read your use of the struts validator meant that you are using Struts. Is this true or are you just using the validator?
Announcing the Winners!

The results are in for the 15th Annual Expert Awards! Congratulations to the winners, and thank you to everyone who participated in the nominations. We are so grateful for the valuable contributions experts make on a daily basis. Click to read more about this year’s recipients!

VKopaczAuthor Commented:
Yes , we are using struts , not just the validator.  
bloodredsunCommented:
Then it's easy, use the contructor as described above.
VKopaczAuthor Commented:
Kuldeep

thanks for your attempt,   the code your forwarded  presents a compile error  

here is your code with yourbean replaced by leadForm

<%
String dateAsString =leadForm.getContactDate();
if(dateAsString==null || dateAsString.length()<=0)
{
     java.util.Date cntctDate = new Date(); //gets the current date
     java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM-dd-yyyy");
dateAsString = sdf.format(cntctDate );
}
%>

Error 500: Unable to compile class for JSP An error occurred between lines: 10 and 18 in the jsp file: /WEB-INF/jsp/leadentry.jsp Generated servlet error: C:\Starteam\ProLeads\DEV\Source code\.metadata\.plugins\com.ibm.etools.server.core\tmp0\cache\localhost\server1\ProLeads\ProLeadsWeb.war\WEB-INF\jsp\_leadentry.java:444: cannot resolve symbol symbol : variable leadForm location: class org.apache.jsp._leadentry String dateAsString =leadForm.getContactDate(); ^ 1 error


SOoooo anyway,   I have now tried the following code , which successfully retains an updated date when page errors occur, BUT  brings back same updated date on a new entry from rather than the current date via the getParamater. I've tried to reset  

<%
String dateAsString = "";
if ("".equals((String) request.getParameter("contactDate"))|| request.getParameter("contactDate") == null)
{
java.util.Date cntctDate = new Date(); //gets the current date
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("MM-dd-yyyy");
dateAsString = sdf.format(cntctDate );
}
else
{
dateAsString = (String) request.getParameter("contactDate");
}
%>


&&&&  I've  tried to empty the parameter in our createLead action class, but the updated date still appears on a new entry form???

request.getSession().setAttribute("contactPage","");
            }
        return mapping.findForward("leadEntry");
    }



thanks again
VKopaczAuthor Commented:
thanks bloodredsun
BUT can you be more specific ---  do you mean the initial statement  in the struts-config file?  

thanks again for your time


<form-bean name="leadForm" type="com.metlife.proleads.form.LeadForm">
                  <display-name>Lead Form</display-name>
                  <form-property name="contactDate" type="java.lang.String" initial="" />      
VKopaczAuthor Commented:
THANKS  for the tips,  but I've added the following code which  calls the superclass'
implementation of intialize ( implemented by
dynavalidation form which is extended by our form)  and the date is initialized properly as well as retained when changed

public void initialize(ActionMapping mapping) {
   super.initialize(mapping);

   java.util.Date cntctDate = new Date(); //gets the current
date
   java.text.SimpleDateFormat sdf = new
   java.text.SimpleDateFormat("MM-dd-yyyy");
   set("contactDate", sdf.format(cntctDate );
}
bloodredsunCommented:
I have no problems with this recommendation
moduloCommented:
Closed, 500 points refunded.
modulo
Community Support Moderator

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JSP

From novice to tech pro — start learning today.