You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Elijah Jacobs <el...@hotmail.com> on 2002/03/20 20:35:32 UTC

nested:options not retrieving values

Hi all,

some code would help:

<nested:form ....>
    <nested:iterate property="itemList">
           <nested:text property="name"/>
           <nested:select property="UserId">
                <nested:options collection="userList" property="idValue"
labelProperty="displayValue"/>
           </nested:select>
    </nested:iterate>
</nested:form>

As you can see I have a form that has a reference to an ArrayList "itemList"
and each item on this list has an ArrayList "userList" that holds idValue
and displayValue attributes.

Currently I am getting to my JSP through an action class.  The code above
gives me a NullPointerException. And I figured out that it complains,  not
because userList is empty, but because of property="idValue"
labelProperty="displayValue". In fact I can do this:
   <nested:iterate property="userList">
        Stuff
   </nested:iterate>

and the word "Stuff" will be printed out.  So you might think it's because
the attribute idValue and displayValue are null.

Well, when I put the userList on the request attribute and do this: (where
"things" is my userList)
  <jsp:useBean id="things" type="java.util.ArrayList" scope="request"/>
      <logic:iterate id="all" type="...." collection="<%=things%>">
         <bean:write name="all" property="idValue"/>
        <bean:write name="all" property="displayValue"/>
  </logic:iterate>

the displayValue and idValue is printed out fine.

I was wondering why  <nested:options> was not able to pick up the proper
idValue and displayValue? Can some point me to the direction as to how to go
about solving this? thanks.

Your time is appreciated,

- ej

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Nester iterate and style sheet

Posted by Michael Skariah <ms...@anshinsoft.com>.
Hi Sanjay,

You might want to look into
http://husted.com/struts/resources.htm
RowTag (ZIP file for download) by Amarda Business Systems Ltd - Source for a
Struts-compatible tag to generate alternating row colors in a table by Niall
Pemberton.

Hope this helps.

-MS.


-----Original Message-----
From: Sanjay Choudhary [mailto:java_sc@yahoo.com]
Sent: Wednesday, March 20, 2002 6:23 PM
To: Struts Users Mailing List; arron@keyboardmonkey.com
Subject: Nester iterate and style sheet


Hi guys,

I have the following code
<nested:iterate property="accountCode">
  <TR>
     <TD><nested:checkbox property="toDelete"/></TD>
     <TD width="186" colspan="3">
     <nested:text property="region"/></TD>
  </TR>
</nested:iterate>

To odd rows I wish to apply different style sheet and
to even a different. How can I do this? Didn't like
the idea of hard coding the style sheet values in the
Formbean and then retreive from there.

I tried following
   <TR class="<bean:message key='<bean:write
property='stylesheet' name='accountCode'/>'/>">

I thought I will configure the style sheet names in
application.properties file. But this didn't work.

Please advice.

Thanks,
Sanjay





__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards.
http://movies.yahoo.com/

--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Nester iterate and style sheet

Posted by Sanjay Choudhary <ja...@yahoo.com>.
Hi guys,

I have the following code
<nested:iterate property="accountCode">	
  <TR>
     <TD><nested:checkbox property="toDelete"/></TD>
     <TD width="186" colspan="3">
     <nested:text property="region"/></TD>
  </TR>
</nested:iterate>            

To odd rows I wish to apply different style sheet and
to even a different. How can I do this? Didn't like
the idea of hard coding the style sheet values in the
Formbean and then retreive from there.

I tried following 
   <TR class="<bean:message key='<bean:write
property='stylesheet' name='accountCode'/>'/>">

I thought I will configure the style sheet names in
application.properties file. But this didn't work.

Please advice. 

Thanks,
Sanjay





__________________________________________________
Do You Yahoo!?
Yahoo! Movies - coverage of the 74th Academy Awards�
http://movies.yahoo.com/

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: nested:options not retrieving values

Posted by Arron Bates <ar...@keyboardmonkey.com>.
Because you've specified the "collection" attribute, it's trying to find 
a bean reference under that name specified. Because it has to be a 
reference to a collection itself, it can't be changed to a nested property.

So, expose a bean to the name using the nested:define, in the collection 
attribute, and you should get that bean reference to use the original 
<html:options> tag.
Example...

<nested:iterate property="itemList">
    <nested:define id="defBean" property="myOptionsCollectionProperty" />
    <nested:select property="userId">
        <html:options collection="defBean" property="idValue" 
labelProperty="displayValue" />
    </nested:select>
</nested:iterate>

The simplified nested version, is when you just use the property 
attribute to get a list if objects, that will render their string form. 
Not all that handy when you want to specify the different label and value.

The best solution is in the nightly builds or 1.1 Beta. Use the new 
<nested:optionsCollection> tag that extends the new 
<html:optionsCollection> tag. This is pretty much what you're wanting 
actually. Set the property attribute to the bean property that is a 
collection of beans (that you have), and then set the label and value 
attributes to point to the various bean properties.

So, just replace your <nested:options> line with...
<nested:optionsCollection property="userList" label="displayValue" 
value="idValue" />


Either one of these above will get things happening.


Arron.


Elijah Jacobs wrote:

>Hi all,
>
>some code would help:
>
><nested:form ....>
>    <nested:iterate property="itemList">
>           <nested:text property="name"/>
>           <nested:select property="UserId">
>                <nested:options collection="userList" property="idValue"
>labelProperty="displayValue"/>
>           </nested:select>
>    </nested:iterate>
></nested:form>
>
>As you can see I have a form that has a reference to an ArrayList "itemList"
>and each item on this list has an ArrayList "userList" that holds idValue
>and displayValue attributes.
>
>Currently I am getting to my JSP through an action class.  The code above
>gives me a NullPointerException. And I figured out that it complains,  not
>because userList is empty, but because of property="idValue"
>labelProperty="displayValue". In fact I can do this:
>   <nested:iterate property="userList">
>        Stuff
>   </nested:iterate>
>
>and the word "Stuff" will be printed out.  So you might think it's because
>the attribute idValue and displayValue are null.
>
>Well, when I put the userList on the request attribute and do this: (where
>"things" is my userList)
>  <jsp:useBean id="things" type="java.util.ArrayList" scope="request"/>
>      <logic:iterate id="all" type="...." collection="<%=things%>">
>         <bean:write name="all" property="idValue"/>
>        <bean:write name="all" property="displayValue"/>
>  </logic:iterate>
>
>the displayValue and idValue is printed out fine.
>
>I was wondering why  <nested:options> was not able to pick up the proper
>idValue and displayValue? Can some point me to the direction as to how to go
>about solving this? thanks.
>
>Your time is appreciated,
>
>- ej
>
>--
>To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>