Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts2 annotation validation

 
Arun Ak
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My action class implements ModelDriven interface. I want to validate the form using @RequiredStringValidator.

its not validating "name" . do any one of you know where I made mistake.



Thanks in advance.
Arun
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arun two wrote:

Please edit your name to use a real first and last name. See the Naming Policy for more details.
 
Mark E Hansen
Ranch Hand
Posts: 650
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you include the actionPackage parameter in your struts.xml file?
If you are going to use annotations in the source files, you'll need to
include the "actionPackages" initialization parameter to the Struts2
filter element in the application's web.xml file, as in:
The actionPackage denotes the Java package under which Struts2 should look
for classes to inspect for annotations.

 
Arun Ak
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I have resolved my validation issue but entered into new issues

My action class have two method one for loading the form and other one to process the form data.
both method to carry out certain validation such on load check ids if not then dont load the form , while processing form data varify correction of form data.



public Class MyAction extends ActionSupport implements ModelDrivern<MyForm>{

@ConversionErrorFieldValidator(type=ValidatorType.FIELD,fieldName="age",shortCircuit=true,message="Invalid data type",)
@IntRangeFieldValidator(type=ValidatorType.FIELD, fieldName = "age",min="1",max="99")
@RequiredStringValidator(type = ValidatorType.FIELD, fieldName = "name", message = "Supply Name ")
public String processFormData() throws Exception {
---
---
return SUCCESS;
}

@Validations(
expressions = {
@ExpressionValidator(expression="employeeId == -1", message="Employee not selected"),
@ExpressionValidator(expression="deptd == -1", message="Depatment not selected")
}
)

public String loadForm(){
getLearnableForm().setMinimumRelevance(20);
return SUCCESS;

}

}



When I load the form it also validationg the process form action annotation. I want to do validation on load form and other set of validation on process data - as I mentioned in the above code.
Please guide me how to achive
and if you any one know how to remove default message @ConversionErrorFieldValidator (Invalid field value for field "age".)- currently It shows default message and my custom message
Thanks in advance.
Arun
 
Martin O'Brien
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Arun Ak

You said you solved problem. Pleas tell me how, beacuse I've the same!

thanks
martin

 
Arun Ak
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please refer my previous post in that I added some annotation to my action.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic