• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Struts complex validation -- no javascript generated?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,

I have defined a complex validation + script in my validation-rules.xml
I declare the validation rule to be applied on a field in the form
but when I try to load the JSP page, I can see that the other checks (like required, minlength etc... are generated, although my own check is not generated. I want to do client checking on this little extra check too because if it's not possible, it's useless (for me) to do checks at the client side at all. The thing that I want to check is that a field A is (almost) equal to a field B, except the final character (which should be A in field A and B in field B). So "0123AA12345A" and "0123AA12345B" will be accepted, otherwise, alert box.

I hope someone already implemented some more complex validation rules and knows how to solve the problem.

Jeroen

-------------------- validation-rules.xml (snipped) --------------
<validator
name="vpnBoxIDsCompareEqualExceptAB" classname="com.mycompany.ui.util.validator.VPNBoxIDsCompareEqualExceptAB"
method="validateVpnBoxIDsCompareEqualExceptAB"
methodParams="java.lang.Object,
org.apache.commons.validator.ValidatorAction,
org.apache.commons.validator.Field,
org.apache.struts.action.ActionErrors,
javax.servlet.http.HttpServletRequest"
depends="" msg="errors.vpnboxidscompareequalexceptab">
<javascript>
<![CDATA[
function validateVpnBoxIDsCompareEqualExceptAB(form) {
var field1 = form['fieldA'];
var field2 = form['fieldB'];
var pack = form['packType'];

if (pack.value != 'DoCheck') {return true;}

if (((field1.type == 'text') || (field1.type == 'textarea')) &&
((field2.type == 'text') || (field2.type == 'textarea')) &&
((field1.value.length > 0) || (field2.value.length > 0)))
{
var sub1 = null;
if (fields1.value.length > 0) {
sub1 = field1.value.substring(0, field1.value.length-1);
}

var sub2 = null;
if (field2.value.length > 0) {
sub2 = field2.value.substring(0, field2.value.length-1);
}

if (sub1 == sub2)
{
if ((field1.value == sub1+'A') && (field2.value == sub2+'B'))
{
return true;
}
}
}

alert('The permanent VPN Box ID and dial-up VPN Box ID are not the same (except A or B)');
return false;
}
]]>
</javascript>
</validator>


---------------------------- declare checks on form fields ----------------
...
<field
property="fieldA"
depends="vpnBoxIDsCompareEqualExceptAB">
<msg name="vpnBoxIDsCompareEqualExceptAB" key="order.status.mask.error.permvpnid"/>
<arg0 key="order.status.vpnbox.permanent"/>
<var>
<var-name>fieldB</var-name>
<var-value>dialupVPNBoxID</var-value>
</var>
<var>
<var-name>packType</var-name>
<var-value>summary.packType</var-name>
</var>
</field>
...
 
I am going down to the lab. Do NOT let anyone in. Not even this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic