3

I'm having an issue while trying to redirect mapping with dynamic parameters.

The way I'm mapping in Struts2:

<action name="Delete" class="templateLalaAction" method="remove">
    <result name="success" type="redirect-action">
        <param name="actionName">LalaTemplatesDisplay</param>
        <param name="buId">${buId}</param>
    </result>
    <result name="failure" type="redirect-action">
        LalaTemplatesDisplay
    </result>
</action>

The method "remove" in the action:

remove() {

    putRequestAttribute("buId",Long.valueOf("1111"));
    return SUCCESS;
}

if I do this, I'm setting the buId=1111, but when I run the app, the url ends with buId= (it's empty), i.e., no parameter is being passed. if I comment the putRequestAttribute method, and set struts passing buId parameter as a static value:

<action name="Delete" class="templateLalaAction" method="remove">
    <result name="success" type="redirect-action">
        <param name="actionName">LalaTemplatesDisplay</param>
        <param name="buId">1111</param>
    </result>
    <result name="failure" type="redirect-action">
        LalaTemplatesDisplay
    </result>
</action>

It works and the url ends with buId=1111.

I also read this question where the accepted answer teaches us to do the same I did, but if we read the comments the user did, we'll see he has the same problems I have. What am I possibly doing wrong?

Community
  • 1
  • 1
periback2
  • 1,459
  • 4
  • 19
  • 36

1 Answers1

2

Inside your method just assign buId variable and you need getter/setters for it in your action class.

public String remove() {
  buId = 1111l;
  return SUCCESS;
}

Also you are using old syntax for redirect-action, use camel case redirectAction.

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • I better not change because this code (redirect-action) is old, so i won't be able to refactor it all (unfortunatelly) :/ – periback2 Jan 08 '13 at 11:52