You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Stefan Hedtfeld <st...@xsoftahead.com> on 2007/01/29 21:17:36 UTC

[tobago] displaying complex values in tx:selectOneChoice

Hi,

I'm trying to display some complex values within a tx:selectOneChoice
element. What I've managed so far is the following:

1. The tag:

          <tx:selectOneChoice
value="#{editorController.currentEntry.member}"
                 label="#{mainBundle.member}" >
            <f:selectItems value="#{editorController.memberItems}" />
          </tx:selectOneChoice>

2. The item list (memberItem):

    ...
    // list is declared as List<Person> list above
    ...
    List<SelectItem> items = new ArrayList<SelectItem>();
    for (Person person : list) {
      items.add(new SelectItem(person, converter.getAsString(person)));
    }
    return items;

3. The converter registered for the Person class (an instance of
Converter with an additional convenience method getAsString(Person p) -
this method is accessible from a caller through the second interface):

public class PersonConverter implements Converter,
AsStringConverter<Person> {

  private static final Log LOG = LogFactory.getLog(PersonConverter.class);

  public Object getAsObject(FacesContext context, UIComponent component,
String value) throws ConverterException {
    if (StringUtils.isEmpty(value)) {
      return null;
    }
    try {
      int posOpen = value.lastIndexOf("(");
      int posClose = value.lastIndexOf(")");
      if (posOpen >= 0 && posClose > posOpen) {
        String substring = value.substring(posOpen + 1, posClose);
        LOG.info("#+#+# Substring = \"" + substring + "\"");
        int personId = Integer.parseInt(substring);
        return
ProjectManagementHelper.getProjectManagement().getPerson(personId);
      }
    } catch (NumberFormatException e) {
      LOG.error("", e);
    }
    return null;
  }

  public String getAsString(FacesContext context, UIComponent component,
Object obj) throws ConverterException {
    if (obj == null) {
      LOG.info("###+++ received null value! +++###");
      return null;
    }
    if (obj instanceof Person) {
      LOG.info("###+++ received Person instance! +++###");
      return getAsString((Person) obj);
    }
    throw new ConverterException("Expected " + Person.class.getName() +
", received " + obj.getClass().getName());
  }

  public String getAsString(Person person) {
    StringBuilder builder = new StringBuilder();
    if (person.getSalutation() != null) {
      builder.append(person.getSalutation().getName()).append(" ");
    }
    if (!StringUtils.isEmpty(person.getFirstname())) {
      builder.append(person.getFirstname()).append(" ");
    }
    return builder.append(person.getLastname()).append("
(").append(person.getId()).append(")").toString();
  }

}

This at least works, but it is kind of ugly UI as I had to code the
object's internal id into the String displayed in the list. So my own
entry could be "Mr. Stefan Hedtfeld (2)" - which is not the intended
way. I'd like to simply display "Mr. Stefan Hedtfeld".

Is there a better way to handle this?

Regards,

Stefan.

Re: [tobago] displaying complex values in tx:selectOneChoice

Posted by Stefan Hedtfeld <st...@xsoftahead.com>.
Hi,

yes, that's exactly what I meant! I implemented a method
getDisplayLable() on my Person class and use it inside the <tc:out .../>
tag.

Thanks again for your suggestions!

Regards,

Stefan.


Volker Weber schrieb:
> Hi,
>
> i'm not sure if i understand this correct, if not please explain with
> jsf source.
>
> You have list of objects containing a person, and display this in a
> sheet?
> e.g:
> <tc:sheet ... var="item" >
>  ...
>  <tc:column ...>
>    <tc:out value="#{item.person}"/>
>  </tc:column>
>  ...
> </tc:sheet>
>
> this will result in the id with your converter.
>
> two possible solutions:
>  add a special method to the person class: getAsLabel()
>    and use <tc:out value="#{item.person.asLabel}"/>
>  or add all properties to the valueBinding
>    <tc:out value="#{item.person.salutation.name}
> #{item.person.firstname} #{item.person.lastname}"/>
>
> Regards,
>  Volker
>
>
>
>
> 2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
>> Hi Volker,
>>
>> thanks for the quick response. I changed my converter to return the id
>> as you suggested (and I guess I had this state before but got over it
>> ...). This way it works for the tx:selectOneChoice.
>>
>> But if the object containing the person as a field is displayed in a
>> table now the person's id is displayed. I can avoid this by adding
>> special properties to the <tc:out /> tag. Or do you know a better
>> solution for this?
>>
>> Regards,
>>
>> Stefan.
>>
>> Volker Weber schrieb:
>> > Hi Stefan,
>> >
>> > change the converter to convert from and to id
>> > and don't use the converter for the label.
>> >
>> > e.g.:
>> >
>> >
>> >   List<SelectItem> items = new ArrayList<SelectItem>();
>> >   for (Person person : list) {
>> >     StringBuilder builder = new StringBuilder();
>> >     if (person.getSalutation() != null) {
>> >       builder.append(person.getSalutation().getName()).append(" ");
>> >     }
>> >     if (!StringUtils.isEmpty(person.getFirstname())) {
>> >       builder.append(person.getFirstname()).append(" ");
>> >     }
>> >      String label =  builder.append(person.getLastname())
>> >         .append("(").append(person.getId()).append(")").toString();
>> >     items.add(new SelectItem(person, label));
>> >   }
>> >
>> >
>> > and
>> >
>> > public Object getAsObject(FacesContext context, UIComponent component,
>> > String value) throws ConverterException {
>> >   if (StringUtils.isEmpty(value)) {
>> >     return null;
>> >   }
>> >   try {
>> >       int personId = Integer.parseInt(value);
>> >       return
>> > ProjectManagementHelper.getProjectManagement().getPerson(personId);
>> >     }
>> >   } catch (NumberFormatException e) {
>> >     LOG.error("", e);
>> >   }
>> >   return null;
>> > }
>> >
>> > public String getAsString(FacesContext context, UIComponent component,
>> > Object obj) throws ConverterException {
>> >   if (obj == null) {
>> >     LOG.info("###+++ received null value! +++###");
>> >     return null;
>> >   }
>> >   if (obj instanceof Person) {
>> >     LOG.info("###+++ received Person instance! +++###");
>> >     return ((Person) obj).getId();
>> >   }
>> >   throw new ConverterException("Expected " + Person.class.getName() +
>> > ", received " + obj.getClass().getName());
>> > }
>> >
>> >
>> > Regards,
>> >  Volker
>> >
>> > 2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
>> >> Hi,
>> >>
>> >> I'm trying to display some complex values within a tx:selectOneChoice
>> >> element. What I've managed so far is the following:
>> >>
>> >> 1. The tag:
>> >>
>> >>           <tx:selectOneChoice
>> >> value="#{editorController.currentEntry.member}"
>> >>                  label="#{mainBundle.member}" >
>> >>             <f:selectItems value="#{editorController.memberItems}" />
>> >>           </tx:selectOneChoice>
>> >>
>> >> 2. The item list (memberItem):
>> >>
>> >>     ...
>> >>     // list is declared as List<Person> list above
>> >>     ...
>> >>     List<SelectItem> items = new ArrayList<SelectItem>();
>> >>     for (Person person : list) {
>> >>       items.add(new SelectItem(person,
>> converter.getAsString(person)));
>> >>     }
>> >>     return items;
>> >>
>> >> 3. The converter registered for the Person class (an instance of
>> >> Converter with an additional convenience method getAsString(Person
>> p) -
>> >> this method is accessible from a caller through the second
>> interface):
>> >>
>> >> public class PersonConverter implements Converter,
>> >> AsStringConverter<Person> {
>> >>
>> >>   private static final Log LOG =
>> >> LogFactory.getLog(PersonConverter.class);
>> >>
>> >>   public Object getAsObject(FacesContext context, UIComponent
>> component,
>> >> String value) throws ConverterException {
>> >>     if (StringUtils.isEmpty(value)) {
>> >>       return null;
>> >>     }
>> >>     try {
>> >>       int posOpen = value.lastIndexOf("(");
>> >>       int posClose = value.lastIndexOf(")");
>> >>       if (posOpen >= 0 && posClose > posOpen) {
>> >>         String substring = value.substring(posOpen + 1, posClose);
>> >>         LOG.info("#+#+# Substring = \"" + substring + "\"");
>> >>         int personId = Integer.parseInt(substring);
>> >>         return
>> >> ProjectManagementHelper.getProjectManagement().getPerson(personId);
>> >>       }
>> >>     } catch (NumberFormatException e) {
>> >>       LOG.error("", e);
>> >>     }
>> >>     return null;
>> >>   }
>> >>
>> >>   public String getAsString(FacesContext context, UIComponent
>> component,
>> >> Object obj) throws ConverterException {
>> >>     if (obj == null) {
>> >>       LOG.info("###+++ received null value! +++###");
>> >>       return null;
>> >>     }
>> >>     if (obj instanceof Person) {
>> >>       LOG.info("###+++ received Person instance! +++###");
>> >>       return getAsString((Person) obj);
>> >>     }
>> >>     throw new ConverterException("Expected " +
>> Person.class.getName() +
>> >> ", received " + obj.getClass().getName());
>> >>   }
>> >>
>> >>   public String getAsString(Person person) {
>> >>     StringBuilder builder = new StringBuilder();
>> >>     if (person.getSalutation() != null) {
>> >>       builder.append(person.getSalutation().getName()).append(" ");
>> >>     }
>> >>     if (!StringUtils.isEmpty(person.getFirstname())) {
>> >>       builder.append(person.getFirstname()).append(" ");
>> >>     }
>> >>     return builder.append(person.getLastname()).append("
>> >> (").append(person.getId()).append(")").toString();
>> >>   }
>> >>
>> >> }
>> >>
>> >> This at least works, but it is kind of ugly UI as I had to code the
>> >> object's internal id into the String displayed in the list. So my own
>> >> entry could be "Mr. Stefan Hedtfeld (2)" - which is not the intended
>> >> way. I'd like to simply display "Mr. Stefan Hedtfeld".
>> >>
>> >> Is there a better way to handle this?
>> >>
>> >> Regards,
>> >>
>> >> Stefan.
>> >>
>> >
>>
>>
>


Re: [tobago] displaying complex values in tx:selectOneChoice

Posted by Volker Weber <v....@inexso.de>.
Hi,

i'm not sure if i understand this correct, if not please explain with
jsf source.

You have list of objects containing a person, and display this in a sheet?
e.g:
<tc:sheet ... var="item" >
  ...
  <tc:column ...>
    <tc:out value="#{item.person}"/>
  </tc:column>
  ...
</tc:sheet>

this will result in the id with your converter.

two possible solutions:
  add a special method to the person class: getAsLabel()
    and use <tc:out value="#{item.person.asLabel}"/>
  or add all properties to the valueBinding
    <tc:out value="#{item.person.salutation.name}
#{item.person.firstname} #{item.person.lastname}"/>

Regards,
  Volker




2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
> Hi Volker,
>
> thanks for the quick response. I changed my converter to return the id
> as you suggested (and I guess I had this state before but got over it
> ...). This way it works for the tx:selectOneChoice.
>
> But if the object containing the person as a field is displayed in a
> table now the person's id is displayed. I can avoid this by adding
> special properties to the <tc:out /> tag. Or do you know a better
> solution for this?
>
> Regards,
>
> Stefan.
>
> Volker Weber schrieb:
> > Hi Stefan,
> >
> > change the converter to convert from and to id
> > and don't use the converter for the label.
> >
> > e.g.:
> >
> >
> >   List<SelectItem> items = new ArrayList<SelectItem>();
> >   for (Person person : list) {
> >     StringBuilder builder = new StringBuilder();
> >     if (person.getSalutation() != null) {
> >       builder.append(person.getSalutation().getName()).append(" ");
> >     }
> >     if (!StringUtils.isEmpty(person.getFirstname())) {
> >       builder.append(person.getFirstname()).append(" ");
> >     }
> >      String label =  builder.append(person.getLastname())
> >         .append("(").append(person.getId()).append(")").toString();
> >     items.add(new SelectItem(person, label));
> >   }
> >
> >
> > and
> >
> > public Object getAsObject(FacesContext context, UIComponent component,
> > String value) throws ConverterException {
> >   if (StringUtils.isEmpty(value)) {
> >     return null;
> >   }
> >   try {
> >       int personId = Integer.parseInt(value);
> >       return
> > ProjectManagementHelper.getProjectManagement().getPerson(personId);
> >     }
> >   } catch (NumberFormatException e) {
> >     LOG.error("", e);
> >   }
> >   return null;
> > }
> >
> > public String getAsString(FacesContext context, UIComponent component,
> > Object obj) throws ConverterException {
> >   if (obj == null) {
> >     LOG.info("###+++ received null value! +++###");
> >     return null;
> >   }
> >   if (obj instanceof Person) {
> >     LOG.info("###+++ received Person instance! +++###");
> >     return ((Person) obj).getId();
> >   }
> >   throw new ConverterException("Expected " + Person.class.getName() +
> > ", received " + obj.getClass().getName());
> > }
> >
> >
> > Regards,
> >  Volker
> >
> > 2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
> >> Hi,
> >>
> >> I'm trying to display some complex values within a tx:selectOneChoice
> >> element. What I've managed so far is the following:
> >>
> >> 1. The tag:
> >>
> >>           <tx:selectOneChoice
> >> value="#{editorController.currentEntry.member}"
> >>                  label="#{mainBundle.member}" >
> >>             <f:selectItems value="#{editorController.memberItems}" />
> >>           </tx:selectOneChoice>
> >>
> >> 2. The item list (memberItem):
> >>
> >>     ...
> >>     // list is declared as List<Person> list above
> >>     ...
> >>     List<SelectItem> items = new ArrayList<SelectItem>();
> >>     for (Person person : list) {
> >>       items.add(new SelectItem(person, converter.getAsString(person)));
> >>     }
> >>     return items;
> >>
> >> 3. The converter registered for the Person class (an instance of
> >> Converter with an additional convenience method getAsString(Person p) -
> >> this method is accessible from a caller through the second interface):
> >>
> >> public class PersonConverter implements Converter,
> >> AsStringConverter<Person> {
> >>
> >>   private static final Log LOG =
> >> LogFactory.getLog(PersonConverter.class);
> >>
> >>   public Object getAsObject(FacesContext context, UIComponent component,
> >> String value) throws ConverterException {
> >>     if (StringUtils.isEmpty(value)) {
> >>       return null;
> >>     }
> >>     try {
> >>       int posOpen = value.lastIndexOf("(");
> >>       int posClose = value.lastIndexOf(")");
> >>       if (posOpen >= 0 && posClose > posOpen) {
> >>         String substring = value.substring(posOpen + 1, posClose);
> >>         LOG.info("#+#+# Substring = \"" + substring + "\"");
> >>         int personId = Integer.parseInt(substring);
> >>         return
> >> ProjectManagementHelper.getProjectManagement().getPerson(personId);
> >>       }
> >>     } catch (NumberFormatException e) {
> >>       LOG.error("", e);
> >>     }
> >>     return null;
> >>   }
> >>
> >>   public String getAsString(FacesContext context, UIComponent component,
> >> Object obj) throws ConverterException {
> >>     if (obj == null) {
> >>       LOG.info("###+++ received null value! +++###");
> >>       return null;
> >>     }
> >>     if (obj instanceof Person) {
> >>       LOG.info("###+++ received Person instance! +++###");
> >>       return getAsString((Person) obj);
> >>     }
> >>     throw new ConverterException("Expected " + Person.class.getName() +
> >> ", received " + obj.getClass().getName());
> >>   }
> >>
> >>   public String getAsString(Person person) {
> >>     StringBuilder builder = new StringBuilder();
> >>     if (person.getSalutation() != null) {
> >>       builder.append(person.getSalutation().getName()).append(" ");
> >>     }
> >>     if (!StringUtils.isEmpty(person.getFirstname())) {
> >>       builder.append(person.getFirstname()).append(" ");
> >>     }
> >>     return builder.append(person.getLastname()).append("
> >> (").append(person.getId()).append(")").toString();
> >>   }
> >>
> >> }
> >>
> >> This at least works, but it is kind of ugly UI as I had to code the
> >> object's internal id into the String displayed in the list. So my own
> >> entry could be "Mr. Stefan Hedtfeld (2)" - which is not the intended
> >> way. I'd like to simply display "Mr. Stefan Hedtfeld".
> >>
> >> Is there a better way to handle this?
> >>
> >> Regards,
> >>
> >> Stefan.
> >>
> >
>
>

Re: [tobago] displaying complex values in tx:selectOneChoice

Posted by Stefan Hedtfeld <st...@xsoftahead.com>.
Hi Volker,

thanks for the quick response. I changed my converter to return the id
as you suggested (and I guess I had this state before but got over it
...). This way it works for the tx:selectOneChoice.

But if the object containing the person as a field is displayed in a
table now the person's id is displayed. I can avoid this by adding
special properties to the <tc:out /> tag. Or do you know a better
solution for this?

Regards,

Stefan.

Volker Weber schrieb:
> Hi Stefan,
>
> change the converter to convert from and to id
> and don't use the converter for the label.
>
> e.g.:
>
>
>   List<SelectItem> items = new ArrayList<SelectItem>();
>   for (Person person : list) {
>     StringBuilder builder = new StringBuilder();
>     if (person.getSalutation() != null) {
>       builder.append(person.getSalutation().getName()).append(" ");
>     }
>     if (!StringUtils.isEmpty(person.getFirstname())) {
>       builder.append(person.getFirstname()).append(" ");
>     }
>      String label =  builder.append(person.getLastname())
>         .append("(").append(person.getId()).append(")").toString();
>     items.add(new SelectItem(person, label));
>   }
>
>
> and
>
> public Object getAsObject(FacesContext context, UIComponent component,
> String value) throws ConverterException {
>   if (StringUtils.isEmpty(value)) {
>     return null;
>   }
>   try {
>       int personId = Integer.parseInt(value);
>       return
> ProjectManagementHelper.getProjectManagement().getPerson(personId);
>     }
>   } catch (NumberFormatException e) {
>     LOG.error("", e);
>   }
>   return null;
> }
>
> public String getAsString(FacesContext context, UIComponent component,
> Object obj) throws ConverterException {
>   if (obj == null) {
>     LOG.info("###+++ received null value! +++###");
>     return null;
>   }
>   if (obj instanceof Person) {
>     LOG.info("###+++ received Person instance! +++###");
>     return ((Person) obj).getId();
>   }
>   throw new ConverterException("Expected " + Person.class.getName() +
> ", received " + obj.getClass().getName());
> }
>
>
> Regards,
>  Volker
>
> 2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
>> Hi,
>>
>> I'm trying to display some complex values within a tx:selectOneChoice
>> element. What I've managed so far is the following:
>>
>> 1. The tag:
>>
>>           <tx:selectOneChoice
>> value="#{editorController.currentEntry.member}"
>>                  label="#{mainBundle.member}" >
>>             <f:selectItems value="#{editorController.memberItems}" />
>>           </tx:selectOneChoice>
>>
>> 2. The item list (memberItem):
>>
>>     ...
>>     // list is declared as List<Person> list above
>>     ...
>>     List<SelectItem> items = new ArrayList<SelectItem>();
>>     for (Person person : list) {
>>       items.add(new SelectItem(person, converter.getAsString(person)));
>>     }
>>     return items;
>>
>> 3. The converter registered for the Person class (an instance of
>> Converter with an additional convenience method getAsString(Person p) -
>> this method is accessible from a caller through the second interface):
>>
>> public class PersonConverter implements Converter,
>> AsStringConverter<Person> {
>>
>>   private static final Log LOG =
>> LogFactory.getLog(PersonConverter.class);
>>
>>   public Object getAsObject(FacesContext context, UIComponent component,
>> String value) throws ConverterException {
>>     if (StringUtils.isEmpty(value)) {
>>       return null;
>>     }
>>     try {
>>       int posOpen = value.lastIndexOf("(");
>>       int posClose = value.lastIndexOf(")");
>>       if (posOpen >= 0 && posClose > posOpen) {
>>         String substring = value.substring(posOpen + 1, posClose);
>>         LOG.info("#+#+# Substring = \"" + substring + "\"");
>>         int personId = Integer.parseInt(substring);
>>         return
>> ProjectManagementHelper.getProjectManagement().getPerson(personId);
>>       }
>>     } catch (NumberFormatException e) {
>>       LOG.error("", e);
>>     }
>>     return null;
>>   }
>>
>>   public String getAsString(FacesContext context, UIComponent component,
>> Object obj) throws ConverterException {
>>     if (obj == null) {
>>       LOG.info("###+++ received null value! +++###");
>>       return null;
>>     }
>>     if (obj instanceof Person) {
>>       LOG.info("###+++ received Person instance! +++###");
>>       return getAsString((Person) obj);
>>     }
>>     throw new ConverterException("Expected " + Person.class.getName() +
>> ", received " + obj.getClass().getName());
>>   }
>>
>>   public String getAsString(Person person) {
>>     StringBuilder builder = new StringBuilder();
>>     if (person.getSalutation() != null) {
>>       builder.append(person.getSalutation().getName()).append(" ");
>>     }
>>     if (!StringUtils.isEmpty(person.getFirstname())) {
>>       builder.append(person.getFirstname()).append(" ");
>>     }
>>     return builder.append(person.getLastname()).append("
>> (").append(person.getId()).append(")").toString();
>>   }
>>
>> }
>>
>> This at least works, but it is kind of ugly UI as I had to code the
>> object's internal id into the String displayed in the list. So my own
>> entry could be "Mr. Stefan Hedtfeld (2)" - which is not the intended
>> way. I'd like to simply display "Mr. Stefan Hedtfeld".
>>
>> Is there a better way to handle this?
>>
>> Regards,
>>
>> Stefan.
>>
>


Re: [tobago] displaying complex values in tx:selectOneChoice

Posted by Volker Weber <v....@inexso.de>.
Hi Stefan,

change the converter to convert from and to id
and don't use the converter for the label.

e.g.:


   List<SelectItem> items = new ArrayList<SelectItem>();
   for (Person person : list) {
     StringBuilder builder = new StringBuilder();
     if (person.getSalutation() != null) {
       builder.append(person.getSalutation().getName()).append(" ");
     }
     if (!StringUtils.isEmpty(person.getFirstname())) {
       builder.append(person.getFirstname()).append(" ");
     }
      String label =  builder.append(person.getLastname())
         .append("(").append(person.getId()).append(")").toString();
     items.add(new SelectItem(person, label));
   }


and

public Object getAsObject(FacesContext context, UIComponent component,
String value) throws ConverterException {
   if (StringUtils.isEmpty(value)) {
     return null;
   }
   try {
       int personId = Integer.parseInt(value);
       return
ProjectManagementHelper.getProjectManagement().getPerson(personId);
     }
   } catch (NumberFormatException e) {
     LOG.error("", e);
   }
   return null;
 }

 public String getAsString(FacesContext context, UIComponent component,
Object obj) throws ConverterException {
   if (obj == null) {
     LOG.info("###+++ received null value! +++###");
     return null;
   }
   if (obj instanceof Person) {
     LOG.info("###+++ received Person instance! +++###");
     return ((Person) obj).getId();
   }
   throw new ConverterException("Expected " + Person.class.getName() +
", received " + obj.getClass().getName());
 }


