You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by aum strut <au...@gmail.com> on 2011/02/16 15:16:21 UTC

Struts2 and Validation issue

Hi All,

I am trying to user Validation framework with Struts2 but struck at a
point,here are the details.

I am developing a import service which includes various steps like

1) Showing number of import options

2) Showing number of elgible files for the import (Import type selected in
step one)

for all this i have created only one action with multiple methods which is
doing all the job.now in the second case when user select a file,i am trying
to place a validation for empty field but since property file is outside of
all he methods so the validation is working for all methods

e.g

i do not want the validation to execute for step1  but it is even getting
executed for step one (since file will be selected in step 2 so step1 is
always fails)

is there any way to organise validation so that it should only execute for a
specific method inside the Action

here is my validation code

@RequiredFieldValidator

(type=ValidatorType.*FIELD*,message="Please select a file for import")




*public* String getSelectedFile() {




*return* selectedFile;




}

any help in this regard will be appriciated

Re: Struts2 and Validation issue

Posted by Michal Ciasnocha <mc...@struts.cz>.
Hi,

the problem of validation through annotations is they are applied every 
time the action is called. You can try use method which you call from 
your form. For example, if you want to validate only execute method, 
write your own method with name validateExecute(). The principle is same 
for another methods.

I hope this helps.

aum strut wrote on 16.2.2011 15:16:
> Hi All,
>
> I am trying to user Validation framework with Struts2 but struck at a
> point,here are the details.
>
> I am developing a import service which includes various steps like
>
> 1) Showing number of import options
>
> 2) Showing number of elgible files for the import (Import type selected in
> step one)
>
> for all this i have created only one action with multiple methods which is
> doing all the job.now in the second case when user select a file,i am trying
> to place a validation for empty field but since property file is outside of
> all he methods so the validation is working for all methods
>
> e.g
>
> i do not want the validation to execute for step1  but it is even getting
> executed for step one (since file will be selected in step 2 so step1 is
> always fails)
>
> is there any way to organise validation so that it should only execute for a
> specific method inside the Action
>
> here is my validation code
>
> @RequiredFieldValidator
>
> (type=ValidatorType.*FIELD*,message="Please select a file for import")
>
>
>
>
> *public* String getSelectedFile() {
>
>
>
>
> *return* selectedFile;
>
>
>
>
> }
>
> any help in this regard will be appriciated
>