This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread 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


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
 
GeeCON Prague 2014
 
subject: Probelom in Manual Validation method