【问题标题】:rich:popupPanel submits value on .hide() , which i dont wantrich:popupPanel 在 .hide() 上提交值,这是我不想要的
【发布时间】:2014-02-05 15:54:37
【问题描述】:

我无法取消在 Richfaces 4 中使用 CKeditor 完成的更改。

简而言之:

<form>
  ...
  <rich:popupPanel>
     <rich:editor id="#{popupID}" value="#{managedBean.value}" />
     <a4j:commandButton value="Annuleer" onclick="#{rich:component(popupID)}.hide();" />
     <a4j:commandButton value="Ok" onclick="saveEditorData();" />
  </rich:popupPanel>
  ...
</form>

当我按下 [Cancel] ("Annuleer") 按钮时,它会关闭弹出面板并将值“提交”到 bean。当按下 [Cancel] 时,我不希望它提交值。我觉得我错过了一些非常简单但对完成这项工作至关重要的东西。

如何使 [取消] 按钮按预期工作?

完整代码:

<rich:popupPanel
 id="#{popupID}"
 modal="true"
 autosized="true"
 resizeable="false"
 styleClass="popup-panel"
 style="z-index:202;"
 left="300"
 domElementAttachment="parent">
 <f:facet name="header">
    <h:outputText value="Text Editor " />
 </f:facet>
 <f:facet name="controls">
    <a4j:commandButton
    value="X"
    type="reset"
    id="popupAfsluiten"
    render="#{panelID}"
    styleClass="btn-afsl"
    onclick="showLoadingOverlay();#{rich:component(popupID)}.hide();"
    oncomplete="cleanOverlay();setFocus('#{rich:clientId(inputID)}');return false;"/>
 </f:facet>
 <rich:panel id="#{cc.attrs.id}TextPanel">
     <rich:editor id="textEditor" lang="nl" value="#{cc.attrs.managedBean.formField(cc.attrs.id).value}" toolbar="CustomToolbar">
        <f:facet name="config">
            toolbar_CustomToolbar:
                [
                    { name: 'document', items: [ 'Save', 'NewPage', 'Preview', 'Print'] },
                    { name: 'clipboard', items : [ 'Cut','Copy','PasteText','-','Undo','Redo' ] },
                    { name: 'editing', items : [ 'Find','Replace','-','SelectAll','-','Scayt' ] },
                    { name: 'tools', items : [ 'Maximize' ] }
                ],
            language: 'nl',
            defaultLanguage : 'nl',
            scayt_sLang : 'nl_NL',
            startupFocus: true,
            pasteFromWordPromptCleanup : true,
            pasteFromWordRemoveFontStyles : true,
            forcePasteAsPlainText : true,
            ignoreEmptyParagraph : true,
            removeFormatAttributes : true,
            removePlugins : 'elementspath',
            tabSpaces : 4,
            autoParagraph : false,
            autoUpdateElement : false,
            enterMode: Number(2)
        </f:facet>
    </rich:editor>
    <a4j:commandButton
    value="Annuleer"
    type="reset"
    id="editorCancel"
    render="#{panelID}"
    styleClass="btn-ja"
    onclick="showLoadingOverlay();#{rich:component(popupID)}.hide();"
    oncomplete="cleanOverlay();setFocus('#{rich:clientId(inputID)}');return false;"/>

    <a4j:commandButton
        value="Ok"
        type="submit"
        styleClass="btn-ja"
        id="#{inputID}Save"
        render="#{inputID}"
        onclick="saveEditorData();"
        oncomplete="setTime();" />
        <h:outputText escape="false" value="Opgeslagen om: " />
        <h:outputText escape="false" value="#{editorBean.value}" id="saveTimeOutput"/>
     </rich:panel>
  </rich:popupPanel>

【问题讨论】:

    标签: ckeditor richfaces submit


    【解决方案1】:

    表单正在由 a4j:commandButton 提交。

    如果您使用的是richfaces 3.3.3,那么像这样添加属性 ajaxSingle = true

    <a4j:commandButton value="Annuleer" ajaxSingle="true"  
                         onclick="#{rich:component(popupID)}.hide();" />  
    

    如果你使用的是richfaces 4.X,那么使用执行属性

     <a4j:commandButton value="Annuleer" execute="@this"  
                       onclick="#    {rich:component(popupID)}.hide();" />  
    

    在这两种情况下,只有您的命令按钮会在后端处理。

    希望这会有所帮助。

    【讨论】:

      【解决方案2】:

      要完全取消对服务器的请求,请将return false; 添加到 onclick 处理程序:

      <a4j:commandButton value="Annuleer"
              onclick="#{rich:component(popupID)}.hide(); return false" />
      

      如果您仍需要重新渲染某些区域(因此您需要 ajax 请求),请使用其他答案中所述的解决方案 (execute="@this")。

      【讨论】:

        【解决方案3】:

        这不是 popupPanel 做的。 &lt;a4j:commandButton&gt;commandLink 默认提交整个表单。如果您不想提交任何内容,请添加 execute="@none"

        【讨论】:

        • 我认为应该是 execute="@this"。 "@none" 不会处理任何内容
        • execute="@none" 和 execute="@this" 都有效。这2个有区别吗?
        • @SrikanthGanji 不过没有什么要处理的。该按钮没有需要执行的@actionListener
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2011-10-24
        • 2018-05-16
        • 2014-11-30
        • 1970-01-01
        • 2021-08-22
        • 2017-11-01
        相关资源
        最近更新 更多