• 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
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

setting a dynamically named scope attribute

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

I want to set a session scope attribute in my jsp, but I will only know the name of the attribute to set at runtime (long story).

I first tried something like this...

<c:set var="prefix" value="${something}" />
<c:set var="attribName" value="${prefix}Attrib" />
<c:set var="${attribName} value="howdy" />

...but alas <c:set> does not accept expressions for the var attribute (which I knew but forgot).

So, before I go writing my own custom tag to do this, I'd like to know: Does something already exist in JSTL or the standard custom tag library <jsp:xxx> to do this? Or perhaps in struts 1.x (which I am using in this project)?

Thanks muchly!
John
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is there a reason that you are doing this in the JSP rather than the controller?
 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. ;o)

Should I write my own tag?
 
Bear Bibeault
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

JohnWilliam Fitz wrote:Yes. ;o)


/unsubscribes
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why is the name of the attribute dynamic? Why not just set a known name on the Java side with the value you need?
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got the same problem. Believe it. There is a reason for this.

Let's say you got a tag-file:



I.E. The purpose is to set some value taken from EL or some HTML and make it visible to the caller. Using taglibs is not good enough, because handling the HTML in java code sucks. Normally, the HTML and the inserted value should be unentangled, but if the inserted value is a bunch of complicated HTML, it simply can't be well unentangled.

But, it is very simple to write a SimpleTag to simulate a <c:set> where the var is rtexprvalue. So, in my opinion, <c:set> should have the var attribute with rtexprvalue="true", so nobody would need to reinvent the well in this point.
 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why? I'm in a contest for the worst programmer of the month at my company and the competition is stiff. ;o)
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic