> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Saturday, October 12, 2002 11:32 PM
> To: [EMAIL PROTECTED]
> Subject: checkbox name
> "org.apache.struts.taglib.html.BEAN[0].stringProperty"?
> 
> 
> I've been adding more "exercises" to the Struts-EL 
> exercise-taglib app, and I'm
> finding some behavior I don't quite understand.
> 
> In the same JSP page, I have two "logic-el:iterate" loops, 
> both of which
> iterate through the same collection, the page attributes map 
> ("${pageScope}").
> One loop has an "html-el:button" in each iteration, and the 
> other has a
> "html-el:checkbox".  Both of them set the "indexed" property 
> to true ("${!empty
> pageScope}" is always true).  After seeing the generated 
> HTML, I'm certain that
> I'm unsure what I should expect for the "name" attribute in 
> the generated HTML.
> 
> This is the "button" loop:
> 
>   <logic-el:iterate collection="${pageScope}" id="item">
>    <html-el:button property="stringProperty" 
> indexed="${!empty pageScope}"/>
>   </logic-el:iterate>
> 
> And this is what it generates for the first iteration:
> 
>   <input type="button" name="stringProperty[0]" value="Click">
> 
> This is the "checkbox" loop:
> 
>   <logic-el:iterate collection="${pageScope}" id="item">
>    <html-el:checkbox property="stringProperty" 
> indexed="${!empty pageScope}"/>
>   </logic-el:iterate>
> 
> And this is what the first iteration generates:
> 
>   <input type="checkbox" 
> name="org.apache.struts.taglib.html.BEAN[0].stringProperty"
> 
> I have a small feeling that the placement of the "[0]" is 
> expected, but I'm
> pretty sure the odd bean name is unexpected.
> 

One important difference to note between the button and checkbox tags is
that the checkbox tag looks up a value to render based on the usual
name/property pair, while the button tag does not. That difference would
appear to be pertinent here.

The odd looking bean name is coming from the absence of the 'name' attribute
on the checkbox tag. If 'name' is not specified, the property is looked up
on the form bean, which is stored in request scope under the o.a.s.t.h.BEAN
key.

I have not used the 'indexed' attribute myself, so I can't make definitive
statements about how it's supposed to work. However, it seems to me that,
where both 'name' and 'property' are valid, the 'name' attribute should be
taken into account when obtaining an initial value to be output to the page,
but should be ignored when generating the name of the value to be submitted
back to the server.

This follows, really, from the way the tags work in the non-indexed case.
The 'property' attribute always names the corresponding request parameter
coming back to the server. The 'name' attribute, however, is only used to
find the initial value, whether it's to be looked up on the form bean, or
some other named bean. It is not relevant to what is submitted back to the
server.

That being the case, I believe the HTML generated for the 'name' attribute
in both cases should be the same, viz 'stringProperty[0]'.

Hope this helps.

--
Martin Cooper


> Could someone help me understand what I should expect here, 
> and what might be
> going wrong if this is incorrect?  If I know what I SHOULDN'T 
> be seeing, I
> could try to track it down a little more.
> 
> -- 
> ===================================================================
> David M. Karr          ; Java/J2EE/XML/Unix/C++
> [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