You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by EROL TEZCAN <st...@yahoo.com> on 2005/07/12 15:38:27 UTC

html:select Problem !!

Hi all,
 
I want to set records come from database into a html:select tag. I found some example like below
<html:select property="selectedItem">
  <html:options collection="customers" property="id" labelProperty="name" />
</html:select>

When I set th options as static , the list comes without any problem. But when I create a html:select dynamicly from DB , I get error.

In my Action class, it has a method called getSikayetler() like this.


 Sikayet sikayet = null;
 ArrayList sikayetler = new ArrayList();

 while (rs.next()) {
                sikayet = new Sikayet();
                sikayet.setSikayetKodu(rs.getString("SIKAYET_KODU"));
                sikayet.setSikayet(rs.getString("ACIKLAMA"));
                sikayetler.add(sikayet);
            }

 

When I created an ArrayList, I send it to my Action class and in my Action class I set this ArrayList to request like below 

 

ArrayList listeDondur = getSikayetler();

request.setAttribute("sikayetler", listeDondur);

 

sikayetler ArrayList is not null and empty, I tested it.

 

How must I use this request object called sikayetler in html:select ? 

 


<html:select property="tumSikayetler">
	<html:options collection="sikayetler" value="sikayetKodu" label="sikayet" />
</html:select>


 

usage of above is wrong?

 

In Sikayet class there are get and set methods like sikayetKodu and sikayet .

 

How can I fill html:select tag with records coming from DB? 

 

Any help, sample codes?

 

Thanks

 

Erol




		
---------------------------------
 Sell on Yahoo! Auctions  - No fees. Bid on great items.

Re: html:select Problem !!

Posted by Martin Gainty <mg...@hotmail.com>.
Erol
Assuming you have your own MyBean which contains 2 string fields 
SIKAYET_KODU and ACIKLAMA
try this in your jsp
<%
List sikayetler = new ArrayList();
sikayetler.add( new MyBean( "SIKAYET_KODU1", "ACIKLAMA1" ));
sikayetler.add( new MyBean( "SIKAYET_KODU2", "ACIKLAMA2" ));
%>
<html:select multiple="true" size="2" property="tumSikayetler">
   <html:options collection="<%=sikayetler%>" property="SIKAYET_KODU" 
labelProperty="ACIKLAMA"/>
</html:select>
Anyone else?
Martin-
----- Original Message ----- 
From: "EROL TEZCAN" <st...@yahoo.com>
To: "sturts_apache_user sturts_apache_user" <us...@struts.apache.org>
Sent: Tuesday, July 12, 2005 9:38 AM
Subject: html:select Problem !!


> Hi all,
>
> I want to set records come from database into a html:select tag. I found 
> some example like below
> <html:select property="selectedItem">
>  <html:options collection="customers" property="id" labelProperty="name" 
> />
> </html:select>
>
> When I set th options as static , the list comes without any problem. But 
> when I create a html:select dynamicly from DB , I get error.
>
> In my Action class, it has a method called getSikayetler() like this.
>
>
> Sikayet sikayet = null;
> ArrayList sikayetler = new ArrayList();
>
> while (rs.next()) {
>                sikayet = new Sikayet();
>                sikayet.setSikayetKodu(rs.getString("SIKAYET_KODU"));
>                sikayet.setSikayet(rs.getString("ACIKLAMA"));
>                sikayetler.add(sikayet);
>            }
>
>
>
> When I created an ArrayList, I send it to my Action class and in my Action 
> class I set this ArrayList to request like below
>
>
>
> ArrayList listeDondur = getSikayetler();
>
> request.setAttribute("sikayetler", listeDondur);
>
>
>
> sikayetler ArrayList is not null and empty, I tested it.
>
>
>
> How must I use this request object called sikayetler in html:select ?
>
>
>
>
> <html:select property="tumSikayetler">
> <html:options collection="sikayetler" value="sikayetKodu" label="sikayet" 
> />
> </html:select>
>
>
>
>
> usage of above is wrong?
>
>
>
> In Sikayet class there are get and set methods like sikayetKodu and 
> sikayet .
>
>
>
> How can I fill html:select tag with records coming from DB?
>
>
>
> Any help, sample codes?
>
>
>
> Thanks
>
>
>
> Erol
>
>
>
>
>
> ---------------------------------
> Sell on Yahoo! Auctions  - No fees. Bid on great items. 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: html:select Problem !!

Posted by EROL TEZCAN <st...@yahoo.com>.
Oh,
 
I think there are two ways to define html:select
 
<html:options collection="xxx" property="" labelProperty=""/>
<html:optionsCollection property="" label="" value=""/>
 
Anyway,
 
Best way to fill the html:select ?
 
Erol

BHansard@powersystems.rockwell.com wrote:

