Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts 1.2.7 Validation blues

 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have wasted many hours on trying to solve this one:

- working with struts 1.2.7, Resin 3.0.14, jdk1.4.

Want to implement Struts validation using validation.xml.

I have a simple Loginform with 2 fields (LoginForm.java), registered in struts-config.xml:

<form-bean name="LoginForm" type="nl.upi.workmate.struts.umba.LoginForm" >
<form-property name="userId" type="java.lang.String" />
<form-property name="passWord" type="java.lang.String" />
</form-bean>

� and corresponding action:

<action
path="/loginDemo"
type="nl.upi.workmate.struts.umba.LoginAction"
name="LoginForm"
input="/jsp/LoginView.jsp"
validate="true">
<forward name="valid" path="/jsp/MainMenu.jsp" />
<forward name="invalid" path="/jsp/LoginView.jsp" />
</action>


I defined the plugin in struts-config.xml:

<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>
</plug-in>


Then why does it not work ??!!
BTW: it does work under Struts 1.1.

When I press submit in the Loginform I get this in the Resin-console:

[22:05:26.256] Server[] starting
[22:05:26.286] http listening to *:80
[22:05:26.316] hmux listening to localhost:6802
[22:05:26.356] Host[] starting
[22:05:26.447] WebApp[http://localhost:80] starting
[22:05:27.027] In-place class redefinition (HotSwap) is not available. In-place class reloading during development requ
ires a compatible JDK and -Xdebug.
[22:05:27.057] WebApp[http://localhost:80/workmate] starting
[22:05:27.758] action: init
** LoginForm.setUserId() <-- ActionForm gets called
** LoginForm.setPassWord()
[22:05:35,129] ERROR ValidatorForm:112 - org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Object, org.
apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErrors, jav
ax.servlet.http.HttpServletRequest)
org.apache.commons.validator.ValidatorException: org.apache.struts.validator.FieldChecks.validateRequired(java.lang.Obje
ct, org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionErr
ors, javax.servlet.http.HttpServletRequest)

at org.apache.commons.validator.ValidatorAction.loadValidationMethod(ValidatorAction.java:627)
at org.apache.commons.validator.ValidatorAction.executeValidationMethod(ValidatorAction.java:557)
at org.apache.commons.validator.Field.validateForRule(Field.java:827)
at org.apache.commons.validator.Field.validate(Field.java:906)
at org.apache.commons.validator.Form.validate(Form.java:174)
at org.apache.commons.validator.Validator.validate(Validator.java:367)
at org.apache.struts.validator.ValidatorForm.validate(ValidatorForm.java:110)
at org.apache.struts.action.RequestProcessor.processValidate(RequestProcessor.java:928)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:204)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:154)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:92)
at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:99)
at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:163)
at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:208)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:259)
at com.caucho.server.port.TcpConnection.run(TcpConnection.java:363)
at com.caucho.util.ThreadPool.runTasks(ThreadPool.java:490)
at com.caucho.util.ThreadPool.run(ThreadPool.java:423)
at java.lang.Thread.run(Thread.java:534)
LoginAction.execute() <-- Action object should not be called since validation failed
LoginAction.execute() - einde
LoginAction.execute() - invalid
** LoginForm.getUserId()
** LoginForm.getPassWord()


Please help me out on this one !!

Thanks in advance.

[ July 25, 2005: Message edited by: Jan van Doorn ]
[ July 25, 2005: Message edited by: Jan van Doorn ]
 
alan do
Ranch Hand
Posts: 354
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ActionErrors/ActionError are deprecated since 1.2.x. it looks like you may have validator-rules.xml file (old) that is still defining validator rules using these classes. change these to ActionMessages/ActionMessage instead.
 
Jan van Doorn
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem solved !

Reason: there were no corresponding error messages in the Resource file.

<validator name="required"
classname="org.apache.struts.validator.FieldChecks"
method="validateRequired"

Looking at an entry in validator-rules.xml:

methodParams="java.lang.Object,org.apache.commons.validator.ValidatorAction, org.apache.commons.validator.Field, org.apache.struts.action.ActionMessages,org.apache.commons.validator.Validator, javax.servlet.http.HttpServletRequest"
msg="errors.required"/>

... I now understand the exception.

The error was caused because I had no entry for errors.required



[ July 26, 2005: Message edited by: Jan van Doorn ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic