*
The moose likes Struts and the fly likes Struts validation framework- for single form, multiple actions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts validation framework- for single form, multiple actions" Watch "Struts validation framework- for single form, multiple actions" New topic
Author

Struts validation framework- for single form, multiple actions

Palayoor Thomas
Greenhorn

Joined: Nov 16, 2006
Posts: 3
I have three struts actions and a single form bean. I am declaring three different form-beans in the struts-config.xml with three different form names for the same form bean java class. How can I validate the forms using the struts validator framework?

My struts-config.xml will look like this:

#########################################################################
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans>
<form-bean name="customerRegistrationForm"
type="com.sag.form.CustomerRegistrationForm">
<form-property name="customerId" type="java.lang.String" />
<form-property name="customerName" type="java.lang.String" />
<form-property name="customerAddress"
type="java.lang.String" />
<form-property name="customerParentId"
type="java.lang.String" />
<form-property name="countryId" type="java.lang.String" />
<form-property name="clientDivision"
type="java.lang.String" />
</form-bean>
<form-bean name="projectRegistrationForm"
type="com.sag.form.CustomerRegistrationForm">
<form-property name="projectName" type="java.lang.String" />
<form-property name="projectType" type="java.lang.String" />
<form-property name="technology" type="java.lang.String" />
<form-property name="sbu" type="java.lang.String" />
<form-property name="projectProfiles"
type="java.lang.String" />
<form-property name="onsiteOffshore"
type="java.lang.String" />
<form-property name="noOfResources" type="java.lang.String" />
</form-bean>
<form-bean name="proposalRegistrationForm"
type="com.sag.form.CustomerRegistrationForm">
<form-property name="proposalSerialNumber"
type="java.lang.String" />
<form-property name="proposalNumber"
type="java.lang.String" />
<form-property name="quarter" type="java.lang.String" />
<form-property name="month" type="java.lang.String" />
<form-property name="salesContact" type="java.lang.String" />
<form-property name="sagContact" type="java.lang.String" />
<form-property name="deliveryContact"
type="java.lang.String" />
<form-property name="proposalValue" type="java.lang.String" />
<form-property name="currencyCode" type="java.lang.String" />
<form-property name="USDinMillion" type="java.lang.String" />
<form-property name="proposalSummary"
type="java.lang.String" />
<form-property name="customerWinQuarter"
type="java.lang.String" />
<form-property name="clientRegion" type="java.lang.String" />
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="getName" path="/pages/registration.jsp" />
</global-forwards>
<action-mappings>
<action input="/pages/registration.jsp"
name="customerRegistrationForm" path="/registerCustomer"
scope="session" type="com.sag.action.CustomerRegisterAction"
validate="true">
<forward name="success" path="/pages/registration.jsp" />
<forward name="failure" path="/pages/customer.jsp" />
</action>
<action input="/pages/registration.jsp"
name="projectRegistrationForm" path="/registerProject"
scope="session" type="com.sag.action.ProjectRegistrationAction"
validate="true">
<forward name="success" path="/pages/registration.jsp" />
<forward name="failure" path="/pages/customer.jsp" />
</action>
<action input="/pages/registration.jsp"
name="proposalRegistrationForm" path="/registerProposal"
scope="session" type="com.sag.action.ProposalRegistrationAction"
validate="true">
<forward name="success" path="/pages/registration.jsp" />
<forward name="failure" path="/pages/customer.jsp" />
</action>
<action input="/pages/registration.jsp"
name="customerRegistrationForm" path="/register" scope="session"
type="com.sag.action.CustomerRegisterAction">
<forward name="success" path="/pages/registration.jsp" />
<forward name="failure" path="/pages/customer.jsp" />
</action>
</action-mappings>
<controller />
<message-resources parameter="ApplicationResources" />
<plug-in className="org.apache.struts.tiles.TilesPlugin">
<set-property property="definitions-config"
value="/WEB-INF/tiles-defs.xml" />
</plug-in>
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in>
</struts-config>
##########################################################################


Inside my jsp for the form, I am declaring the script for enabling the client side alert as:


#####################################################################
<html:javascript formName="customerRegistrationForm"
method="validateForm" dynamicJavascript="true" staticJavascript="false"
cdata="false" />
<html:javascript formName="projectRegistrationForm"
method="validateForm" dynamicJavascript="true" staticJavascript="false"
cdata="false" />
<html:javascript formName="proposalRegistrationForm"
method="validateForm" dynamicJavascript="true" staticJavascript="false"
cdata="false" />

##########################################################
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Moving this to our Struts forum.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Manuel Jordan
Ranch Hand

Joined: Sep 29, 2006
Posts: 131
Hello Palayoor

i think that this
link
is the solution
read carefully all the document

regards


kill your pride, share your knowledge with all
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Struts validation framework- for single form, multiple actions
 
Similar Threads
Struts Validator Framework error
Struts:: referring indexId of logic:iterate from javascript call
Problem with Validator Framework
Help:client validation on struts multi-page
STRUTS: client-side validation in jsp using DynaValidatorForm