Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem writing from tag  RSS feed

 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it that the first 5 lines below print out in my JSP, but the last 5 lines (starting with the radio line) won't?

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 37242
519
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are you expecting this line to do?


I might be wrong, but I thought the EL expression got evaluated before the tag.
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jeanne Boyarsky wrote:What are you expecting this line to do?


I might be wrong, but I thought the EL expression got evaluated before the tag.


I'm trying to print out Struts radio buttons.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Jeanne indicated, but the time a JSP is executing, the translation phase where tags would be evaluated is long past.

I'd recommend taking some time and reading this article to better understand how JSPs operate and the their lifecycle.

To sum it up, you can't use a tag to emit other tags.
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:To sum it up, you can't use a tag to emit other tags.


Okay, that means I need to do some re-thinking about how I'm doing things here. What I'm trying to do is design a JSP with a poll question in it. If the user hasn't voted, he should see the question and have a chance to vote. If he has, I want to show him the results of the poll so far. I want the Struts Action class (which I haven't written yet, and is not germane to the JSP board anyway) to process the vote and send back a cookie indicating that the user has voted. What I want the tag to do is see if the cookie exists and tell the JSP.

Here's the musical question: is it possible for the JSP to read a boolean variable from the tag? If the boolean variable is true, the user gets the poll results. If it's false, the user gets the Struts form, which would be encoded in the JSP itself. I know enough about JSTL to know how to use variables local to the JSP, but I'm not sure if the JSP can take a variable from a tag. Maybe I missed it in the link that Bear put up, but I didn't see anything about how to accomplish that, i. e., what syntax I would be using. I'm presuming I'm going to need a c:if statement here. If I'm wrong, please set me straight.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not exactly sure what you are asking, but if you are asking if a tag can set a scoped variable that the JSP can test for, then yes.
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Not exactly sure what you are asking, but if you are asking if a tag can set a scoped variable that the JSP can test for, then yes.


Yes, that sounds like what I'm asking. I've Googled and figured out how to use c:set to declare a variable in the JSP, but the one thing I don't understand is this. How do I associate a variable in my JSP with a variable in my tag? In other words, how do I let the JSP know that the variable set in the tag is the variable I want the JSP to test for?
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frank Serkland wrote:How do I associate a variable in my JSP with a variable in my tag? In other words, how do I let the JSP know that the variable set in the tag is the variable I want the JSP to test for?


Wait, I bet I can use PageContext.setAttribute() for that. Am I right?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66205
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes
 
Frank Serkland
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Yes


This worked. Thank you, Bear.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!