You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@myfaces.apache.org by Roger Lee <ro...@42objects.com> on 2005/04/12 18:12:08 UTC
Getting Values from selectOneListbox
I populate a selectOneListbox with data from a table from a backing class;
<h:selectOneListbox id="loanSelectionListbox"
value="#{loanSelectionListDataModelBean.loanName}"
valueChangeListener="#{loanSelectionListDataModelBean.selectedLoanNameList}"
immediate="true">
<f:selectItems
value="#{loanSelectionListDataModelBean.loanNameList}" />
</h:selectOneListbox>
value = valueChangeEvent.getNewValue();
This give the element number select in the list 1-99 etc
How do I get the actual value text (Loan Name)?
Thanks,
Roger Lee
Re: Getting Values from selectOneListbox
Posted by Heath Borders <he...@gmail.com>.
You need to use converters.
You should create your SelectItems in the following way:
List loans = // get your loans
List loanItems = new ArrayList(loans.size());
for (Iterator i = loans.iterator(); i.hasNext();)
{
Loan loan = (Loan) i.next();
loanItems.add(new SelectItem(loan, loan.getName());
}
Then somewhere else in your bean, you have a converter:
private static final class LoanConverter implements Converter
{
public String getAsString(FacesContext p_ctx, UIComponent p_component,
Object p_value)
{
Loan loan = (Loan) p_value;
String s = // convert the loan to a String somehow, either using an id, or
XML conversion or something.
return s;
}
public Object getAsObject(FacesContext p_ctx, UIComponent p_component,
String p_value)
{
Loan loan = // do some processing on p_value to create a loan from it.
Should be the inverse of
// getAsString
return loan;
}
}
Then you have a property on your bean:
public Converter getLoanConverter()
{
return new LoanConverter();
}
and then in your JSP:
<h:selectOneListbox id="loanSelectionListbox"
converter="#{loanSelectionListDataModelBean.loanConverter}"
value="#{loanSelectionListDataModelBean.loanName}"
valueChangeListener="#{loanSelectionListDataModelBean.selectedLoanNameList}"
immediate="true">
<f:selectItems
value="#{loanSelectionListDataModelBean.loanNameList}" />
</h:selectOneListbox>
On 4/13/05, Roger Lee <ro...@42objects.com> wrote:
>
> It involves a call to an EJB which returns an ArrayList populated with
> the data;
>
> // Get Loan Name
>
> String sLoanName = loan.getName();
>
> intCount++;
>
> String sCount = (new Integer(intCount)).toString();
>
> SelectItem selectItem = new SelectItem(sCount, sLoanName, "");
>
> alLoansList.add(selectItem);
>
> alLoansList is returned and used to populate the "selectOneListbox".
>
> There is not a problem with the backing bean. Every is populated
> correctly. I can get the "sCount" but it is the "sLoanName" I can't get!
>
> ------------------------------
>
> *From:* Bruno Aranda [mailto:brunoaranda@gmail.com]
> *Sent:* 13 April 2005 08:41
> *To:* MyFaces Development; roger.lee@42objects.com
> *Subject:* Re: Getting Values from selectOneListbox
>
> How do you create the list of SelectItems in your backing bean
> (loanNameList)?
>
> On 4/12/05, *Roger Lee* <roger.lee@42objects.com > wrote:
>
> I populate a selectOneListbox with data from a table from a backing class;
>
>
> <h:selectOneListbox id="loanSelectionListbox"
> value="#{loanSelectionListDataModelBean.loanName}"
>
> valueChangeListener="#{loanSelectionListDataModelBean.selectedLoanNameList}"
>
> immediate="true">
> <f:selectItems
> value="#{loanSelectionListDataModelBean.loanNameList}" />
> </h:selectOneListbox>
>
> value = valueChangeEvent.getNewValue ();
>
> This give the element number select in the list 1-99 etc
>
> How do I get the actual value text (Loan Name)?
>
> Thanks,
>
> Roger Lee
>
>
--
-Heath Borders-Wing
hborders@mail.win.org
RE: Getting Values from selectOneListbox
Posted by Roger Lee <ro...@42objects.com>.
It involves a call to an EJB which returns an ArrayList populated with the
data;
// Get Loan Name
String sLoanName = loan.getName();
intCount++;
String sCount = (new Integer(intCount)).toString();
SelectItem selectItem = new SelectItem(sCount, sLoanName, "");
alLoansList.add(selectItem);
alLoansList is returned and used to populate the "selectOneListbox".
There is not a problem with the backing bean. Every is populated correctly.
I can get the "sCount" but it is the "sLoanName" I can't get!
_____
From: Bruno Aranda [mailto:brunoaranda@gmail.com]
Sent: 13 April 2005 08:41
To: MyFaces Development; roger.lee@42objects.com
Subject: Re: Getting Values from selectOneListbox
How do you create the list of SelectItems in your backing bean
(loanNameList)?
On 4/12/05, Roger Lee <roger.lee@42objects.com > wrote:
I populate a selectOneListbox with data from a table from a backing class;
<h:selectOneListbox id="loanSelectionListbox"
value="#{loanSelectionListDataModelBean.loanName}"
valueChangeListener="#{loanSelectionListDataModelBean.selectedLoanNameList}"
immediate="true">
<f:selectItems
value="#{loanSelectionListDataModelBean.loanNameList}" />
</h:selectOneListbox>
value = valueChangeEvent.getNewValue ();
This give the element number select in the list 1-99 etc
How do I get the actual value text (Loan Name)?
Thanks,
Roger Lee
Re: Getting Values from selectOneListbox
Posted by Bruno Aranda <br...@gmail.com>.
How do you create the list of SelectItems in your backing bean
(loanNameList)?
On 4/12/05, Roger Lee <ro...@42objects.com> wrote:
>
> I populate a selectOneListbox with data from a table from a backing class;
>
> <h:selectOneListbox id="loanSelectionListbox"
> value="#{loanSelectionListDataModelBean.loanName}"
>
> valueChangeListener="#{loanSelectionListDataModelBean.selectedLoanNameList
> }"
> immediate="true">
> <f:selectItems
> value="#{loanSelectionListDataModelBean.loanNameList}" />
> </h:selectOneListbox>
>
> value = valueChangeEvent.getNewValue();
>
> This give the element number select in the list 1-99 etc
>
> How do I get the actual value text (Loan Name)?
>
> Thanks,
>
> Roger Lee
>
>