在jsf中如何将单选按钮存储到bean中

时间:2014-11-14 08:52:37

标签: java jsf-2

请为此代码编写bean:

<h:dataTable rows="10" value="#{LoginFormBean.keyAsList}"
        rendered="true" var="deviceid" id="producten">
        <h:column>
            <h:outputText value="#{deviceid}" />
        </h:column>
        <h:column>
            <h:selectOneRadio value="#{LoginFormBean.deviceMap[deviceid]}">
                <c:if test="#{LoginFormBean.deviceMap[deviceid] eq ON}">
                    <f:selectItem itemValue="ON" itemLabel="ON" />
                </c:if>
                <c:otherwise>
                    <f:selectItem itemValue="OFF" itemLabel="OFF" />
                </c:otherwise>
            </h:selectOneRadio>
        </h:column>
    </h:dataTable>

    <h:commandButton value="submit"
        action="#{LoginFormBean.updateConfigurations}" />

这里devicemap包含deviceid作为键,status是值 在提交按钮后,值必须存储..我的bean会看起来像请帮帮我..

2 个答案:

答案 0 :(得分:0)

我认为你需要保存在pojo课程中。

答案 1 :(得分:0)

// imports

@ManagedBean   // or @Named
@SessionScoped // the scope you want
public class LoginFormBean implements Serializable{
    private List<Object> keyAsList;
    private HashMap<String, String> deviceMap;

    public LoginFormBean() {
        this.keyAsList = new ArrayList<Object>();
        this.deviceMap = new HashMap<String, String>();
    }

    //getters - setters

    public void updateConfigurations() {
        // do something
    }
}

像这样的东西。你应该阅读How to write a managedBean