struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alireza Fattahi <>
Subject How configure struts2 to get validation rules from Spring via @value
Date Tue, 17 Sep 2013 09:03:25 GMT
We are using spring 3 and struts 2. We use spring @value annotation to get values from property
We want to get validation rules from property files instead of hard-coding them in action.

Here is sample property transfer.account.min.amount=10 
Here is the action: 
and other methods omitted@IntRangeFieldValidator(type =ValidatorType.FIELD,min ="${minAmount}",key
="")publicvoidsetAmount(Integeramount){this.amount =amount;} 
The minAmount is populated correctly by value 10, but the validation is not working. 
To see if parameters are passed correctly, I make a test as below. 
Assume we want to get a key from spring managed property file ( This is just a test ;) ) 
The resource bundel is: = This field must be more than ${min} 
...and make this change 
@IntRangeFieldValidator(type =ValidatorType.FIELD,min ="${minAmount}",key ="${transfer.account.min.amount.key}")

Now when an error happens the validation message shows, instead of fetching
this value from resource bundle!  
Of course, when you run below code: 
@IntRangeFieldValidator(type =ValidatorType.FIELD,min ="${minAmount}",key ="")

The error message is fetched resource bundle correctly! 
If I can use annotation in this way, please let me know what is my mistake! 
If I can not use annotations like this, please let me know what is 
the best way to avoid hard coding the validaiton rolls in actions. 

~~Alireza Fattahi
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message