This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

STRUTS VALIDATOR FRAMEWORK

 
Mohd Junaid Khan
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am new to struts framework . I am developing a web application and i need to use validator framework to validate the input provided by the User...... The problem i am facing here is if there is any error (user provides wrong input) then the error messages are being displayed but i am unable to hold the invalid data entered by the user...... and moreover all my fields get empty if user provides wrong value in only one field................. can any one please tell me what to do..................


1----------plugin tag in struts-config.xml is
<!DOCTYPE
struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
..
.
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property
property="pathnames"
value="/org/apache/struts/validator/validator-rules.xml,
/WEB-INF/validation.xml"/>
</plug-in>
-----------------------------
2--------- validation.xml


<form-validation>
<formset>
<form name="loginForm1">
<field property="userLoginID" depends="required">
<arg key="inputForm.userLoginID"/>
</field>

<field property="password" depends="required">
<arg key="inputForm.password"/>
</field>
</form>
</formset>
</form-validation>
----------------------------------------

3.-------------------------Action Mapping

<form-beans>
<!-- ========== Form Bean Definitions ================================ -->
<form-bean name="loginForm1"
type="net.sample.ui.form.LoginForm" />
</form-beans>
<action-mappings>
<action path="/signIn"
type="net.sample.ui.actionclass.SignInAction"
name="loginForm1"
scope="request"
input="/jsp/common/login.jsp"
validate="true">
<forward name="ACTION_FORWARD_SUCCESS"
path="/jsp/common/home.jsp" />
</action>
</action-mappings>
----------------------------------------

4--------------- FormBean
package net.sample.ui.form;
public class LoginForm extends ValidatorForm{
public LoginForm() {
}
private String userID;
private String password;
public String getUserID() {
return userID;
}

/**
* @param userID the userID to set
*/
public void setUserID(String userID) {
this.userID = userID;
}

/**
* @return the password
*/
public String getPassword() {
return password;
}

/**
* @param password the password to set
*/
public void setPassword(String password) {
this.password = password;
}
}

----------------------------------------
5.-------------Action Class

contains only one statement inside execute function

return map.findForward("ACTION_FORWARD_SUCCESS");


--------------------

I tried all the possible things i could do......... but in vain
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic