【问题标题】:JSF backing bean triggered when not called [duplicate]未调用时触发 JSF 支持 bean [重复]
【发布时间】:2015-07-03 14:34:48
【问题描述】:

我在 .xhtml 中有这个按钮:

    <p:commandButton id="openDialog"
     value="#{msg.CreateMultiple}"
     onclick="PF('dialogLocations').show();" title="View"
     type="button">
     </p:commandButton>

它应该做的是打开具有下一个代码的对话框dialogLocations:

<p:dialog header="#{msg.CreateMultiple}" id="dialogLocations"
            widgetVar="dialogLocations" modal="true"closable="true"
            dynamic="true" closeOnEscape="true">
            <h:form>

                        <p:commandButton id="acceptMultiple_button" value="#{msg.Create}"
                            action="#{locationCreateBean.createMultiple(true)}"
                            styleClass="btn-green internal-margin-left" update="@form">
                        </p:commandButton>

                        <p:commandButton id="cancelMultiple_button"
                            styleClass="btn-red internal-margin-left"
                            onclick="PF('dialogLocations').hide();" value="#{msg.Cancel}"
                            title="View" type="button">
                        </p:commandButton>

                    </div>


                </h:panelGroup>

            </h:form>
        </p:dialog>

对话框有一些输入也可以在 bean 中使用。

我的问题是,当我单击按钮“openDialog”时,对话框打开并调用 locationBean.createMultiple(true) 方法,这是按钮“acceptMultiple_button”的操作。

点击按钮的时候不应该触发按钮的动作吗?

谢谢。

【问题讨论】:

  • 您的预期是正确的。其他人正在调用createMultiple。如果您将action 更改为完全使用不同的方法(即使只是一个空的createMultiple2),对话框打开时是否仍会调用它?
  • 除非有错别字,否则&lt;p:commandButton&gt; 标签的表述不正确。
  • 我试过了,添加了 createMultiple2,它仍然调用 createMultiple。但我检查并在 Xhtml 中仅在该按钮中调用它。而在 bean 中,它永远不会被调用。
  • 是在此处粘贴代码的错误。对不起
  • 等一下:所以您将您的action 更改为调用createMultiple2 并且有些东西仍然调用createMultiple?你需要找出那个“东西”是什么。这里没有真正的魔法,JSF 不会调用你不告诉它的方法。

标签: jsf javabeans


【解决方案1】:

解决了。这是对 &lt;!-- --&gt; 包围的 xhtml 的评论,它调用了该方法。我认为在评论中不会调用该函数。但似乎有时它无论如何都会调用评论。

感谢cmets。

【讨论】:

    猜你喜欢
    • 2011-04-04
    • 2013-03-24
    • 2012-08-03
    • 1970-01-01
    • 1970-01-01
    • 2014-02-25
    • 1970-01-01
    • 2017-11-06
    • 2016-10-15
    相关资源
    最近更新 更多