문제

I am hiding some fields based on some condition, i.e. in UI they won't be visible , but clicking on submit button ,struts is validating these hidden fields ..

Is there a way to tell struts not to validate fields which are hidden ... i.,e validate these fields only when they are visible on UI.

I am using struts 1.2 framework.

도움이 되었습니까?

해결책

Set a property on your form when you trigger these conditions and then check for that in your validator:

if(!form.isSkipValidation()){
   //Hear you can write your Validation code..
}

In javascript you can set this property with a hidden input field:

<input type="hidden" name="skipValidation" value="false"/>

hope this is helpful...

다른 팁

Struts will validate whatever is in the form, hidden or not.

You'd need to use conditional validation and determine if you should be performing those validations, perhaps through another hidden form value, depending on how you decide what's hidden.

Personally, I find this kind of validation to be difficult to maintain under XML configuration. Especially if the validation conditions rely on business logic I prefer to see this kind of logic in either a custom validator, or in an ActionForm validate method, encapsulated in a class isolated from the Struts framework altogether.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top