Struts: How to handle server side validation when using dynamic forms!!!

Posted on 2006-07-13
Last Modified: 2013-11-24
Hi! I am using struts 1.2 and is new to struts. Since I am using dynamic forms how do I do server side validation? I mean, I want to authenticate username and password from my form against the database. ( The client side validation is done with the validator framework. ) Should I do that in my Action class? And, if I do the authentication in the action class how do I set the action error object if there is an error to come back to the form and print it. Note: I am using hibernate as my ORM tool. The other question is: why is my client side validation not working?

here is my jsp:
    <html:base />
       <html:javascript formName="loginFormBean" dynamicJavascript="true"
<html:form action="/login" method="post" onsubmit="return validateLoginFormBean(this);">
      <table border="0">
          <td><html:text property="username" size="15" maxlength="30"/></td>
          <td><html:text property="password"/></td>
          <td colspan="2" align="center">

Here is the class

public class LoginAction extends Action {
    // --------------------------------------------------------- Instance Variables
    protected final Log logger = LogFactory.getLog(getClass());
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                    HttpServletRequest request, HttpServletResponse response) {
            DynaActionForm loginForm = (DynaActionForm) form;
            // TODO Auto-generated method stub
  "Forwarding from login action class");
            return mapping.findForward("success");


Here are the relevant mappings in struts-config:

      <form-bean name="loginFormBean"  type="org.apache.struts.validator.DynaValidatorActionForm">
      <form-property name="username" type="java.lang.String"/>
      <form-property name="password" type="java.lang.String"/>
      <forward name="success" path="/jsp/showmenu.jsp"/>


Here is my validation.xml:

 <form name="loginFormBean">
    <field property="username" depends="required, minlength">
       <arg key="loginFormBean.username"/>
    <field property="password" depends="required,mask,minlength">
         <arg key="loginFormBean.password"/>

1) how do I set the action error object in my loginAction class if there is an error with authentication?

2) Some how the client side validation is trigerring, without any error. I mean even if I do enter anything in the textbox and click submit, I am being forwarded to the next page (showmenu.jsp)

I think I am missing something small for my second problem........
Question by:subirc
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2

Expert Comment

ID: 17097553
In form beans you are doing wrong

Inseted of <form-bean name="loginFormBean"  type="org.apache.struts.validator.DynaValidatorActionForm"> write

<form-bean name="loginFormBean"  type="org.apache.struts.validator.DynaValidatorForm">

For further reference go thru follwinglink StrutsValidationFramework_speakernoted.pdf

Hope this will solve your problem :)


Author Comment

ID: 17097723
No still not working!!!  When I am clicking submit (without entering anything in username + password) a error pops up saying

error: _required is undefined
Somewhere that underscore is coming....


Expert Comment

ID: 17098765

Can you post complete error trace.. so we can go thru easily..

Author Comment

ID: 17105924
I think I have solved the problem another way. I am writing all my client side validation in the Action Class itself using Action Messages. The server side is also done there. There is no error trace unfortunately. It's that when I was clicking on submit it was forwarding to the success page without doing any validation. You already have seen my validation.xml and struts-config. How do I get back my points?


Accepted Solution

Netminder earned 0 total points
ID: 17157334
Closed, 40 points refunded.
Site Admin

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
web application structure 18 114
Chrome and Firefox Java 5 68
Setup GlassFish 4 35
batch vs regular insert in spring DAO 2 23
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question