jsf:如何在一个枚举中使用多个SelectOneRadio

时间:2015-12-17 15:34:31

标签: jsf enums selectoneradio

首先抱歉我的英语,我会尽力让自己理解。 我正在开发一个wep应用来管理用户个人资料。但现在我被困在创建用户组。我有权利的枚举类

public enum UsergroupRights {

  Ja("Ja"),
  Nein("Nein");

  private String rights;

  UsergroupRights(String rights) {
    this.rights = checkRights();
  }

  public String getRights() {
    return rights;
  }
}

名称的类

public class UsergroupName extends AbstractValueObject<String> {

  public UsergroupName() {
  }

  public UsergroupName(String value) {
    this.value = value;
  }

  @Override
  public String toString() {
    return value;
  }
}

存储在对象“usergroups”

public class Usergroup {

  public Usergroup() {
  }

  private UsergroupName name;

  private UsergroupRights rights;

  public Usergroup(UsergroupName name, UsergroupRights rights) {
    this.name = name;
    this.rights = rights;
  }

  public UsergroupName getName() {
    return name;
  }

  public void setName(UsergroupName name) {
    this.name = name;
  }

  public UsergroupRights getRights() {
    return rights;
  }

  public void setRights(UsergroupRights rights) {
    this.rights = rights;
  }

}

和一些JSF代码

<h:form>
    <h:panelGrid columns="3">
        <h:outputLabel value="Name der Benutzergruppe: " for="usergroupName"/>
        <h:inputText value="#{userData.usergroupName}" id="usergroupName" required="true"/>
        <h:message for="usergroupName" style="color: red"/>

        <h:outputLabel value="Darf Benutzer einsehen: " for="watchUser"/>
        <h:selectOneRadio value="#{userData.usergroupRights.watchUser}" required="true" id="watchUser">
                <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Benutzer hinzufügen: " for="addUser"/>
        <h:selectOneRadio value="#{userData.usergroupRights.addUser}" required="true" id="addUser">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Benutzer bearbeiten: " for="editUser"/>
        <h:selectOneRadio value="#{userData.usergroupRights.editUser}" required="true" id="editUser">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Benutzer löschen: " for="deleteUser"/>
        <h:selectOneRadio value="#{userData.usergroupRights.deleteUser}" required="true" id="deleteUser">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Gruppe einsehen: " for="watchUsergroup"/>
        <h:selectOneRadio value="#{userData.usergroupRights.watchUsergroup}" required="true" id="watchUsergroup">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Gruppe hinzufügen: " for="addUsergroupR"/>
        <h:selectOneRadio value="#{userData.usergroupRights.addUsergroup}" required="true" id="addUsergroupR">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Gruppe bearbeiten: " for="editUsergroups"/>
        <h:selectOneRadio value="#{userData.usergroupRights.editUsergroup}" required="true" id="editUsergroups">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>

        <h:outputLabel value="Darf Gruppe löschen: " for="deleteUsergroups"/>
        <h:selectOneRadio value="#{userData.usergroupRights.deleteUsergroup}" required="true" id="deleteUsergroups">
            <f:selectItems value="#{userData.usergroupRightsValues}"/>
        </h:selectOneRadio>
        <h:message for="watchUser"/>


        <h:commandButton value="Speichern" id="save" action="#{userData.addUsergroup}"/>
    </h:panelGrid>
</h:form>

现在我想创建一个jsf页面,我可以在其中添加用户组名称并选择用户组具有的权限。它看起来像

image

我知道这部分“#{userData.usergroupRights.deleteUsergroup}”无效,但我没有更多想法。

我试图意识到它几个小时,但现在我没有更多的想法。我该怎么做才能将我的用户组名称与我的用户组权限相关联?

我希望这是可以理解的。

问候

0 个答案:

没有答案