下面的代码<p:remoteCommand>
当我使用 @all 时,只需更新整个 View ,但我尝试过更新 @this
, @form
或wizardEventContainer
没有成功。即使@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>
JS代码与JAVA方法链接
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:我编辑添加了链接到 p:remoteCommand 上的 java 方法的完整代码示例和 js 代码 谢谢!
最佳答案
如果从 p:commandButton
而不是 h:commandButton
抛出 p:remoteCommad
,则更新可以使用 ID 正常工作。
因此,代码必须更改为
<p:commandButton value="#{msg['omitLayer.btn']}" alt="#{msg['omitLayer.btn.alt']}" title="#{msg['omitLayer.btn.title']}" onclick="showEditor('delete')" />
关于spring - p :remoteCommand only update ="@all" PF5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27672535/