Struts mapping actions September 21, 2006Posted by javafoo in javanotes, struts basic.
In this latest project of mine I was thinking about the various ways to map struts actions. I had done this, a couple of different ways and was wondering if there was a classification out there. And sure enough someone had already done this and instead of paraphrasing, I will just provide the link, here at TSS. Another thing/caveat about using named form-beans accross actions For ex, in your struts-config.xml, if you have a form-bean:
<form-bean name=”xyzForm” type=”package.web.XYZForm” />
and you want to use the same form accross two actions:
<action path=”/processAction” type=”package.web.action.ProcessAction”
<action path=”/displayAction” type=”package.web.action.DisplayAction”
Notice here, I am using the same named form-bean for two actions, in the display action I don’t want to validate the form, but in the process action I want to validate the form. In this case I was in for a surprise, the validate=”true” wasn’t working for the process action. This is because the form params are set only once per form-bean. To overcome this, define two different named form-beans of the same type or if you still want to reuse the form-bean, set validate to true for both actions and within the validate method, based on a parameter decide if you want to validate or not.