struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <craig...@apache.org>
Subject Re: Subclass Struts tags to work with JSTL?
Date Wed, 17 Jul 2002 02:51:43 GMT


On 16 Jul 2002, David M. Karr wrote:

> Date: 16 Jul 2002 19:42:46 -0700
> From: David M. Karr <dmkarr@earthlink.net>
> Reply-To: Struts Developers List <struts-dev@jakarta.apache.org>
> To: struts-dev@jakarta.apache.org
> Subject: Subclass Struts tags to work with JSTL?
>
> I don't know how much thought has yet gone into how Struts and JSTL can work
> together.  I haven't noticed much serious talk about this.  If these thoughts
> are obvious or ignorant, I apologize.
>

There hasn't been much talk about this on the lists.  Part of that is me
trying to avoid succumbing to the "pay attention to the cool new stuff"
instead of getting 1.1 out the door :-).

> It occurred to me that a straightforward interim solution would be to provide
> tag libraries named "bean-el", "html-el", etcetera.  The actual tag classes
> would just be subclasses of the Struts tags.  The way that the actual JSTL tag
> classes are implemented makes this very easy to do.
>

That would certainly be one way to do it.  The other alternative I was
thinking of was to add a "var" attribute to each existing tag that
supported the "name/property/scope" tuple, and allow you to use either/or
with the same tag.  Of course, that doesn't really cover cases like your
example of the message tag, where you might want to use EL expressions on
more than one of the attributes.

> In fact, I spent about an hour this afternoon implementing and verifying a
> proof of concept (mostly spent updating my environment), adding a
> "bean:el-message" tag to my local CVS of Struts.  For a P.O.C., it was easier
> to add the tag to the existing tag library, but for a real implementation, I
> would want a separate tag library.  The code for the tag is very
> straightforward.  My test derived from "MessageTag", but it could just as
> easily (I believe) derive from "NestedMessageTag".
>
> Does anyone see value to this, or have any other relevant comments?
>
> The tag class just looks like this:
>
> --------------------------
> public class ELMessageTag extends MessageTag
> {
>    public   ELMessageTag()
>    {
>       super();
>       init();
>    }
>
>    private  void  init()
>    {
>       setArg0(null);
>       setArg1(null);
>       ...; // Others
>    }
>
>    public   void  release()
>    {
>       super.release();
>       init();
>    }
>
>    public   int   doStartTag()
>       throws JspException
>    {
>       evaluateExpressions();
>       return (super.doStartTag());
>    }
>
>    private  void  evaluateExpressions()
>       throws JspException
>    {
>       try
>       {
>          setArg0((String) ExpressionUtil.
>                  evalNotNull("el-message", "arg0", getArg0(),
>                              String.class, this, pageContext));
>       }
>       catch (NullAttributeException ex)
>       { setArg0(null); }
>
>       try
>       {
>          setArg1((String) ExpressionUtil.
>                  evalNotNull("el-message", "arg1",getArg1(),
>                              String.class, this, pageContext));
>       }
>       catch (NullAttributeException ex)
>       { setArg1(null); }
>
>       ...; // Others
>    }
> }
> --------------------------
>
> An example usage would be:
>
> --------------------------
> <bean:el-message key="main.totalAlbums.label" arg0="${mainForm.totalAlbumCount}"/>
> --------------------------
>

I think this would be a cool "contrib" thing, if you wanted to work
the tags out and host it here.  That's how the "nested" tags started,
IIRC.


> David M. Karr          ; Java/J2EE/XML/Unix/C++

Craig



--
To unsubscribe, e-mail:   <mailto:struts-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:struts-dev-help@jakarta.apache.org>


Mime
View raw message