struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "James Turner" <>
Subject RE: Another bright idea, make "indexed" work with JSTL forEach and friends
Date Sat, 04 Jan 2003 20:35:40 GMT
On Sat, 4 Jan 2003, Martin Cooper wrote:
> If you want to do this, I'd rather see it happen in the html-el taglib
> than the regular html taglib. Struts-EL already depends on 
> JSTL, and is
> designed to work in cooperation with it, so it's a much more 
> natural fit
> than trying to sneak JSTL functionality into the regular tags.

I mildly disagree.  EL is to allow struts HTML tags to use EL syntax.
This deals with letting the standard tags find JSTL looping constructs.
As is, you can "*almost* entirely eliminate all the Struts tags except
for the HTML tags in favor of JSTL substitutes, since only the HTML tags
deal with things like actions.  By implementing this, we can eliminate
having to use the logic taglibs at all.  And the change is pretty darn
innocuous, here's the revisted code from BaseHandlerTag, which works
very nicely.  Note that I'm not even referencing org.apache stuff.  And
the JSTL stuff is only ever invoked if it fails to find the Iterate tag.

One thing I'm considering is caching the classes and methods so that the
reflection doesn't need to happen on every invokation.

    protected void prepareIndex(StringBuffer handlers, String name)
throws JspException {
	int index = 0;
	boolean found = false;

        // look for outer iterate tag
        IterateTag iterateTag = (IterateTag) findAncestorWithClass(this,
	// Look for JSTL loops
	if (iterateTag == null) {
	    try {
		Class loopClass =
		Object loopTag = findAncestorWithClass(this, loopClass);
		if (loopTag != null) {
		    Method getStatus = 
		    Object status = getStatus.invoke(loopTag, null);
		    Class statusClass = 
		    Method getIndex = 
			statusClass.getDeclaredMethod("getIndex", null);
		    Integer ind = (Integer) getIndex.invoke(status,
		    index = ind.intValue();
		    found = true;
	    catch (ClassNotFoundException ex) {}
	    catch (NoSuchMethodException ex) {}
	    catch (IllegalAccessException ex) {}
	    catch (IllegalArgumentException ex) {}
	    catch (InvocationTargetException ex) {}
	    catch (NullPointerException ex) {}
	    catch (ExceptionInInitializerError ex) {}
	} else {
	    index = iterateTag.getIndex();
	    found = true;
        if (!found) {
            // this tag should only be nested in iteratetag, if it's
not, throw exception
            JspException e = new
            RequestUtils.saveException(pageContext, e);
            throw e;
        if (name != null)
        if (name != null)

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message