This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Validation fetching rules from Database Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Validation fetching rules from Database" Watch "Validation fetching rules from Database" New topic
Author

Validation fetching rules from Database

Rammohan Bandakunta
Greenhorn

Joined: Aug 17, 2005
Posts: 9
Hi,
I have some javascript Functions which are for basic validations like length ,numeric but I have some set of Rules that I need to Fetch in, when a dropdown is selected in the Front End,thus the length rules changes with mask and other parameters.

1>should i store these Rules in the Database and Fetch using DAO in to Action Form and the Front End.
2>should i Hardcode all the Function in the Front end and validate onChange submit with the Dropdown.

or Can I use the Validaation Framework which struts seems to offer,I am not sure how the validation Framework really works.

Suggest please..
Kerry Wilson
Ranch Hand

Joined: Oct 29, 2003
Posts: 254
Definitely use validation framework, storing code in a database (javascript or otherwise) is never a good idea. Here is a good tutorial:

http://javaboutique.internet.com/tutorials/Struts11Val/index-3.html


http://www.goodercode.com
SCJP 1.4
Rammohan Bandakunta
Greenhorn

Joined: Aug 17, 2005
Posts: 9
Thanks kerry,
I have an working project developed so far with jsp's,Action,FormBean's and DAO suggest me the best way of approachin validation's through Frame work so that i need not have much of cleanin..
Rammohan Bandakunta
Greenhorn

Joined: Aug 17, 2005
Posts: 9
Hi,

I made the required changes in struts-config ,validation and validation-rules.xml

issue is when i change the value in the drop down for a perticular field the Min and Max length value should change and the field should validate against the updated value.
ex:if for a perticular value (a) in the Dropdown the length against which a serial number field is validated is 10,on changing or selecting the value in the dropdown to (b) the length against which serialnumber field should be validated is 20,

Any thoughts about how i need to submit the value on change in to the validation.xml

In struts validation whats the best way to implement this
----------------------------------------------------------------------------
<TD height="39" width="106">ApplicationType</TD>
<TD height="39" width="179"><html:select name="micrtoolhomeCBForm"
property="applicationType"
onchange="javascript ocument.forms[0].submit()">
<html ptions collection="applicationTypeList" property="value"
labelProperty="label" />
</html:select></TD>
-----------------------------------------------------------------------
if (decknumber==null || decknumber.length==0){

alert("Please enter DeckName ")
document.forms[0].deckNumber.focus();
return false;
}
else if(decknumber.length>10) {
alert("Please enter deckname < 10 char...")
document.forms[0].serialNumber.focus();
return false;
}
else if (serialnumber==null || serialnumber.length==0)
{
alert("please enter SerialNumber.")
document.forms[0].serialNumber.focus();
return false;
}
else if(serialnumber.length>10 ) {
alert("Please enter serialnumber < Serial Length Rule For Selected AppType")
document.forms[0].ird.focus();
return false;
}
 
wood burning stoves
 
subject: Validation fetching rules from Database