【问题标题】:p:remoteCommand only update="@all" PF5p:remoteCommand only update="@all" PF5
【发布时间】:2015-02-24 16:12:16
【问题描述】:

在下面的代码<p:remoteCommand> 上,当我使用@all 时只更新整个视图,但我尝试更新@this@formwizardEventContainer 没有成功。即使@all 工作如我所愿,我更愿意只更新特定容器wizardEventContainer

在 PrimeFaces 网站中,该示例使用 id 属性工作,因此我不知道为什么我也无法获得它。

我使用 PF5、JSF 2.2 和 SWF 2.4。我将 JSF 分隔符更改为 - 而不是 :

<h:form id="formEditor" styleClass="eventEditorForm" prependId="true">
            <p:editor id="editorEvent" height="150" width="900" maxlength="500" onchange="writeTextonPanel()" widgetVar="editorWidget"  />

            <h:panelGroup layout="block" id="eventEditorButtons" styleClass="eventEditorButtons">
                <h:commandButton value="#{msg['saveLayer.btn']}" actionListener="#{eventProvider.saveTextLayer()}" alt="#{msg['saveLayer.btn.alt']}" title="#{msg['saveLayer.btn.title']}" onclick="showEditor('save')">
                    <f:ajax execute="@form" render="-formBotones-wizardEventContainer" />
                </h:commandButton>
                <h:commandButton value="#{msg['omitLayer.btn']}" alt="#{msg['omitLayer.btn.alt']}" title="#{msg['omitLayer.btn.title']}" onclick="showEditor('delete')">
                    <f:ajax execute="@form" render="-formBotones-wizardEventContainer" />
                </h:commandButton>
            </h:panelGroup>

            <h:inputHidden id="tempCSS" value="#{eventProvider.tempCSS}" />
            <h:inputHidden id="tempHTML" value="#{eventProvider.tempHTML}" />
</h:form>

<h:form id="formBotones" prependId="true">

    <p:remoteCommand name="omitTextLayer" process="@this" update="formBotones-wizardEventContainer" actionListener="#{eventProvider.omitTextLayer()}" />
    <p:remoteCommand name="modifyTextLayer" actionListener="#{eventProvider.modifyTextLayer()}" />
    <h:inputHidden id="tempCSSforModify" value="#{eventProvider.tempCSSModified}" />

    <h:panelGroup layout="block" id="wizardEventContainer" styleClass="wizardEventContainer">
        <h:inputHidden id="tempTextIdLayer" value="#{eventProvider.tempTextIdLayer}" />
    </h:panelGroup>
</h:form>

用JAVA方法链接的JS代码

function showEditor(mode){
if(mode=='save')
    saveLayer();

if(mode=='delete')
    deleteLayer();

if($('#eventEditorContainer').css('visibility')=="hidden"){
    $('#eventEditorContainer').css('visibility','visible');
    $('#formControl-textLayerBtn').prop("disabled",true);
}
else{
    $('#eventEditorContainer').css('visibility','hidden');
    $('#formControl-textLayerBtn').prop("disabled",false);
}

}

function deleteLayer(layer){


if(layer==null){
    var idLayer='formBotones-' + $('#formBotones-tempTextIdLayer').val();

    $('#' + idLayer).remove();

    $('#formEditor-tempCSS').val('');
    $('#formEditor-tempHTML').val('');

}
else{
    var idLayer=layer.parent().attr('id');


    layer.parent().remove();


    $('#formBotones-tempTextIdLayer').val(idLayer.substring(idLayer.indexOf("-")+1));
    $('#formEditor-tempCSS').val('');
    $('#formEditor-tempHTML').val('');


}

omitTextLayer(); // p:remoteCommand function

}

P.D:我已编辑添加完整的代码示例和 js 代码,它们链接到 p:remoteCommand 上的 java 方法 谢谢!

【问题讨论】:

  • &lt;p:remoteCommand&gt;process 属性设置为@all(默认)。因此,它处理整个视图。你可以试试process="@this" 吗? (虽然我认为,它不会影响你的具体问题)。
  • @Tiny 我试过了 process="@this" update="@this" 但没有用。是否可能与spring webflow有任何不兼容?因为我在几个 PF5 组件的更新属性方面遇到了一些问题,并且我将代码更改为 f:ajax 行为而不是 PF5 更新属性。
  • update 基本上需要设置为一些(容器)组件(取决于您的需要),例如update="wizardEventContainer" 而不仅仅是update="@this" 本身就是&lt;p:remoteCommand&gt;。不应该吗?我还没有使用过 Spring WebFlow。因此,我完全不知道。通过观察网络监视器/浏览器控制台(看看是否有一些 JavaScript 错误),我希望你应该能够找到罪魁祸首。最后,你如何将那些&lt;p:remoteCommand&gt;s 与一些组件关联起来?在当前代码 sn-p 中,没有看到任何关联/附件。待续
  • 你基本上应该做这样的事情。以&lt;p:commandButton&gt; 为例 - &lt;p:commandButton type="button" onclick="func()" value="Click".../&gt; 然后您需要将此按钮附加到&lt;p:remoteCommand name="func" update="wizardEventContainer".../&gt;。此远程命令附加到onclick JavaScript 事件上的按钮(作为示例)。如果需要,您可以使用 action/actionListener 来调用 bean 方法。我想,你应该已经在做所有这些了。你? Example.
  • @Tiny 是的!代码是按你说的写的。我为 p:remoteCommand 添加了完整的代码和 JS。 Java函数被抛出,我可以正确调试它。现在我已经看到,wizardEventContainer 也是从第一个表单(formEditor)上的 commandButton 更新的。所以,我真的尝试更新该容器两次但没有成功。作为绝望的尝试,我删除了 f:ajaxBehavior 并在 p:remoteCommand 上设置了 process="@this" update="wizardEventContainer" 但都不起作用。

标签: spring jsf jsf-2 primefaces


【解决方案1】:

如果p:remoteCommadp:commandButton 而不是h:commandButton 抛出,则更新使用ID 正常工作。

所以,代码必须改为

<p:commandButton value="#{msg['omitLayer.btn']}" alt="#{msg['omitLayer.btn.alt']}" title="#{msg['omitLayer.btn.title']}" onclick="showEditor('delete')" />

【讨论】:

  • 呃!第一次看到 :) (至少我从未尝试过 &lt;p:remoteCommand&gt;&lt;h:commandButton&gt;)这不容易猜到。感谢您在这里回复。
猜你喜欢
  • 1970-01-01
  • 2022-06-10
  • 2018-06-21
  • 2015-11-17
  • 1970-01-01
  • 2015-05-27
  • 1970-01-01
  • 1970-01-01
  • 2022-11-24
相关资源
最近更新 更多