aspose file tools*
The moose likes Struts and the fly likes struts2 action-method-validation.xml not working? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 action-method-validation.xml not working?" Watch "struts2 action-method-validation.xml not working?" New topic
Author

struts2 action-method-validation.xml not working?

M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
I have an action for updating an address object: ChangeAddressAction which has 2 methods: show() and update(). This action implements prepare() and getModel(). I have the following validation file -> ChangeAddressAction-update-validation.xml in my action package (along with other validations).

ChangeAddressAction (extends ActionSupport) implements Preparable, ModelDriven<Address>

prepare() - sets up an action attribute
getModel() - returns the address object
show() - populates the action's address object - renders the jsp to the user
update() - expects a VALID populated address object to send to the service

I call an action mapping to render the changeAddress.jsp which calls the ChangeAddressAction show() method. The JSP renders with all of the pre-populated address information. However when I submit (to a different action mapping calling the same action with the update() method), the validations on the action are not performed.

<action name="ShowAddress" class="com.ChangeAddressAction" method="show">
<result>changeAddress.jsp</result>
</action>

<action name="ChangeAddress class="com.ChangeAddressAction" method="update">
<result name="input">changeAddress.jsp</result>
<result name="success">changeAddress.jsp</result>
</action>

From the documentation that I've seen so far I thought it would be enough to name the validation file the same as the ChangeAddressAction-update-validation.xml for validations to be triggered, but they aren't triggered. I have several other validation files that do not have aliases which trigger as expected. What am I doing wrong?!

Thanks

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is very difficult to read. You can edit your post to include them by using the button.
M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
I have removed the alias method from my action and am calling the execute() method directly but still my validation is still not firing. The validation field names seem to match the field names in the JSP...





where action mapping is:



and validation file is named:

PolicyAddressChangeAction-validation.xml

Any thoughts?

Much thanks.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Just to verify:

The action extends ActionSupport?
You're running the default interceptor stack?
The validation file is in the same directory as the action, and is being deployed?
Does it work for a "simple" action property (like "fname" or something, to see if it's an OGNL navigation issue)?
If the action populates the form field it's being displayed on the form?
With logging set to DEBUG is there anything regarding validation in the logs?
M Turner
Greenhorn

Joined: Dec 16, 2009
Posts: 25
Thanks very much for your prompt reply

David Newton wrote:Just to verify:

The action extends ActionSupport? YES

You're running the default interceptor stack? YES

The validation file is in the same directory as the action, and is being deployed? YES

Does it work for a "simple" action property (like "fname" or something, to see if it's an OGNL navigation issue)? - since the flow falls through to the action, a breakpoint in the execute() shows that the object IS being populated - there are no OGNL warnings in the log

If the action populates the form field it's being displayed on the form? I'm using 2 actions now: 1) populate the address object and show the form page and 2) populates a service object (which has the address object nested in it) using ModelDriven and sends the edits to the service - I know I shouldn't have to use 2 actions in struts2 but I haven't gotten things to work otherwise...

With logging set to DEBUG is there anything regarding validation in the logs? - there are no validation OR converter errors in the log


Actually, the 2 actions bother me because I'm sure there's something there. The "set up" action has the "newBillingAddress" in it as an action attribute while the "update" action has "newBillingAddress" nested as an attribute of a service object. However, I did try putting a "newBillingAddress" object in the "update" action and setting it into the service object but it didn't change anything.

I ALSO tried putting the nested property field name in my validation.xml, in case that was the problem e.g.:



any more thoughts?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 action-method-validation.xml not working?