You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Samuel Rochas <sa...@andinasoft.com> on 2004/05/27 23:58:26 UTC

only with bean?

Hello there,

I am able to create a html select with struts when the collection to 
display in the options tag is a collection stored in the session or 
request and to use the selected value for my form. Fine.

But now I have a Form representing a bean. This form has an attribute of 
type ArrayList. I'd like the select/options tag to show me the content 
of the ArrayList for the actual Form property value. I want to use the 
form attribute and not create a collection to store in a scope.

My JSP looks like:
<html:form action="data" focus="identification">
<html:text property="identification"/>
<html:select property="selectedItems">
	<html:options collections="allItems"
		property="id" 	labelProperty="description"/>
</html:select>

My form DataForm has the attributes identification, selectedItems and 
allItems.

But it is not working. Anybody a hint?

Sincerly
Samuel

---  andinasoft SA - Software y Consulting  ---
Mariano Aguilera 276 y Almagro - Quito, Ecuador
Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
---------  http://www.andinasoft.com  ---------


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


Re: only with bean?

Posted by Henrique VIECILI <vi...@softplan.com.br>.
Well,

in that case I would put into some scope a collection with beans containing the values and labels and access like this:

<html:options collection="myCollection" property="value" labelProperty="label"/>

or, if you want to retrieve from the Form, you can try this:

<html:optionsCollection name="myForm" property="arrayList" value="value" label="label"/>

where the collection is obtained from myForm.getArrayList(), and the beans in the collection having getLabel() and getValue()

Henrique Viecili
  ----- Original Message ----- 
  From: Samuel Rochas 
  To: Struts Users Mailing List 
  Sent: Friday, May 28, 2004 2:47 PM
  Subject: Re: <html:options> only with bean?


  Hello Henrique,

  Thanks for your answer.

  Your solution suppose I maintain two lists of objects, one for the 
  labels and one for the values.
  Is it not possible to give a list of object, and to use the object 
  properties for the value and for the label?

  Samuel



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

Re: only with bean?

Posted by Samuel Rochas <sa...@andinasoft.com>.
Hello Henrique,

Thanks for your answer.

Your solution suppose I maintain two lists of objects, one for the 
labels and one for the values.
Is it not possible to give a list of object, and to use the object 
properties for the value and for the label?

Samuel



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


Re: only with bean?

Posted by Henrique VIECILI <vi...@softplan.com.br>.
Hi Samuel,

let´s suppose in your form you have the method getArrayListValues() returning the ArrayList containing the values and the method getArrayListLabels() returning the ArrayList containing the values for each option you wanna render. Then:

<html:form action="data" focus="identification">
<html:text property="identification"/>
<html:select property="selectedItem"> <!-- selectedItem must be a single-valued property -->
<html:options property="arrayListValues" labelProperty="arrayListLabels"/>
</html:select>
</html:form>

I think it will work, but you can try this too: (I´m not sure it works)

struts-config.xml
<form-bean name="myForm" type="my.pkg.MyForm"/>

in MyForm there is a method (getValuesAndLabels()) returning a collection containing beans holding the label (getLabel()) and value (getValue()) for each option. Then:

<html:options collection="myForm.valuesAndLabels" property="value" labelProperty="label" />, or maybe:
<html-el:options collection="${myForm.valuesAndLabels}" property="value" labelProperty="label">

Just thoughts,

Henrique Viecili



  ----- Original Message ----- 
  From: Samuel Rochas 
  To: Struts Users Mailing List 
  Sent: Thursday, May 27, 2004 6:58 PM
  Subject: <html:options> only with bean?


  Hello there,

  I am able to create a html select with struts when the collection to 
  display in the options tag is a collection stored in the session or 
  request and to use the selected value for my form. Fine.

  But now I have a Form representing a bean. This form has an attribute of 
  type ArrayList. I'd like the select/options tag to show me the content 
  of the ArrayList for the actual Form property value. I want to use the 
  form attribute and not create a collection to store in a scope.

  My JSP looks like:
  <html:form action="data" focus="identification">
  <html:text property="identification"/>
  <html:select property="selectedItems">
  <html:options collections="allItems"
  property="id" labelProperty="description"/>
  </html:select>

  My form DataForm has the attributes identification, selectedItems and 
  allItems.

  But it is not working. Anybody a hint?

  Sincerly
  Samuel

  ---  andinasoft SA - Software y Consulting  ---
  Mariano Aguilera 276 y Almagro - Quito, Ecuador
  Tel. +593 2 290 55 18 ---- Cel. +593 9 946 4046
  ---------  http://www.andinasoft.com  ---------


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