【问题标题】:PrimeFaces commandButton to set edit mode and refresh the formPrimeFaces commandButton 设置编辑模式和刷新表单
【发布时间】:2014-06-15 15:41:19
【问题描述】:

我正在尝试设置一个按钮来设置编辑模式并刷新表单,但是单击该按钮,什么也没有发生。

这是我的代码:

<h:form>
    <h:panelGrid columns="2" cellpadding="5">
        <p:commandButton type="submit" value="Edit Your Records" icon="ui-icon-edit"
                         update="@form" rendered="#{!bean.editMode}">
            <f:setPropertyActionListener value="true" target="#{bean.editMode}"/>
        </p:commandButton>
        <p:commandButton type="submit" value="Exit Edit Mode" icon="ui-icon-back" 
                         update="@form" rendered="#{bean.editMode}">
            <f:setPropertyActionListener value="false" target="#{bean.editMode}"/>
        </p:commandButton>
    </h:panelGrid>

    <p:dataTable id="table" value="#{bean.table}" var="apartment">
        ...
    </p:dataTable>
</h:form>

谢谢!

【问题讨论】:

  • 我认为受影响的value属性为target之一,应该用EL表示:value="#{true}"

标签: jsf primefaces


【解决方案1】:

我建议使用

<h:form>
    <p:commandButton value="Edit Your Records" update="@form" rendered="#{!bean.editMode}" action="#{bean.toggleEditMode()}" />
    <p:commandButton value="Exit Edit Mode" update="@form" rendered="#{bean.editMode}" action="#{bean.toggleEditMode()}" />
    <h:outputText value="#{bean.editMode}" />

public void toggleEditMode() {
    this.editMode = !this.editMode;
}

【讨论】:

    【解决方案2】:

    好的,'action'属性中调用的函数需要返回一个字符串。

    以下工作:

    public String toggleEditMode() {
        this.editMode = !this.editMode;
        return "#";
    }
    

    谢谢!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-02
      • 1970-01-01
      • 2016-01-16
      • 2013-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多