Primefaces commandButton action属性未被调用 [英] Primefaces commandButton action attribute not being called

查看:139
本文介绍了Primefaces commandButton action属性未被调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用primefaces创建一个JSF应用程序。基本上我有这个观点。有一个标签视图,每个标签包含一个命令按钮和一个折叠面板(另一种标签视图)。手风琴面板的选项卡以及其他元素包含每个命令按钮。我的问题是第一个命令按钮(在1级选项卡下)在单击时正确调用操作方法,而第二个按钮(在2级选项卡下)则没有。我应该说tabView和accordionPanel都正常工作,因为他们正在显示他们应该显示的信息。

I am creating a JSF application with primefaces. Basically I have this view. There is a tab view which for each tab contains a command button and a accordion panel (another kind of tab view). The tabs of the accordion panel among other elements, contain each one command button. My problem is that the first command button (under 1 level of tabs) calls correctly the action method when it is clicked, while the second button (under 2 level of tabs) does not. I should say that both the tabView and accordionPanel are working correctly, since they are displaying the information they should display.

我发布了我的视图的简化版本,以便你可以看到发生了什么。

I am posting a simplified version of my view so that you can see what is happening.

<h:form>
<p:tabView id="unitTabs"  orientation="left" dynamic="true" cache="false" var="unit" value="#{unitController.getUnitsOfLoggedInUser(loginController.checkedUser)}">
    <p:tab id="unitTab" title="#{unit.unitName}">

    <p:commandButton value="Add Lecture" action="#{unitController.setTemporary(unit)}" onclick="createLectureDialog.show()">

    <p:accordionPanel id="lectureTabs" value ="#{lectureController.getLecturesForUnit(unit)}" var="lecture" dynamic="true" cache="false">

         <p:tab title="#{lecture.lectureName}">
              <p:commandButton value="Add Criterion" action ="#{lectureController.setTemporary(lecture)}" onclick="createCriterionDialog.show()" >
         </p:tab>
     </p:accordionPanel>
     </p:tab>
</p:tabView>
</h:form>

我做错了什么?谢谢

推荐答案

此构造要求属性中的EL表达式< p:tabView> < p:accordionPanel> 返回完全相同处理表单时的值在初始显示期间提交。

This construct requires that the EL expression in the value attribute of the <p:tabView> and <p:accordionPanel> returns exactly the same value during processing the form submit as it was during the initial display.

如果bean是请求作用域和/或值取决于基于请求的参数或变量的幕后,因此它会在每个请求中返回不同的值,那么它将失败,因为JSF无法找到已被调用的按钮。要修复它,需要将bean放在视图范围内,并且getter方法不应包含任何业务逻辑,或者在后续请求中应保留任何基于请求的参数或变量。

If the bean is request scoped and/or the value depends behind the scenes on a request based parameter or variable and it thus returns a different value on every request, then it will fail because JSF cannot locate the button which was been invoked. To fix it, the bean needs to be placed in the view scope and the getter method should not contain any business logic, or any request based parameters or variables should be retained in the subsequent requests.

  • commandButton/commandLink/ajax action/listener method not invoked or input value not updated - point 4.

这篇关于Primefaces commandButton action属性未被调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