*
The moose likes Struts and the fly likes Cannot set parameter in HTML:Link Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Cannot set parameter in HTML:Link" Watch "Cannot set parameter in HTML:Link" New topic
Author

Cannot set parameter in HTML:Link

sumita mukherjee
Greenhorn

Joined: Aug 27, 2007
Posts: 22
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
Remi Malessa
Greenhorn

Joined: Aug 27, 2007
Posts: 7
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

Joined: Aug 27, 2007
Posts: 22
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

Joined: Aug 27, 2007
Posts: 22
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.
Bhaskar Reddy
Ranch Hand

Joined: Dec 17, 2002
Posts: 52
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

Joined: Aug 27, 2007
Posts: 22
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

Joined: Dec 17, 2002
Posts: 52
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

Joined: Aug 27, 2007
Posts: 22
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

Joined: Aug 27, 2007
Posts: 22
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
Dom Lassy
Ranch Hand

Joined: May 05, 2006
Posts: 181
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Cannot set parameter in HTML:Link
 
Similar Threads
html:link tag ------- urgent
Dynamically displaying html:option values
logic iterate something wrong
Logic iterate
Regarding Logic iterate