0

我试图从 selectOneListbox 设置枚举性别,但由于某种原因它失败了,所以我尝试使用纯字符串,但它仍然不起作用。例如,InputText 工作得很好。这是代码xhtml:

    <h:form>
        <h:panelGrid columns="2">

            <h:outputLabel value="Name"/>         
            <h:inputText value="#{userProfileBean.name}"/>

            <h:outputLabel value="Name from list"/>
            <h:selectOneListbox value="#{userProfileBean.name}">
                    <f:selectItem itemValue="Bob" itemLabel="bobLabel"/>
                    <f:selectItem itemValue="Cindy" itemLabel="cindyLabel"/>
            </h:selectOneListbox>

            <h:commandButton value="Save" action="#{userProfileBean.saveChanges()}"/>

        </h:panelGrid>
    </h:form>

和后端bean:

@ManagedBean
@Named
@ViewScoped
public class UserProfileBean implements Serializable {

@Inject
private UserDatabase userDB;

private User user;
private String name;

...getters/setters...

public void saveChanges() {
    user.setName(name);
}

有谁知道出了什么问题?

4

0 回答 0