'Struts1 Link tag to Struts2 Anchor Tag; get the action parameter

Short Question: How do I get the action passed in the AnchorTag's action when I am customising it?

Long Question:

I am doing a migration from Struts 1 to Struts 2 where we are using some custom tags. One of the customisations is in the org.apache.struts.taglib.html.LinkTag. This has been customised to add additional parameters. Please see below a sample tag in a particular jsp.

<shared:link page="/getItems.do?itemType=ItemA&amp;callingPage=Summary">

This link gets added with some additional parameters by the customisation resulting in the below modified link.

/main/getItems.do?itemType=ItemA&callingPage=Summary&custAcctId=1041&customerName=name_mask

The customisation is done like below by overiding the calculateURL method

    public class MetaLinkTag extends LinkTag {
        /**
         * Return the complete URL to which this hyperlink will direct the user.
         *
         * @exception JspException if an exception is thrown calculating the value
         */
    protected String calculateURL() throws JspException {

        // Identify the parameters we will add to the completed URL
        Map params = RequestUtils.computeParameters
            (pageContext, paramId, paramName, paramProperty, paramScope,
             name, property, scope, transaction);
        params.put("custAcctId","1041");
        params.put("custAcctName","name_mask");
        String url = RequestUtils.computeURL(pageContext, forward, href,
                                              page, params, anchor, false);
        return url;
    }
}

I have identified that the org.apache.struts2.views.jsp.ui.AnchorTag in struts 2 will have to be customised to do the equivalent in Struts2. So I replaced the jsp as follows

<shared:link action="/getItems.do?itemType=ItemA&amp;callingPage=Summary">

but I am not able to get the parameter list for adding the new parameters. Struts 1 does RequestUtils.computeParameters to get the parameters and then appends additional stuff to it.

How do I get the original list of parameters of the AnchorTag for Struts 2

P.S: If I get the parameters list, I am planning to override the setAction with the new customised parameters list. Hopefully that goes good. Sample code below

public class MetaLinkTag extends AnchorTag {

@Override
public void setAction(String action) {
    //String existingAction = GetExistingAction()
    //super.setAction(existingAction +"&custAcctId=1041&customerName=name_mask");
}


Solution 1:[1]

Spent 30+ mins in thinking/writing this question and I found the answer when I came to the end of it. It was straight forward.

public class MetaLinkTag extends AnchorTag {

  @Override
  public void setAction(String action) {
      super.setAction(action +"&custAcctId=1041&customerName=name_mask");
  }

}

I don't want to waste this effort in writing this question. Putting it out here in case it is useful for someone.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Peter Csala