Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 602355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:48:50+00:00 2026-05-13T16:48:50+00:00

I want to add a variable list of parameters to a Struts2 URL tag.

  • 0

I want to add a variable list of parameters to a Struts2 URL tag. I have a map of the parameters (name value pairs) in an object in the session. I’m struggling to find a good approach to this. Here is the relevant JSP code:

    <s:iterator value="%{#session['com.strutsschool.interceptors.breadcrumbs']}" status="status">
    <s:if test="#status.index > 0">
        &#187;
    </s:if>
    <s:url id="uri" action="%{action}" namespace="%{nameSpace}">
            <s:param name="parameters" value="%{parameters}"/>
    </s:url>
    <nobr><s:a href="%{uri}"><s:property value="displayName"/></s:a></nobr>
</s:iterator>

The parameters variable is a Map that contains the params. This, of course does not work but I cannot see a way to approach this at the moment. I’m thinking at the moment that I might need a custom freemarker template for this. Can anyone suggest a better way?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T16:48:50+00:00Added an answer on May 13, 2026 at 4:48 pm

    The Parameter tag populates parameters only to its direct antecessor. Wrappings an iterator tag around the parameter tag has no effect. 🙂
    To solve this you can easily write an alternative parameter tag wich can use a map direclty
    The tag may look like this.

    package my.taglibs;
    
    import java.io.Writer;
    import java.util.Map;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.commons.logging.Log;
    import org.apache.commons.logging.LogFactory;
    import org.apache.struts2.components.Component;
    import org.apache.struts2.views.jsp.ComponentTagSupport;
    import com.opensymphony.xwork2.util.ValueStack;
    
    public class ParamTag extends ComponentTagSupport {
    
        private String map;
        private static final long serialVersionUID = 2522878390854066408L;
        Log log = LogFactory.getLog(ParamTag.class);
    
        @Override
        public Component getBean(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
            return new Param(stack);
        }
    
        @Override
        protected void populateParams() {
            super.populateParams();
    
            Param param = (Param) component;
            param.setMap(map);
        }
    
        public void setMap(String map) {
            this.map = map;
        }
    
        public class Param extends Component {
    
            private String map; 
    
            public Param(ValueStack stack) {
                super(stack);
            }
    
            @Override
            public boolean end(Writer writer, String body) {
                Component component = findAncestor(Component.class);
                if (this.map == null) {       
                    log.warn("Attribute map is mandatory.");
                    return super.end(writer, "");
                }
                Object o = findValue(this.map); //find map in vs
                if(o == null) {
                    log.warn("map not found in ValueStack");
                    return super.end(writer, "");
                }
                if(!(o instanceof Map)) {
                    log.warn("Error in JSP. Attribute map must evaluate to java.util.Map. Found type: " + o.getClass().getName());
                    return super.end(writer, "");
                }
    
                component.addAllParameters((Map) o);
                return super.end(writer, "");
            }
    
            public void setMap(String map) {
                this.map = map;
            }
        }
    }
    

    And you need a corresponding tld-entry

    <tag>
        <description><![CDATA[Parametrize other tags]]></description>
        <name>param</name>
        <tag-class>my.taglibs.ParamTag</tag-class>
        <body-content>JSP</body-content>
        <attribute>
            <name>map</name>
            <required>true</required>
            <rtexprvalue>true</rtexprvalue>
        </attribute>
        <dynamic-attributes>false</dynamic-attributes>
    </tag>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a string to a variable name that represents an integer.
I have two variables, key and value , and I want to add them
I have a view that has a list and I want to add a
I want to add a dictionary that maps an object to a list of
I am iterating through a database and want to add the variable value of
I want to add a variable number of records in a table (days) And
I want to add code php to variable with html, for example $html =
I want to add leading zero to a variable to obtain a 6 digits
I have a website built with ASP.NET (3.5) and want add some level of
I have the following YAML: - name: List of monkeys - author: Nicolas Raoul

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.