Adolf Liepelt wrote:
>
> Hello Hans,
>
> Thank you for your answer. I should have asked my question more
> specific:
>
> I want to write a custom tag what converts a date into a well formatted
> germanlike string. So I want to take the bean declared by useBean (which
> can be of any type), call a method on this bean which gives a date back
> and convert this date:
>
> <jsp:useBean id="testBean" class="concept.TestBean" scope="request"/>
> <mylib:date ref="testBean" getProperty="date" />
>
> For now I call the appropriate method on testBean with reflection:
>
> public int doStartTag() throws JspException {
> Object o = pageContext.findAttribute(beanName);
> try {
> Class objectClass = o.getClass();
> Method aMethod = objectClass.getDeclaredMethod(
> convertPropertyNameToGetMethodName(propertyName), null); //
use of a
> private method
> Date date = (Date)aMethod.invoke(o, null);
> pageContext.getOut().print(date); // date formatting not yet
included
> } catch (Exception e) {
> e.printStackTrace();
> }
> return SKIP_BODY;
> }
>
>
> But I am wondering if there is a better way to do this, because in the
> JSP spec on page 109 (5.6.1 Ids and PageContext) is something written
> about id and ref attribute but with no example.
The approach described in 5.6.1 is the one you're using. useBean adds the
bean to a scope (accessible through pageContext) and your date action
gets it, using a name specified by an attribute (ref). There's nothing else
intended by 5.6.1.
> And, at second point,
> there is the TagExtraInfo class which stores type information about
> scripting variables.
>
> I think there is a way to get the TagExtraInfo of the useBean-Tag to get
> the right type or there is any magic about the id and ref attribute. Do
> you know something about that?
TagExtraInfo is used by the JSP container during the translation phase
to generate code with appropriate declarations for scripting variables
created by a custom action. In JSP 1.1, there's no way for one action to
get hold of the TagExtraInfo defined by another action.
So, the approach you're using is the only way I can think of with the
capabilities available in JSP 1.1.
Hans
--
Hans Bergsten [EMAIL PROTECTED]
Gefion Software http://www.gefionsoftware.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets