hi,
when i am submitting twice only i am able to go to next page.in jsf
note
1) if we give right values in dates then there is no problem.
2) if we give r fromdate is grater than to date
then validation error comes.
3)even though we rectify that no validation error comes but the values are
not submitted so we again have to submitted.
what is the error in my code
jsp page
<h:outputText id="dates" value="ENTER THE DATE (DD:MON:YYYY:HH24)
FORMAT"/><br>
<h:outputText id="fromdateTEXT" value="FROMDATE"/>
<h:panelGroup>
<h:inputText id="fromdate"
value="#{HRselforeachappvm.fromDate}"
validator="#{HRselforeachappvm.fromDateValidate}" size="14"
required="true"/>
<h:message for="fromdate" style="color:red"/>
</h:panelGroup> <br>
<h:outputText id="todatetext" value="TODATE"/>
<h:panelGroup>
<h:inputText id="todate" value="#{HRselforeachappvm.toDate}"
validator="#{HRselforeachappvm.toDateValidate}" required="true"
size="14">
</h:inputText>
<h:message for="todate" style="color:red"/>
</h:panelGroup> <br>
<h:commandButton action="#{HRselforeachappvm.showreport}"
value="showreports"/>
code in backing bean
public void setToDate(String todate){
this.todate=todate;
}
public String getToDate(){
return todate;
}
public void setFromDate(String fromdate){
this.fromdate=fromdate;
}
public String getFromDate(){
return fromdate;
}
public void fromDateValidate(FacesContext context, UIComponent component,
Object value)throws ValidatorException{
try{
date1=(String)value;
System.out.println(date1);
SimpleDateFormat sdf=new SimpleDateFormat("dd:MMM:yyyy:HH");
fdate =sdf.parse(date1);
}
catch(Exception e){
message= new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setDetail("INVALID FORMAT");
message.setSummary("INVALID FORMAT");
throw new ValidatorException(message);
}
}
public void toDateValidate(FacesContext context, UIComponent component,
Object value)throws ValidatorException{
try{
date2=(String)value;
System.out.println(date2);
System.out.println("date1 value is"+date1);
SimpleDateFormat sdf=new SimpleDateFormat("dd:MMM:yyyy:HH");
tdate= sdf.parse(date2);
}
catch(Exception e){
message= new FacesMessage();
message.setSeverity(FacesMessage.SEVERITY_ERROR);
message.setDetail("INVALID FORMAT");
message.setSummary("INVALID FORMAT");
throw new ValidatorException(message);
}
}
public String showreport(){
System.out.println("to date is "+tdate);
System.out.println("from date is "+fdate);
if(!(tdate.after(fdate))){
FacesContext context=FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage("TODATE IS ALWAYS GREATER THAN
FROM DATE");
message.setDetail("TODATE IS ALWAYS GREATER THAN FROM DATE");
message.setSummary("TODATE IS ALWAYS GREATER THAN FROM DATE");
context.addMessage("HRselforeachappVm", message);
return "failure";
}
return "showreport";
}
--
View this message in context:
http://www.nabble.com/problem-with-submitting-a-form-urgent-tf2002171.html#a5498009
Sent from the MyFaces - Users forum at Nabble.com.