You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Rick Reumann <ma...@reumann.net> on 2002/07/02 04:22:29 UTC

How to avoid a scriplet and make this cleaner?

For this example I have an ArrayList of "cars" (which are CarBeans
with String carName, int id ). I want to iterate over this ArrayList
and set up each car name with a checbox next to it with the id as the
value. My FormBean has the property String[] carID to get the cars
selected.

The problem is I can't seem to avoid using a scriplet and can't seem
to use the checkbox tag to set up the following:

<logic:iterate id="element" name="cars" >
  <TR>
    <TD><bean:write name="element" property="carName"/></TD>
    <TD>
      <input type="checkbox" name="carID" value="<%= ((CarBean)element).getId() %>"/>
    </TD>
 </TR>
</logic:iterate>

I want to avoid having to use the scriplet for the value above. I also
get errors when I try to use the tag for the checkbox with the
scriplet:

<html:checkbox property="carID" value="<%= ((CarBean)element).getId() %>" />


Any ideas how I can make the above code cleaner and/or get the
checkbox tag to work?

TIA

--

Rick

mailto:maillist@reumann.net


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


Re[2]: How to avoid a scriplet and make this cleaner?

Posted by Rick Reumann <ma...@reumann.net>.
Thanks for trying to help Kevin..comments below...

On Monday, July 1, 2002, 10:46:05 PM, Kevin Henrikson wrote:

KH> <html:checkbox property="carID" value="<%=(String)((CarBean)element).getId() %>"
/>>

   The above wouldn't work since I can't cast a primitive int to a
   String like that, but even
   <%= Integer.parseInt( ((CarBean)element).getId() ) %>
   wouldn't work. It's only inside of a tag that I have this problem
   using <%= %> syntax or even <% %> which doesn't work at all. Oh
   well, with the below I'm fine...

KH> Also you might want to check out multibox... Like this:

KH> <logic:iterate id="element" name="cars">
KH>      <html:multibox property="carID">
KH>        <bean:write name="element" property="id" />
KH>      </html:multibox>
KH> </logic:iterate>

    Thanks Kevin! That multibox works perfectly. No need to use the
    scriplet above when using the multibox like:

    <logic:iterate id="element" name="cars">
         <TR>
            <TD><bean:write name="element" property="carName"/></TD>
            <TD>
             <html:multibox property="carID">
               <bean:write name="element" property="id" />
             </html:multibox>
            </TD>
         </TR>
    </logic:iterate>

    </END RICK COMMENTS>

>> -----Original Message-----
>> From: Rick Reumann [mailto:maillist@reumann.net]
>> Sent: Monday, July 01, 2002 7:22 PM
>> To: Struts Users Mailing List
>> Subject: How to avoid a scriplet and make this cleaner?
>>
>>
>> For this example I have an ArrayList of "cars" (which are CarBeans
>> with String carName, int id ). I want to iterate over this ArrayList
>> and set up each car name with a checbox next to it with the id as the
>> value. My FormBean has the property String[] carID to get the cars
>> selected.
>>
>> The problem is I can't seem to avoid using a scriplet and can't seem
>> to use the checkbox tag to set up the following:
>>
>> <logic:iterate id="element" name="cars" >
>>   <TR>
>>     <TD><bean:write name="element" property="carName"/></TD>
>>     <TD>
>>       <input type="checkbox" name="carID" value="<%=
>> ((CarBean)element).getId() %>"/>
>>     </TD>
>>  </TR>
>> </logic:iterate>
>>
>> I want to avoid having to use the scriplet for the value above. I also
>> get errors when I try to use the tag for the checkbox with the
>> scriplet:
>>
>> <html:checkbox property="carID" value="<%= ((CarBean)element).getId() %>" />
>>
>>
>> Any ideas how I can make the above code cleaner and/or get the
>> checkbox tag to work?
>>
>> TIA
>>
>> --
>>
>> Rick


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


RE: How to avoid a scriplet and make this cleaner?

Posted by Kevin Henrikson <ke...@openwave.com>.
Try to cast the value to a string.

<html:checkbox property="carID" value="<%=(String)((CarBean)element).getId() %>"
/>

Also you might want to check out multibox... Like this:

<logic:iterate id="element" name="cars">
     <html:multibox property="carID">
       <bean:write name="element" property="id" />
     </html:multibox>
</logic:iterate>


-kevin

> -----Original Message-----
> From: Rick Reumann [mailto:maillist@reumann.net]
> Sent: Monday, July 01, 2002 7:22 PM
> To: Struts Users Mailing List
> Subject: How to avoid a scriplet and make this cleaner?
>
>
> For this example I have an ArrayList of "cars" (which are CarBeans
> with String carName, int id ). I want to iterate over this ArrayList
> and set up each car name with a checbox next to it with the id as the
> value. My FormBean has the property String[] carID to get the cars
> selected.
>
> The problem is I can't seem to avoid using a scriplet and can't seem
> to use the checkbox tag to set up the following:
>
> <logic:iterate id="element" name="cars" >
>   <TR>
>     <TD><bean:write name="element" property="carName"/></TD>
>     <TD>
>       <input type="checkbox" name="carID" value="<%=
> ((CarBean)element).getId() %>"/>
>     </TD>
>  </TR>
> </logic:iterate>
>
> I want to avoid having to use the scriplet for the value above. I also
> get errors when I try to use the tag for the checkbox with the
> scriplet:
>
> <html:checkbox property="carID" value="<%= ((CarBean)element).getId() %>" />
>
>
> Any ideas how I can make the above code cleaner and/or get the
> checkbox tag to work?
>
> TIA
>
> --
>
> Rick
>
> mailto:maillist@reumann.net
>
>
> --
> 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>


I'm Lost - How to display ArrayList of Hashtables

Posted by Matt Barnicle <br...@barnicle.org>.
Hey all...  I've done this in many languages including Java, but I can't
seem to figure out how to do it in struts.  For some reason the struts
paradigm is very difficult for me.  Enough whining though.  My situation
is that I have a search page.  I search a directory given a person's
name.  I retrieve a list of possible matches (or exact match) to that
name.  I store the results in a bean 
org.my.company.PeopleSearchResults.  That's my first question.  How do I
store this data?  Right now, I have 'private ArrayList searchResults',
which gets populated when the object is constructed, then stored in the
request scope.  Then the search gets forwarded to the search_results.jsp
page.  I then have to display the attributes in certain places on the
page, like:

Name: <bean:write name="commonName">
Dept: <bean:write name="department">

etc., etc...  What I have so far looks like this:

<bean:define id="resultsBean" name="peopleSearchResults" scope="request"
  type="org.my.company.PeopleSearchResults" />

<logic:iterate 
id="resultsIterator" name="resultsBean" property="searchResults">
  This logic tag works ok, but inside here is where everything I've
  tried so far falls apart.
</logic:iterate>

I _do_ have a property getter method in my bean, "public ArrayList
getSearchResults()", which seems to work ok.  Am I doing this right so
far?  What do I need to do to finish the job?

- M@

P.S.  Struts 1.0.2, Tomcat


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