P:dataTable排序在ui:decorate中不起作用

时间:2017-05-18 07:59:55

标签: jsf primefaces

p:datatable在独立工作正常,但不适用于这种情况: (我正在使用Primefaces 6.1mojarra 2.2.9

index.xhtml代码:

<h:body>
    <ui:decorate template="/main.xhtml">
        <ui:define name="wrapper">
            <c:if test="#{not empty param['action']}">
               <ui:include src="/templates/param['action'].xhtml" />
            </c:if>
        </ui:define>
    </ui:decorate>
</h:body>

param['action']的值为wrapper.xhtml代码:

<body>
    <ui:composition>
            <h:form>
                <p:dataTable var="menu" value="#{customerBean.listMenu}"
                    rowKey="#{menu.menuId}" selectionMode="single">
                    <f:facet name="header">
                         TEST
                    </f:facet>
                    <p:column headerText="Id" sortBy="#{menu.menuId}">
                        <h:outputText value="#{menu.menuId}" />
                    </p:column>
                    <p:column headerText="Action" sortBy="#{menu.name}">
                        <h:outputText value="#{menu.name}" />
                    </p:column>
                </p:dataTable>
            </h:form>
    </ui:composition>
</body>

java代码:

@ManagedBean(name="customerBean")
@RequestScoped
public class CustomerBean {
    @ManagedProperty("#{listMenu}")
    private List<Test> listMenu;

    @PostConstruct
    public void init(){
        listMenu = new ArrayList<Test>();
        listMenu.add(new Test("123","Test","A1"));
        listMenu.add(new Test("124","Test2","A12"));
        listMenu.add(new Test("125","Test3","A13"));
    }

    public List<Test> getListMenu() {
        if(listMenu == null){
            init();
        }
        return listMenu;
    }

    public void setListMenu(List<Test> listMenu) {
        this.listMenu = listMenu;
    } 
}

当我删除<c:if test="#{not empty param['action']}">和硬编码/templates/wrapper.xhtml时,它可以正常工作。

有没有遗漏的步骤?

任何建议都将不胜感激,谢谢您的阅读。

1 个答案:

答案 0 :(得分:0)

我不知道为什么,但当我将<c:if test="#{not empty param['action']}">替换为p:panel时,它运行正常!