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 <[EMAIL PROTECTED]> 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:[EMAIL PROTECTED]]
Sent: 13 April 2005 08:41
To: MyFaces Development; [EMAIL PROTECTED]
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 < [EMAIL PROTECTED] > 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
[EMAIL PROTECTED]

Reply via email to