aspose file tools*
The moose likes Struts and the fly likes weird validation issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "weird validation issue" Watch "weird validation issue" New topic
Author

weird validation issue

subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
I have a jsp page that I need to validate .I have set validate to true in my struts-config.still the action is invoked before the validation
Any ideas what could be wrong

Posting snippets of struts config:
<action path="/viewAirRates" type="au.com.xbnet.rates.actions.AirRateAction" input="/AirRateEditor.jsp" name="AirRateEditorForm" parameter="dispatchaction" validate="true" >
<forward name="SHOW_RATES" path=".xbnet.rates.AirFreightRateEditor"/>
<forward name="NO_RATES_FOR_COMPANY" path=".xbnet.rates.AirFreightRateEditor"/>
</action>

JSP
<html:javascript formName="AirRateEditorForm" dynamicJavascript="true" staticJavascript="true" />

<html:form action="/viewAirRates" method="post" onsubmit="return validateAirRateEditorForm(this);">

validation.xml
<form name="AirRateEditorForm">
<field property="wt" depends="required,float">

<arg0 key="xbnet.rates.wt"/>
</field>
<field property="kgs" depends="required,integer" >
<arg0 key="xbnet.rates.kgs"/>
</field>
<field property="l" depends="required,float" >
<arg0 key="xbnet.rates.l"/>
</field>
<field property="b" depends="required,float" >
<arg0 key="xbnet.rates.b"/>
</field>
<field property="h" depends="required,float" >
<arg0 key="xbnet.rates.h"/>
</field>
<field property="vol" depends="required,float" >
<arg0 key="xbnet.rates.vol"/>
</field>

<field property="total" depends="required,float">
<arg0 key="xbnet.rates.t"/>
</field>
</form>

View source from JSP
var formValidationResult;
formValidationResult = validateRequired(form) && validateFloat(form) && validateInteger(form);
return (formValidationResult == 1);
}

function AirRateEditorForm_required () {
this.a0 = new Array("wt", "Weight is required.", new Function ("varName", " return this[varName];"));
this.a1 = new Array("kgs", "Quantity in kgs is required.", new Function ("varName", " return this[varName];"));
this.a2 = new Array("l", "Length in cms is required.", new Function ("varName", " return this[varName];"));
this.a3 = new Array("b", "Breadth in cms is required.", new Function ("varName", " return this[varName];"));
this.a4 = new Array("h", "Height in cms is required.", new Function ("varName", " return this[varName];"));
this.a5 = new Array("vol", "Volume in cubic centimeter is required.", new Function ("varName", " return this[varName];"));
this.a6 = new Array("total", "Total value is required.", new Function ("varName", " return this[varName];"));
}

function AirRateEditorForm_FloatValidations () {
this.a0 = new Array("wt", "Weight should be a decimal or a number", new Function ("varName", " return this[varName];"));
this.a1 = new Array("l", "Length in cms should be a decimal or a number", new Function ("varName", " return this[varName];"));
this.a2 = new Array("b", "Breadth in cms should be a decimal or a number", new Function ("varName", " return this[varName];"));
this.a3 = new Array("h", "Height in cms should be a decimal or a number", new Function ("varName", " return this[varName];"));
this.a4 = new Array("vol", "Volume in cubic centimeter should be a decimal or a number", new Function ("varName", " return this[varName];"));
this.a5 = new Array("total", "Total value should be a decimal or a number", new Function ("varName", " return this[varName];"));
}

Any help greatly appreciated.Am presently tearing my hair out with this....
regards
subu
Preeti Jain
Ranch Hand

Joined: Jun 08, 2005
Posts: 57
Have you put the plugin for Validator in the struts-config.xml?
[ December 29, 2005: Message edited by: Preeti Jain ]
subu ananthram
Ranch Hand

Joined: May 16, 2004
Posts: 102
yep
Preeti Jain
Ranch Hand

Joined: Jun 08, 2005
Posts: 57
Why dont you put an alert in the validateRequired function that is in the validator-rules.xml file and see if control goes there?

Also, try putting scope="session" in the action element of struts-config.xml. It shouldn't make any difference but you can try..

I hope your form beans are extending ValidatorForm and not ActionForm
[ December 29, 2005: Message edited by: Preeti Jain ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: weird validation issue