?
Solved

Struts <html:link> and sending parameters

Posted on 2005-03-28
11
Medium Priority
?
7,971 Views
Last Modified: 2009-03-02
Hi,
  I've read a few answers to this question but I'm hoping there is a way to do it without scriplets. The simple reason being I'm not designing the pages and I'd like to keep it as clean as possible for the designer :)


Is there any way to simply specify a parameter? For example :


<html:link action="ShowStuff">
<parameter name="url"  value="www.test.com"/>
Here is the link text
</html:link>


I know this won't work, it's just an example of what I'm hoping exists :)



Any takers?
0
Comment
Question by:petepalmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 14

Expert Comment

by:boonleng
ID: 13649452
You can use JSTL if dont want to use scriptlet.
Example:

<%@ taglib uri="/tags/struts-html"  prefix="html" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<jsp:useBean id="map" class="java.util.HashMap" scope="page">
    <c:set target="${map}" property="url1" value="www.site1.com"/>
    <c:set target="${map}" property="url2" value="www.site2.com"/>
</jsp:useBean>

<html:link action="ShowStuff" name="map">Here is the link text</html:link>
0
 
LVL 1

Author Comment

by:petepalmer
ID: 13651063
So there's no way of doing it natively with struts?

The other problem is that each link would have a different parameter (i.e I would be iterating through a list of links ) so I imagine using a HashMap would be a bit of a pain....

wonder why they didn't think of this in their tag library? :)
0
 
LVL 14

Expert Comment

by:boonleng
ID: 13651515
If you have have only one parameter in the url, then you dont need to use HashMap. You can loop it directly.
Example:

<logic:iterate id="value" name="arraylist">
    <html:link action="ShowStuff" paramId="url" paramName="value">Here is the link text</html:link>
</logic:iterate>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:petepalmer
ID: 13651570
Very close - but the problem is that the value of paramName needs to be the same as the contents between the link tags i.e the same url  :)

0
 
LVL 14

Accepted Solution

by:
boonleng earned 1000 total points
ID: 13658310
Use <bean:write> to output the value:

<logic:iterate id="value" name="arraylist">
    <html:link action="ShowStuff" paramId="url" paramName="value"><bean:write name="value"/></html:link>
</logic:iterate>
0
 
LVL 1

Author Comment

by:petepalmer
ID: 13659838
perfect example - nice one :)
0
 
LVL 1

Author Comment

by:petepalmer
ID: 13659948
Slight problem :)

It's nearly working perfectly - but I need "url"  to be the contents of the "url" property on the "feed" bean... any suggestions?
0
 
LVL 14

Expert Comment

by:boonleng
ID: 13667728
You can specify the property name on the bean to the atttibute 'property'. If not specified, it will use the attribute 'name' as the value (e.g. previous example).

<logic:iterate id="feed" name="listOfBeans">
    <html:link action="ShowStuff" paramId="url" paramName="feed" paramProperty="url">
    <bean:write name="feedbean" property="url"/>
    </html:link>
</logic:iterate>
0
 
LVL 1

Author Comment

by:petepalmer
ID: 13675103
Thanks again - that is working beautifully now :)
0
 
LVL 1

Author Comment

by:petepalmer
ID: 13675307
Is it possible to use the <html:link> tag to link to a dynamic URL? i.e the url would be a property of a bean but instead of transfering control to a fixed location, I'd want each one to be a different url.

Maybe I should open a new question for that :)
0
 
LVL 14

Expert Comment

by:boonleng
ID: 13677351
The <html:link> tag allows to link to dynamic url (see http://struts.apache.org/userGuide/struts-html.html#link), but if the url is from a bean, then will require to write scriptlet. You can use the following example if you prefer no scriptlet.

<logic:iterate id="feed" name="listOfBeans">
   <a href="<bean:write name="feedbean" property="url"/>"><bean:write name="feedbean" property="url"/></a>
</logic:iterate>
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

New style of hardware planning for Microsoft Exchange server.
I originally wrote this article to compare SARDU and YUMI, but have now added Easy2Boot, since that is the one I currently use and find the easiest to create and alter.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question