0

I want to show a Default(selected) Value in a selectOneMenu. In the selectOneMenu i show Person Object from a list. But i want to add a String value like "Please choose a value". And i want to show this String as Default, so that the user have to choose some of the existing Person Object in the Select One Menu. My result is, that the String value "Please choose a value" exists, but it is not as the Default (selected Value).

 <p:selectOneMenu id="emailaddress" value="#{personDataActions.actualPerson}">
    <f:converter converterId="personConverter" />
    <f:selectItem itemLabel="Please choose a value" itemValue=""  noSelectionOption="true" />

    <f:selectItems value="#{personDataActions.allPersons}"
    var="person" itemLabel="#{person.emailaddress}" converter="personConverter"/>

    </p:selectOneMenu>

My Converter is this:

@FacesConverter(value = "personConverter")
public class PersonConverter implements Converter {

    @Inject
    private PersonDataActions personDataActions;

    @Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        return personDataActions.getPersonByEmailaddress(arg2);
    }

    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        Person person = (Person) arg2;
        if (person != null) {
            return person.getEmailaddress();
        }
        return null;
    }

}

I have followed the example in the other post. but it not works. I see the item, but it is not a Default value. So my unterstanding is, that the value in the select one menu value="#{personDataActions.actualPerson}" is responsible for Setting the Default value. But the value in the select One Menu is a Person Object, and i want to set a String object. How i can handle this ?

java java
  • 405
  • 1
  • 11
  • 25
  • I have followed the example in the other post. but it not works. I see the item, but it is not a Default value. So my unterstanding is, that the value in the select one menu value="#{personDataActions.actualPerson}" is responsible for Setting the Default value. But the value in the select One Menu is a Person Object, and i want to set a String object. How i can handle this ? – java java Oct 29 '15 at 14:06
  • 2
    Just set to null as answered in dupe? – BalusC Oct 29 '15 at 14:58

0 Answers0