Вопрос

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