• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Return value from within tag

 
Ian Beckley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I work for a small software company and the majority of my duties entail writing examples for our help files. I program in VB, C++ and dotNet but we are getting ready to release a java version of one of our products so I have to familiarize myself with the java language. Doing things is servlets is fairly easy, but when using a .jsp page I can't figure out how to return values from within tags. Given the following code how would I, for example, return the value of "text" so that a user could verify it. Can it be done from outside the tag? ...

<fpspread:cell row="5" col="-1">
<fpspread:button text="Click Me" command="MyCommand" buttonType="push" />
</fpspread:cell>
 
Ryan McGuire
Ranch Hand
Posts: 1069
4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you say you want to "return" the value of text, do you mean how do you get it to show up in the browser?

In button.doStartTag() put something like...

...or whatever HTML you want.

Inside of the button.java (Java class name == tag name), the identifier "pageContext" refers to the PageContext object that allows you acces to all sorts of stuff, including the output stream that sends data to the user's browser.

Also, for each custom tag attribute, such as "text", in the JSP you'll have a getter and a setter, such as getText() and setText(). The attribute name is automatically "mangled" so that the method names are in what they call "camel case", the first letter lower-case and subsequent words capitalized. An attribute like buttonType would have corresponding getButtonType() and setButtonType() methods.

On the other hand...
If by "return" you mean you want to pass back some value that the JSP can use later, well that gets a little more complicated. You'll need to use the pageContext to get the HttpSession object, set a value in there, and then retrieve that value in your JSP:

In button.doStartTag():


Then in your JSP:


(In the JSP, "session" is a predefined HttpSession variable.)

(edit)That depends on what class your JSP engine uses for JSPs. I'm using BEA Weblogic 6.someodd, so all my JSPs get translated to classes subclassing weblogic.servlet.jsp.JspBase. Worst-case, you'll have to get the HttpSession from the HttpRequest object named "request", which I believe is pretty standard for all JSP->Java class translaters.(/edit)

Is this what you were looking for?

Ryan
[ April 13, 2005: Message edited by: Ryan McGuire ]
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to JSP...
 
Ian Beckley
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ryan -

That's exactly what I'm looking for. Thanks much...
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and of course you'd use JSTL instead of scriptlets (and probably requestscope instead of sessionscope)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic