This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Setting attributes in forms or anchors  RSS feed

 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there a way to set an attribute (c:set) in an <a> or <form> before performing the action?
 
Darryl Nortje
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Andy,

Have you tried doing it using javascript. onclick event. That should execute first before performing the action.
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats what I'm doing now, but its in a c:forEach loop, and the EL expression isn't evaluated at the time of the forEach; instead it waits until the click event. This means the last element of the forEach is used.

<blockquote>code:
<pre name="code" class="core">
<table style="font-style: bold">
<c:forEach var="hostname" items="${hostnames}">
<tr>
<td><a href="Server.do"
onclck="<c:set var='hostname' value='${hostname}' scope='session'/>">${hostname}</a>
</td>
<td>${hostname.ipAddress}</td>
</tr>
</c:forEach>
</table>
</pre>
</blockquote>

See what I mean? I think I may be forced to use scriptlets. (I had to misspell onclick for the reply, otherwise I get an error on the post.)
 
Andres Quinones
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand your problem is that you want to set a Session attribute in the onlcik event of an <a>?

If this is correct I just want to tell you that this is impossible because the javascript is executed in the client browser. In this case you should send the hostname as a request parameter, in order that the Server.do action could set this parameter in the session scope.

Hope this helps.
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It does. I had to make a helper class to relate the String parameter to the actual enum instance it represents.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!