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>
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:
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 ]
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Joined: Apr 13, 2005
That's exactly what I'm looking for. Thanks much...