Where did you derive the code snippet you sent?  Is it possible there is some name 
collision ('element')?

AFAIK, the nested tags simply set the stage (set the bean name and property) and 
delegate the actual iteration to their <logic> counterpart.

Sri

-----Original Message-----
From: Jim Krygowski [mailto:[EMAIL PROTECTED]] 
Sent: Friday, December 13, 2002 11:39 AM
To: Struts Users Mailing List
Subject: RE: Page scope bean and nested:iterate


Hi Sri-

Thanks for trying.  If I don't nest the element.getName() in the logic tag it 
completely blows up with a big fat NullPointerException.  The element is definitely 
not there.  I stepped through the code and it looks like id is always getting removed 
from the page context!

This is the code that does the work:

        if (iterator.hasNext()) {
            Object element = iterator.next();
            if (element == null)
                pageContext.removeAttribute(id);
            else
                pageContext.setAttribute(id, element);
            lengthCount++;
            started = true;
            if (indexId != null)
                pageContext.setAttribute(indexId, new Integer(getIndex()));
            return (EVAL_BODY_TAG);
        } else
            return (SKIP_BODY);

element is always null (even though stuff is rendering on my JSP) so the id is always 
getting pulled out of the pageContext.  But index id keeps getting set.  This is 
pretty confusing,  I don't know if I should trust my debugger or not, but it 
definitely looks like something strange is going on.

All this makes me wonder if the Nested code is doing an end run around the id and just 
passing references to the containing object to its nested tags?

jk


> -----Original Message-----
> From: Sri Sankaran [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 13, 2002 11:24 AM
> To: Struts Users Mailing List
> Subject: RE: Page scope bean and nested:iterate
>
>
> The id attribute of the <nested:iterate> is a handle to the current 
> element in the iteration.  So, by definition, the reference cannot be 
> null -- 'cos if it were, you'd be out of the iteration.  Make sense?  
> So, methinks you *shouldn't* need to test if it is present.
>
> I know all this doesn't explain your NPE.
>
> Just for grins can you try changing the
>
> <nested:write property="name"/>
>
> to
>
> <%=element.getName()%>
>
> If 'element' is null, *that* should blow up too.  I am puzzled as to 
> how the bean at element can be null.
>
> Sorry if this didn't help any bit.
>
> Sri
>
> -----Original Message-----
> From: Jim Krygowski [mailto:[EMAIL PROTECTED]]
> Sent: Friday, December 13, 2002 10:51 AM
> To: Struts Users Mailing List
> Subject: Page scope bean and nested:iterate
>
>
> Hi-
>
> I'm using nested:iterate and have not been successful in using the id 
> attribute of the iterate tag.  The documentation for nested:iterate is 
> just the documentation for logic:iterate so I would imagine that 
> nested:iterate should support id.
>
> I have some code like where theBean is the source of the objects I'm 
> iterating over:
>
>       <nested:iterate id="element" indexId="currentIndex" 
> property="theBean">
>          <logic:present name="element">
>             <%=element.hashCode()%><br>
>          </logic:present>
>          <nested:write property="name"/><br>
>          <%=currentIndex.intValue()%>
>
>       </nested:iterate>
>
> The following code runs and outputs just the value of the name and the 
> current index number.  If I removed the logic:present, I get a runtime 
> error because element is null.  I think this should work, but it 
> doesn't.  Why?
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to