We are building a system on struts 2.0.9 with model aware design but we cant figure how to setup the validation, I have blundered in struts wiki for quite some time now and even on xwork code but I havent figured it.
Anyone have any idea or can point were to look for such information?
What is "model aware design" and how does it impact your use of validation. You mention the phrase in your subject line and message so it seems like it is important. I tried Google and did not find much (this page was the first hit).
Model-Aware is a Struts 2 specific term. Normally in Struts 2, the struts 1 concepts of an ActionForm and an Action are unified -- since you get a new Struts 2 action on every request you can have the instance variables, etc.
However, this still means you often end up doubling your get/setters once on the model object and once on the action. With the action simply proxing through. (ie the framework calls all the setters on the action, and then in your action you call someObject.setProperty(getProperty()) ).
This is seen as annoying/unclean.
Model-Driven/Model Aware refers to using your model object as a Struts 1 action form, effectively. So the get/setters do not exist on the action.
Now I haven't used model driven yet, mainly because until I get HDIV hooked up also , I don't like some of the security implications. However, to make validations work my impression is that 1) Move your validation from your action's setters to your model's setters 2) Set up a Visitor validator on the model object in the action
Joined: Mar 30, 2004
Hello again, Thanks for the reply, after reading Erich's reply I went about trying to configure the visitor to validate the model, but I was not able to do so.
I created an <Model Class Name>-validation.xml file next to the model class, with the validation for the model, in the action validation file I created a configuration for the model, I tried to use the field-name as the class name, as "model"(since the action property for the model is surprisingly model).
I tried to configure it without using prefix, using prefix as model. In none of my attempts the validation fired for the model properties. I was unable to find proper documentation on the usage of the visitor field, being the only one: http://struts.apache.org/2.x/docs/visitor-validator.html
But the documentation is lacking, for example it does not tell me if I have to have one visitor to each field or just one visitor to each model object regardless of the number of fields that must be validated against.
Anyone has pointers to were look for more info? Like books or a sample aplication that actually use visitor?