How can I add or change params to a struts url tag?

In struts, I'd like to have a base URL (an <s:url...) set up with a some parameters (<s:param...), and then either add parameters to that URL or change the values of some parameters. For example:

<s:url action="getSomeData" id="baseDataUrl"> <s:param name="someID" value="%{currentID}"/> </s:url>

I can then do <s:property value="baseDataUrl" /> and it'll spit out something like / (I'm keeping the params simple for this example, but you can imagine having many more default params. For instance, the app I'm working on has 3 params that are the same for every URL, and two that change.)

I'd like to be able to add or change parameters after defining that base URL. I'm dreaming up two approaches:

<s:url base="baseDataUrl" id="breadUrl"> <s:param name="bread" value="%{'toast'}"/> </s:url>

And then <s:property value="breadUrl" /> would result in / Another approach is to define the base URL with placeholders:

<s:url action="getSomeData" id="baseDataUrl"> <s:param name="someID" value="%{currentID}"/> <s:param name="bread" /> <s:param name="jelly" /> </s:url>

And then fill them in when I ask for the property:

<s:param url="baseDataUrl" name="bread" value="%{'toast'}"/> <s:param url="baseDataUrl" name="jelly" value="%{selectedJam}"/>

So <s:property value="baseDataUrl" /> would result in /

The docs for s:url ( say "Dynamic Attributes Allowed: false" so I think I'm venturing into custom-tag territory. This feels like such a common use case (define a base URL with some params, and then add or change some of them) that I don't want to reinvent the wheel. Searching has yielded nothing, but maybe I'm not looking for the right thing. I'm open to a wide variety of suggestions!

-------------Problems Reply------------

Here are few options that I can think of

  1. Use an action called "delegatorAction" and write only the extra params that is needed. You could write an Action/Handler which then "infers" the other params (in this case "someID"). This could be complicated and you may have to alter this code everytime there is a change to your url handling logic
  2. You could write your own url tag and say and have a property like "base" the way you have suggested, which just evaluates the base attribute and adds any param to it (You could subclass the Url Tag for that)
  3. The most simplistic approach could be to first declare the 3 params as a url and then add the extra parameters using standard s:property tags (Heck I cant get to output xml code even with proper formatting dont know why, must be because of chrome)

In this approach you are merely appending strings at the end.

Category:java Views:7 Time:2010-02-10

Related post

  • Add a :filter param to the end of a url 2010-05-04

    I am building an application that requires a search to go deeper than the initial level. I am using nested scopes to accomplish this and params in the URL For example, when a user searches for "handbag" it creates a query like the following. http://l

  • How can I add a GET param to some anchor elements in jQuery? 2011-07-18

    I have a bunch of a elements and I want to add a GET param to their href attribute. I want to use ? or & where appropriate. For example, should become and

  • How can I add params to a c:import tag in a loop? 2011-06-16

    I want to do something like this: <c:import url="${myvar.url}"> <c:forEach items="${myvar.params}" var="param"> <c:param name="${}" value="${param.value}"/> </c:forEach> </c:import> And I get this error: Illega

  • access struts2 include param value in another jsp page in struts if tag 2011-11-11

    I am passing param value in include tag in jsp page like below <s:include value="../../commonjspf/status.jspf"> <s:param name="mystatus" value="%{status}"> </s:param> </s:include> where status variable come from action class .

  • Java Servlet getParameter for a param that is a URL 2010-09-20

    I am building a site which submits a url to a servlet for analysis purposes. On the client side, I submit the url as a parameter that is encoded. For example... Submit: Goes to: http://localhost/myservlet/?url=http%3A%2F%2Fwww.sit

  • When I add a third segment to my expressionengine url, the exp:channel:entries stops returning results 2011-08-05

    I'm having an issue where a third "segment" in the url will cause ALL the exp:channel:entries to stop returning results. Example URLs: works fine: does not work: Example Entry Pull: {e

  • Add search terms from form to search url 2011-10-02

    I am trying to create a search input to a site that add the search terms to the end of the url. This is the url in question: You can manually search by adding the search t

  • preg_replace syntax to add chrs after the closing of an image tag 2011-10-31

    I need a preg_replace syntax to add something (anything) after the /> of an image tag that is within a string I have. So for example $string="here is a <img src="images/test.gif" /> string!" needs to become... $string="here is a <img src=

  • Firefox add-on: getting started - how to block url on a certain page? 2012-03-01

    I'm trying to develop an add-on to block a list of urls (facebook, twitter, etc.) on a certain website (e.g. I'd also like to block ads... Do you know if it's possible to extend adblock plus? Where should I start? I can't find much inf

  • Add a class with Jquery or Javascript to tag 2012-04-27

    I have the following markup: <ul class="menubar"> <li><a href="home.php" title="Home">Home</a></li> <li><a href="services.php" title="Services">Services</a></li> <li><a href="aboutus.php"

  • Internet Explorer adds ://0 to the end of some URLs that result to 404 not found. 2012-01-26

    Original Title: IE adds ://0 to the end of some URLs I'm running a website, and I've been just checking the access logs for oddities. Now there are a lot of requests where the URI ends "://0" that result to 404 not found. All of these come from IE ve

  • How to add parameter at the end of the URL 2015-03-17

    i created one wcf service in c#.and i successful publish i want to pass parameter in the URL and wcf will return data in json format.but i am trying than i am not getting any can you help me how add parameter at the end of the URL. I

  • how to add a dynamic param 2011-01-10

    the jquery plugin that im using is this if i have a table like this <table> <thead> <tr> <th>id</th> <th>first name </th> <th>last name </th> </

  • Add Class to Param tag - JavaApplet 2011-03-25

    I have an applet code like this: <applet type="applet" codebase="." code="ViewerApplet.class" align="center" width="100%" height="600" archive="icepdf-core.jar, icepdf-viewer.jar, icepdf-applet.jar"> <param name="image" value="my_logo.gif" t

  • How to add an optional "param" in a regular expression in .htaccess 2011-08-04

    I've following 2 rules in my .htaccess file - 1. RewriteRule ^myscript/([A-Za-z0-9]{0,1})\?page=([0-9]?)$ /myscript.php?action=check&var=$1&page=$2 [L] 2. RewriteRule ^myscript/([A-Za-z0-9]{0,1})$ /myscript.php?action=check&var=$1 [L] so

  • grails, add only existing params from current url to pagination 2011-08-24

    guys! I`d like to make 'clever pagination'. For example, if i already have params.category=Auto - i want it to be added to my params. Of course, i can do smth like this : <g:paginate total="${total}" max="10" maxsteps="5" params="[category: params

  • How to add wmode="transparent" for every flash object & ebmed tag? 2010-04-24

    I have a page which displays dynamic flash content from I need to add wmode="transparent" because otherwise navigation menu shows under flash. Is there a short way to do this with jQuery or simple java-script? I don't want to change embed

  • How to add a custom field with fb:request-form tag 2010-12-29

    I need to add a custom field with the fb:request-form tag in facebook. ie:- I need the user enter some value in a text box and then select his/her facebook friends and when the user send the invitation with the selected uid's i need to process the va

  • ASP.NET MVC: Redirect from query string params to a canonical url 2011-04-14

    In my Asp.Net Mvc project I'd like to have a good looking urls, e.g., and I want to redirect from my old style urls (such as with 301 state so that there won't be two urls with identical content. Is there a way to

Copyright (C), All Rights Reserved.

processed in 0.216 (s). 11 q(s)