Return-Path: Delivered-To: apmail-myfaces-users-archive@www.apache.org Received: (qmail 75938 invoked from network); 31 Aug 2007 16:51:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 31 Aug 2007 16:51:49 -0000 Received: (qmail 89222 invoked by uid 500); 31 Aug 2007 16:51:40 -0000 Delivered-To: apmail-myfaces-users-archive@myfaces.apache.org Received: (qmail 88959 invoked by uid 500); 31 Aug 2007 16:51:39 -0000 Mailing-List: contact users-help@myfaces.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "MyFaces Discussion" Delivered-To: mailing list users@myfaces.apache.org Received: (qmail 88948 invoked by uid 99); 31 Aug 2007 16:51:39 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2007 09:51:39 -0700 X-ASF-Spam-Status: No, hits=2.0 required=10.0 tests=HTML_MESSAGE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of simon.lessard.3@gmail.com designates 209.85.146.177 as permitted sender) Received: from [209.85.146.177] (HELO wa-out-1112.google.com) (209.85.146.177) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 31 Aug 2007 16:51:35 +0000 Received: by wa-out-1112.google.com with SMTP id l24so1057974waf for ; Fri, 31 Aug 2007 09:51:15 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=ZP7Hsm6d2Zx/lFVW7J5BKt7IKdOBZ+n++tTzKzgLe/RK07uzDM1+gyA3MpUK4V9Xm3Mm2eDuu+RSufhcmoT+H43b1Imhwg1exEHZ217LFE8AWyR9VuozjpyfGi9/SxU2JidTESYOB2oIBNNCX5cAA0Sbrpu56E2ueFBbaPA7uSM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=MnvO+UNKD8fXbSFPJvjhmwYn0qnEh/jrw4AObo7G9mKt4QTA2w6DZND/30PiEXeVIbzG21ASgmtKQWRmZEtF1hqzyS5JBQI4nHKVcGPB3Tdw4mYh/lhn4rj+CqxeEaDoiwWV8zIXmIkLf0ykusDDWYI8G1mKEgiWPNRIzfpX6mA= Received: by 10.114.133.1 with SMTP id g1mr785354wad.1188579073752; Fri, 31 Aug 2007 09:51:13 -0700 (PDT) Received: by 10.114.152.7 with HTTP; Fri, 31 Aug 2007 09:51:13 -0700 (PDT) Message-ID: <254acf980708310951v1e41753esd901f5e3333b22a2@mail.gmail.com> Date: Fri, 31 Aug 2007 12:51:13 -0400 From: "Simon Lessard" To: "MyFaces Discussion" Subject: Re: SelectOneMenu text In-Reply-To: <2bd5ed640708310852j14cb6600y7615cb634db9ea23@mail.gmail.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_7953_19411052.1188579073452" References: <2bd5ed640708310719v3ef60f2cy883c427b59864979@mail.gmail.com> <254acf980708310723i88529a5tf59f87dec8ba0c2e@mail.gmail.com> <2bd5ed640708310725s218c414etdede59657c6d6e3b@mail.gmail.com> <254acf980708310738j18331ab3h7d7efb9632115590@mail.gmail.com> <2bd5ed640708310852j14cb6600y7615cb634db9ea23@mail.gmail.com> X-Virus-Checked: Checked by ClamAV on apache.org ------=_Part_7953_19411052.1188579073452 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline LoV = List of Values. In page.jspx Either or 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)mySelector.getChildren()) { if (selectedValue.equals(child.getItemValue())) { return child.getItemLabel(); } } return null; // or throw an exception } } or public class MyBeanClass { private List listOfValues; public List 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 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 < simon.lessard.3@gmail.com> wrote: > > > > Ah ok, > > > > It depends on the type of LoV you're using. If you're using a static lov > > (), 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 < danielccss2@gmail.com> 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 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 < danielccss2@gmail.com> wrote: > > > > > > > > > > Hi all, > > > > > > > > > > How I can get the selected text, not the code, of a > > > > > > > > > > > > > > thanks > > > > > > > > > > > > > > > > > > > ------=_Part_7953_19411052.1188579073452 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 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 set
MySelector(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 <danielccss2@gmail.com> 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 < simon.lessard.3@gmail.com> 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 < danielccss2@gmail.com> 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 <simon.lessard.3@gmail.com> 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 < danielccss2@gmail.com> wrote:
Hi all,

How I can get the selected text, not the code, of a <h:selectOneMenu component?

thanks





------=_Part_7953_19411052.1188579073452--