Regards,
  Volker

2007/1/29, Stefan Hedtfeld <st...@xsoftahead.com>:
> Hi,
>
> I'm trying to display some complex values within a tx:selectOneChoice
> element. What I've managed so far is the following:
>
> 1. The tag:
>
>           <tx:selectOneChoice
> value="#{editorController.currentEntry.member}"
>                  label="#{mainBundle.member}" >
>             <f:selectItems value="#{editorController.memberItems}" />
>           </tx:selectOneChoice>
>
> 2. The item list (memberItem):
>
>     ...
>     // list is declared as List<Person> list above
>     ...
>     List<SelectItem> items = new ArrayList<SelectItem>();
>     for (Person person : list) {
>       items.add(new SelectItem(person, converter.getAsString(person)));
>     }
>     return items;
>
> 3. The converter registered for the Person class (an instance of
> Converter with an additional convenience method getAsString(Person p) -
> this method is accessible from a caller through the second interface):
>
> public class PersonConverter implements Converter,
> AsStringConverter<Person> {
>
>   private static final Log LOG = LogFactory.getLog(PersonConverter.class);
>
>   public Object getAsObject(FacesContext context, UIComponent component,
> String value) throws ConverterException {
>     if (StringUtils.isEmpty(value)) {
>       return null;
>     }
>     try {
>       int posOpen = value.lastIndexOf("(");
>       int posClose = value.lastIndexOf(")");
>       if (posOpen >= 0 && posClose > posOpen) {
>         String substring = value.substring(posOpen + 1, posClose);
>         LOG.info("#+#+# Substring = \"" + substring + "\"");
>         int personId = Integer.parseInt(substring);
>         return
> ProjectManagementHelper.getProjectManagement().getPerson(personId);
>       }
>     } catch (NumberFormatException e) {
>       LOG.error("", e);
>     }
>     return null;
>   }
>
>   public String getAsString(FacesContext context, UIComponent component,
> Object obj) throws ConverterException {
>     if (obj == null) {
>       LOG.info("###+++ received null value! +++###");
>       return null;
>     }
>     if (obj instanceof Person) {
>       LOG.info("###+++ received Person instance! +++###");
>       return getAsString((Person) obj);
>     }
>     throw new ConverterException("Expected " + Person.class.getName() +
> ", received " + obj.getClass().getName());
>   }
>
>   public String getAsString(Person person) {
>     StringBuilder builder = new StringBuilder();
>     if (person.getSalutation() != null) {
>       builder.append(person.getSalutation().getName()).append(" ");
>     }
>     if (!StringUtils.isEmpty(person.getFirstname())) {
>       builder.append(person.getFirstname()).append(" ");
>     }
>     return builder.append(person.getLastname()).append("
> (").append(person.getId()).append(")").toString();
>   }
>
> }
>
> This at least works, but it is kind of ugly UI as I had to code the
> object's internal id into the String displayed in the list. So my own
> entry could be "Mr. Stefan Hedtfeld (2)" - which is not the intended
> way. I'd like to simply display "Mr. Stefan Hedtfeld".
>
> Is there a better way to handle this?
>
> Regards,
>
> Stefan.
>