• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Setting attributes in forms or anchors

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a way to set an attribute (c:set) in an <a> or <form> before performing the action?
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.)
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic