【问题标题】:How to update component on clientside in primefaces?如何在primefaces中更新客户端的组件?
【发布时间】:2013-05-02 21:03:06
【问题描述】:

我想创建带有对话框表单功能的添加子按钮。

页面上有树形和模态对话框形式。树的每个节点上都有创建子按钮。如果单击创建子按钮,将显示模态表单,其中 parentId 将设置为单击按钮的节点的 id

树:

 <h:form id="TestGroupListForm">    
    <p:tree value="#{testTreeController.root}" var="node" dynamic="true" cache="false"  
                    selectionMode="single"  selection="#{treeBean.selectedNode}" id="tree">  

                <p:treeNode>  
                    <h:outputText value="#{node.getName()}" />  <p:commandButton id="createButton#{node.getIdTestGroup()}" icon="ui-icon-plus"   value="#{bundle.Create}"  update="tree" oncomplete="TestGroupCreateDialog.show()"/>
                </p:treeNode>  
            </p:tree>                    
 </h:form>

对话框:

        <h:form id="TestGroupCreateForm">

            <h:panelGroup id="display">
                <p:panelGrid columns="2" >


                    <p:outputLabel value="#{bundle.CreateTestGroupLabel_name}" for="name" />
                    <p:inputText id="name" value="#{testGroupController.selected.name}" title="#{bundle.CreateTestGroupTitle_name}" />
                    <h:inputHidden  id="parentId" value="#{testGroupController.selected.parentId}" />

                </p:panelGrid>
                <p:commandButton actionListener="#{testGroupController.saveNew}" value="#{bundle.Save}" update="display,:TestGroupListForm:tree,:growl" oncomplete="handleSubmit(xhr,status,args,TestGroupCreateDialog);"/>
                <p:commandButton value="#{bundle.Cancel}" onclick="TestGroupCreateDialog.hide()"/>
            </h:panelGroup>

        </h:form>

    </p:dialog> 

我想要那个点击

<p:commandButton id="createButton#{node.getIdTestGroup()}" icon="ui-icon-plus"   value="#{bundle.Create}"  update="tree" oncomplete="TestGroupCreateDialog.show()"/>

将设置值:

<h:inputHidden  id="parentId" value="#{testGroupController.selected.parentId}" />

更新

我必须使用动作监听器 testGroupController.nodeListener 来设置新项目的 parentId。

    <p:commandButton process="@this" id="createButton" actionListener="#{testGroupController.nodeListener}" icon="ui-icon-plus"   value="#{bundle.CreateGroup}"  update=":TestGroupCreateForm" oncomplete="TestGroupCreateDialog.show()">
                            <f:attribute name="rawParentId" value="#{node.getIdTestGroup()}" />
  </p:commandButton>

【问题讨论】:

    标签: jsf jsf-2 primefaces


    【解决方案1】:

    您可以像这样将 parentId 添加到现有的update= 属性中:

    update="tree parentId"
    

    这将呈现parentId 并将其值设置为testGroupController.selected.parentId

    编辑

    您也可以使用以下方法处理从 UI 到过去的任何值:

    process="myInputId"
    

    示例

    <h:form>
        <h:inputText id="input" 
                     value="#{bean.value}" />
        <h:outputText id="output" 
                      value="#{bean.value}" />
        <p:commandButton process="input"
                         update="output"
                         value="Submit" />
    

    点击按钮后,id="input" 的值将设置在bean.value 中(按process="input" 排序)。接下来,您的id="output" 将使用bean.value 呈现(或更新)(由update="output" 排序)。

    【讨论】:

    • 我明白,但首先我必须设置 testGroupController.selected.parentId 值。我是通过actionListener来做的,对吗?
    • 我通过编辑和示例扩展了我的答案。希望这会为您解决问题。如果您仍然遇到问题,请随时添加其他评论。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-20
    • 1970-01-01
    • 1970-01-01
    • 2015-06-26
    • 1970-01-01
    • 2020-09-29
    • 1970-01-01
    相关资源
    最近更新 更多