you have the html:options set correctly in the first example
<html:select property="selectedItem">
 <html:options collection="customers" property="id" labelProperty="name" />
</html:select>

in the second example you changed to:
<html:select property="tumSikayetler">
<html:options collection="sikayetler" value="sikayetKodu" label="sikayet" />
</html:select>

try:
<html:select property="tumSikayetler">
<html:options collection="sikayetler" property="sikayetKodu" labelProperty="sikayet" />
</html:select>



" src="cid:10__=0ABBFAAFDFD86F@powersystems.rockwell.com" width=16>EROL TEZCAN <st...@yahoo.com>


EROL TEZCAN <st...@yahoo.com> 
07/12/2005 09:38 AM Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>






To

sturts_apache_user sturts_apache_user <us...@struts.apache.org>
cc


Subject

html:select Problem !!
Hi all,

I want to set records come from database into a html:select tag. I found some example like below
<html:select property="selectedItem">
 <html:options collection="customers" property="id" labelProperty="name" />
</html:select>

When I set th options as static , the list comes without any problem. But when I create a html:select dynamicly from DB , I get error.

In my Action class, it has a method called getSikayetler() like this.


Sikayet sikayet = null;
ArrayList sikayetler = new ArrayList();

while (rs.next()) {
               sikayet = new Sikayet();
               sikayet.setSikayetKodu(rs.getString("SIKAYET_KODU"));
               sikayet.setSikayet(rs.getString("ACIKLAMA"));
               sikayetler.add(sikayet);
           }



When I created an ArrayList, I send it to my Action class and in my Action class I set this ArrayList to request like below 



ArrayList listeDondur = getSikayetler();

request.setAttribute("sikayetler", listeDondur);



sikayetler ArrayList is not null and empty, I tested it.



How must I use this request object called sikayetler in html:select ? 




<html:select property="tumSikayetler">
<html:options collection="sikayetler" value="sikayetKodu" label="sikayet" />
</html:select>




usage of above is wrong?



In Sikayet class there are get and set methods like sikayetKodu and sikayet .



How can I fill html:select tag with records coming from DB? 



Any help, sample codes?



Thanks



Erol





---------------------------------
Sell on Yahoo! Auctions  - No fees. Bid on great items.


		
---------------------------------
 Sell on Yahoo! Auctions  - No fees. Bid on great items.

Re: html:select Problem !!

Posted by BH...@powersystems.rockwell.com.
you have the html:options set correctly in the first example
<html:select property="selectedItem">
  <html:options collection="customers" property="id" labelProperty="name"
/>
</html:select>

in the second example you changed to:
<html:select property="tumSikayetler">
             <html:options collection="sikayetler" value="sikayetKodu"
label="sikayet" />
</html:select>

try:
<html:select property="tumSikayetler">
             <html:options collection="sikayetler" property="sikayetKodu"
labelProperty="sikayet" />
</html:select>





                                                                           
             EROL TEZCAN                                                   
             <struts_jasper@ya                                             
             hoo.com>                                                   To 
                                       sturts_apache_user                  
             07/12/2005 09:38          sturts_apache_user                  
             AM                        <us...@struts.apache.org>            
                                                                        cc 
                                                                           
             Please respond to                                     Subject 
               "Struts Users           html:select  Problem !!             
               Mailing List"                                               
             <user@struts.apac                                             
                  he.org>                                                  
                                                                           
                                                                           
                                                                           




Hi all,

I want to set records come from database into a html:select tag. I found
some example like below
<html:select property="selectedItem">
  <html:options collection="customers" property="id" labelProperty="name"
/>
</html:select>

When I set th options as static , the list comes without any problem. But
when I create a html:select dynamicly from DB , I get error.

In my Action class, it has a method called getSikayetler() like this.


 Sikayet sikayet = null;
 ArrayList sikayetler = new ArrayList();

 while (rs.next()) {
                sikayet = new Sikayet();
                sikayet.setSikayetKodu(rs.getString("SIKAYET_KODU"));
                sikayet.setSikayet(rs.getString("ACIKLAMA"));
                sikayetler.add(sikayet);
            }



When I created an ArrayList, I send it to my Action class and in my Action
class I set this ArrayList to request like below



ArrayList listeDondur = getSikayetler();

request.setAttribute("sikayetler", listeDondur);



sikayetler ArrayList is not null and empty, I tested it.



How must I use this request object called sikayetler in html:select ?




<html:select property="tumSikayetler">
             <html:options collection="sikayetler" value="sikayetKodu"
label="sikayet" />
</html:select>




usage of above is wrong?



In Sikayet class there are get and set methods like sikayetKodu and sikayet
.



How can I fill html:select tag with records coming from DB?



Any help, sample codes?



Thanks



Erol





---------------------------------
 Sell on Yahoo! Auctions  - No fees. Bid on great items.