Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using struts2 to redirect with dynamic parameters not working

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?

like image 306
periback2 Avatar asked Nov 25 '25 18:11

periback2


1 Answers

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.

like image 96
Aleksandr M Avatar answered Nov 27 '25 08:11

Aleksandr M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!