Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting a dynamically named scope attribute

 
JohnWilliam Fitz
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Yes. ;o)

Should I write my own tag?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JohnWilliam Fitz wrote:Yes. ;o)

/unsubscribes
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • 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?
 
Victor Williams Stafusa da Silva
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • 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
  • 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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic