开发者

Make h:dataTable cell editable by using h:selectbooleanCheckbox linked to HashMap in the bean

I went through this question from SO How to use <h:selectBooleanCheckbox> in <h:dataTable> to select multiple rows?

Using the single checkbox as shown in above question i want to find out whether i can make h:datatable cell editable so that user can edit all the rows and columns at once and submit

Here is part of bean class

public class bean {
private List<Group> GroupList;

private Map<Long, Boolean> checked = new HashMap<Long, Boolean>();

public void setChecked(Map<Long, Boolean> checked) {
    this.checked = checked;
}

public Map<Long, Boolean> getChecked() {
    return checked;
}


}

And here is my JSF page

<h:dataTable id="editTable" styleClass = "listtable" value="#{bean.GroupList}"  var="group" border="1" first="0" rows="8" width="75%" 开发者_JAVA技巧frame="hsides" rules="all" cellpadding="5" headerClass="tableheading" rowClasses="firstrow, secondrow">

    <f:facet name="header">
    <h:outputText value="Groups"></h:outputText>
    </f:facet>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupId"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Id}" rendered=""></h:outputText>
        <h:inputText value="#{group.Id}" rendered=""/>
    </h:column>

    <h:column>
        <f:facet name="header">
        <h:outputText value="GroupName"></h:outputText>
        </f:facet>
        <h:outputText value="#{group.Name}" rendered=""></h:outputText>
        <h:inputText value="#{group.Name}" rendered=""/>
    </h:column>


    <h:column>
        <f:facet name="header">
        <h:outputText value="Check to Enable/Disable"></h:outputText>
        </f:facet>
        <h:selectBooleanCheckbox value="#{bean.checked[group.Id]}" />
    </h:column>

    </h:dataTable>

What should be kept in rendered attribute so that when it is checked h:inputtext is rendered and when not checked h:outputtext is rendered?


Just bind to the same property. It returns a Boolean anyway. You can use ! or not to negate it.

<h:outputText value="#{group.Id}" rendered="#{!bean.checked[group.Id]}" />
<h:inputText value="#{group.Id}" rendered="#{bean.checked[group.Id]}" />
...
<h:outputText value="#{group.Name}" rendered="#{!bean.checked[group.Id]}" />
<h:inputText value="#{group.Name}" rendered="#{bean.checked[group.Id]}" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