This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Struts and the fly likes Probelom in Manual Validation method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Probelom in Manual Validation method" Watch "Probelom in Manual Validation method" New topic
Author

Probelom in Manual Validation method

vasu devan
Ranch Hand

Joined: Apr 14, 2005
Posts: 38
Dear Friends,

I am new to Struts, and using Struts 1.1
Here i encounter probelom while using Validate method in Form,following are the Details

1.ValidationAction -> Action class
2.ValidationForm ->Form class

Following are the Syntex that is used in ValidationAction class

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
{
ActionErrors errors= new ActionErrors();

if(isMissing(getName()))
errors.add("name",new ActionMessage("name.required"));

if(isMissing(getPlace()))
errors.add("place",new ActionMessage("place.required"));

return(errors);

}

in struts-config.xml ths configuration lookes like this

<form-bean name="ValidationForm"
type="manualvalidation.ValidationForm" />

.
.
<actionpath="/Validation"
type="manualvalidation.ValidationAction"
name="ValidationForm"
scope="request"
validate="true"
input="/validation/Validation.jsp">
<forward name="success" path="/validation/success.jsp" />

</action>

<message-resources parameter="MessageResources" />

When i Accessed the page and given submit,
it return the following error in browser

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.ClassCastException
org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
org.apache.jsp.validation.Validation_jsp._jspx_meth_html_errors_0(Validation_jsp.java:129)
org.apache.jsp.validation.Validation_jsp._jspx_meth_html_html_0(Validation_jsp.java:101)
org.apache.jsp.validation.Validation_jsp._jspService(Validation_jsp.java:71)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:274)
org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1012)
org.apache.struts.tiles.TilesRequestProcessor.internalModuleRelativeForward(TilesRequestProcessor.java:345)
org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:980)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:255)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

i Dont know how to fix the above probelom

Guide me to resolve the probelom

Thanks in advance
Regards,
vasu
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Since you're using Struts 1.1, you need to populate your ActionErrors object with objects of type ActionError, not ActionMessage. The way you've done it is correct for Struts 1.2, but not for 1.1.


Merrill
Consultant, Sima Solutions
vasu devan
Ranch Hand

Joined: Apr 14, 2005
Posts: 38
Dear Merill,

Thanks for the Reply,
its working fine after changed to ActionError

cheers
vasu
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Probelom in Manual Validation method