LoV = List of Values.
In page.jspx
Either
<h:selectOneChoice binding="#{myBean.mySelector}" value="#{whatever}">
<f:selectItem itemValue="someValue" itemLabel="someText"/>
</h:selectOneChoice>
or
<h:selectOneChoice value="#{whatever}">
<f:selectItems value="#{myBean.listOfValues}"/>
</h:selectOneChoice>
In MyBeanClass.java
Either
public class MyBeanClass
{
private UISelectOne mySelector;
public UISelectOne getMySelector()
{
return mySelector;
}
public void setMySelector(UISelectOne mySelector)
{
this.mySelector = mySelector;
}
public String getSelectedDescription()
{
Object selectedValue = mySelector.getValue();
if (selectedValue == null)
{
return null;
}
for (UIComponent child : (List<UIComponent>)mySelector.getChildren())
{
if (selectedValue.equals(child.getItemValue()))
{
return child.getItemLabel();
}
}
return null; // or throw an exception
}
}
or
public class MyBeanClass
{
private List<SelectItem> listOfValues;
public List<SelectItem> getListOfValues()
{
return listOfValues;
}
public String getSelectedDescription()
{
Object selectedValue = mySelector.getValue();
if (selectedValue == null)
{
return null;
}
for (SelectItem item : listOfValues)
{
if (selectedValue.equals(item.getValue()))
{
return item.getLabel();
}
}
return null; // or throw an exception
}
}
That being said, I'm very curious about the use case requiring that.
Regards,
~ Simon
On 8/31/07, daniel ccss <[EMAIL PROTECTED]> wrote:
>
> Sorry but what do you mean with LoV, can you give me some example code of
> the static and dynamic
>
> On 8/31/07, Simon Lessard < [EMAIL PROTECTED]> wrote:
> >
> > Ah ok,
> >
> > It depends on the type of LoV you're using. If you're using a static lov
> > (<f:selectItem/>), then you have to use a binding for your selectOneChoice
> > component to your managed bean. Then, in your method, you simply have to
> > loops through the selectOneMenu's children until you find the right
> > UISelectItem. IF you use a dynamic LoV, it's simpler, as you simply have to
> > call the methods returning the list of values and loops through all returned
> > SelectItem objects.
> >
> >
> > Regards,
> >
> > ~ Simon
> >
> > On 8/31/07, daniel ccss < [EMAIL PROTECTED]> wrote:
> > >
> > > Hi, sorry, yes the correct question is how to:
> > >
> > > loop through the SelectItem list until find the one with the selected
> > > value to extract the description
> > >
> > > Thanks
> > >
> > > On 8/31/07, Simon Lessard <[EMAIL PROTECTED]> wrote:
> > > >
> > > > Hello Daniel,
> > > >
> > > > I don't really understand your question. Can you be a bit more
> > > > specific? If I understand well though, you could either change the value
> > > > property of your SelectItem object, or loop through the SelectItem list
> > > > until you find the one with the selected value to extract the
> > > > description.
> > > >
> > > >
> > > > Regards,
> > > >
> > > > ~ Simon
> > > >
> > > > On 8/31/07, daniel ccss < [EMAIL PROTECTED]> wrote:
> > > > >
> > > > > Hi all,
> > > > >
> > > > > How I can get the selected text, not the code, of a
> > > > > <h:selectOneMenu component?
> > > > >
> > > > > thanks
> > > > >
> > > >
> > > >
> > >
> >
>