I need to stay on the same page after Item update, but I need the item id to know where to go on success. I tried a few examples:
First one:
<action
name="add-item"
method="addItem"
class="com.deveto.struts.actions.ItemsAction" >
<interceptor-ref name="defaultStack"/>
<result name="success" type="redirectAction">
<param name="actionName">show-update-item</param>
<param name="itemId">${itemId}</param>
</result>
</action>
Second one:
With an Action variable and setter & getter methods.
and
<action
name="add-item"
method="addItem"
class="com.deveto.struts.actions.ItemsAction" >
<interceptor-ref name="defaultStack"/>
<result name="success" type="redirectAction">show-update-item</result>
</action>
Third one:
With request.setAttribute("itemId", itemId); and request.getAttribute("itemId");
and
<action
name="add-item"
method="addItem"
class="com.deveto.struts.actions.ItemsAction" >
<interceptor-ref name="defaultStack"/>
<result name="success" type="redirectAction">show-update-item</result>
</action>
Fourth one:
With an Action variable and setter & getter methods.
and the type=”chain”
<action
name="add-item"
method="addItem"
class="com.deveto.struts.actions.ItemsAction" >
<interceptor-ref name="defaultStack"/>
<result name="success" type="chain">show-update-item</result>
</action>
Eventually the Action is one, show-update-item.action.
But all of this is giving me the same null result.
Any advices?
Ex: show-update-item.action?itemId=33 (getParameter of itemId) -> editing some textfields -> submit (with itemId=33 in request) -> on succes redirectAction -> show-update-item.action (here when I try to getAttribute it is null)
If I understand correctly you’re staying on the same page with a different action after an item is selected on the first action. If this is the case, your first action definition should work:
Now that being said, you need to make sure you have accessor methods in both actions (we’ll call them action 1 and action 2) for itemId.
In action 1 ${itemId} is being retreived through the getter and in action 2 ${itemId} should be set through the setter method.
Another option would be to consider using sessionaware. Simply set a session variable in action 1 and in action 2 retrieve the session variable and remove it from session if you’re concerned about overhead. I tend to use session more often than not.