Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Cannot set parameter in HTML:Link

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,

I need some help with my jsp code, please.

Below is the code snippet:

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList">
<html:link action="/TopicLink.do?link=<%= showResult %>" styleId="leftmenuHREF" title="" target="basefrm"><%= showResult %></html:link><br>

</logic:iterate>
</logic resent>

I want to dynamically set the link value in the action tag, but it is not working. The action="/TopicLink.do?link=<%= showResult %>" is giving me link="null" when I print it, but the same <%= showResult %> value in between the HTML tags are showing correct value. Please tell me where I am going wrong. Also, if I put The action="/TopicLink.do?link= testing", and later acces the value of link in my action class as


searchText = request.getParameter("link");

It gives the correct value. Only, action="/TopicLink.do?link=<%= showResult %>" does not work.:-(

Thanks,
~E
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think I read yesterday that in Struts Tags (or html:link tag) there is a rule about using scriptlets: "all or nothing". You either write the whole construction inside the tag as a scriptlet, or you don't use the scriptlets inside. . . But I'm not 100% sure
 
sumita mukherjee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply.
As you suggested:
>You either write the whole construction inside the tag as a scriptlet, or >you don't use the scriptlets inside. . .

can you give me an example of doing that? I beg your pardon for my ignorance, but I am very new in this domain.

Thanks again.
 
sumita mukherjee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched the net and got a suggestion as :

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList">

<bean efine id="param1" name="showResult"/>
<a href="/TopicLink.do?link=<%= param1%>" title="" target="basefrm"><%= showResult %></a><br>

</logic:iterate>
</logic resent>

so the <html:link> tag is replaced by <a> (anchor)tags. But this does not work as well. Clicking on the link gives a Servlet eror 404(Action TopicLink.do navailable), even though I have a mapping in of this action in TopicLink.

Is there any way I can achieve this?
Thanks for all the help.
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try using <html-el:link..> tag!

It is so much easier to set the values dynamically using the <html-el:xxxx> tags. I use it in combination with JSTL tags... I hope it should work with struts tags as well...

see the below code for an example -
 
sumita mukherjee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I have 2 questions regarding this:
1. I guess I need to add some jars for using this? Please correct me if I am wrong.

2. I need to set the value dynamically according to the arrayList value, so actually the value passed to link should be equal to the value of the id of Logic:iterate(i.e. showResult).

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList">
//have to pass action="somehing.do?link=<<value of showResult>>

</logic:iterate>
</logic resent>

so if I put like this:

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList">
<c:set var="actionUrl">
<c ut value="/myfolder/addSomething.do?link=<%=showResult %>" />
</c:set>
<html-el:link action="${actionUrl}"> <%= showresult></html-el:link>
</logic:iterate>
</logic resent>

will this work?

Please guide me a bit in this.
Thanks again.
 
Bhaskar Reddy
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. Yes, you may need to have struts-el-<version>.jar (eg., struts-el-1.3.8.jar) file in your classpath.

Please see Struts-EL for reference

2. This may probably work for you -


[ August 28, 2007: Message edited by: Bhaskar Reddy ]
[ August 28, 2007: Message edited by: Bhaskar Reddy ]
 
sumita mukherjee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks again for your reply. Now, while I was setting up for the JSTL resolution, I gave a last try with this and came very close, but got stuck at one place:

Code:

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList" >
<%
String contextPath ="testing" ;
pageContext.setAttribute("contextPath",new String(contextPath));
java.util.HashMap newValues = new java.util.HashMap();
newValues.put("link", contextPath);pageContext.setAttribute("newValues", newValues);%>
<html:link action="/TopicLink" name="newValues" target="basefrm"> <%=showResult%> </html:link>
</logic:iterate>
</logic resent>

Now this works fine, and when I click on the link it sets the "link" parameter to "testing" correctly. But I am stuck here. How can I now set the HashMap value dynamically to the value of the Logic:Iterate Id attribute? If I can at least get a variable assigned to this it would work out. I am doing some syntactical mistakes here.

Can somebody please help me?

Regards,
~S
 
sumita mukherjee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess I solved the problem. This works fine!! Putting the code, in case someone needs help in future:

<logic resent name="resultList" scope="session">
<logic:iterate id="showResult" name="resultList" >
<%
String contextPath =(String)showResult;
pageContext.setAttribute("contextPath",new String(contextPath));
java.util.HashMap newValues = new java.util.HashMap();
newValues.put("link", contextPath);pageContext.setAttribute("newValues", newValues);%>
<html:link action="/TopicLink" name="newValues" target="basefrm"> <%=showResult%> </html:link>
<br>
</logic:iterate>
</logic resent>

Thanks all for all the guidance and help!!

~S
 
Ranch Hand
Posts: 181
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is how to do it without using scriptlets:

<logic:iterate id="showResult" name="resultList">
<html:link action="/TopicLink.do" styleId="leftmenuHREF" target="basefrm">
<bean:write name="showResult"/>
<html:param name="link"><bean:write name="showResult"></html:param>
</html:link>
</logic:iterate>
[ August 29, 2007: Message edited by: Dom Lassy ]
 
permaculture is largely about replacing oil with people. And one tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic