[英]Primefaces p:selectOneMenu or p:selectBooleanCheckbox not firing change-event depending on if I use h:form
I'm working with Primefaces 5.3. 我正在使用Primefaces 5.3。
First, I implemented functionality to change visibility of ap:selectOneMenu depending on the value of ap:selectBooleanCheckbox according to this post: 首先,根据这篇文章,我实现了根据ap:selectBooleanCheckbox的值更改ap:selectOneMenu可见性的功能:
Enabling and disabling components via select checkbox 通过选择复选框启用和禁用组件
This works so far, if I use the h:form. 到目前为止,如果我使用h:form,则此方法有效。
Next, I wanted to update the values in the bean, as chosen in the p:selectOneMenu. 接下来,我想更新p:selectOneMenu中选择的bean中的值。 This is where my question starts: Even if i use p:ajax to explicitly call a listener, it won't get called.
这是我的问题开始的地方:即使我使用p:ajax显式调用侦听器,也不会调用它。 This is my code:
这是我的代码:
<h:panelGrid>
<p:selectOneMenu value="#{schedulerCDIBean.selectedParentTask}" var="parentTask" id="taskDependence" disabled="#{task.dependsOn != 'true'}">
<p:ajax event="change" listener="#{schedulerCDIBean.taskToAddListener}"/>
<f:selectItems id="taskDependenceItems" value="#{schedulerCDIBean.taskWebDataObjectList}" var="item" itemLabel="#{item.taskName}"
itemValue="#{item}" />
<p:column>
<h:outputText value="#{parentTask}"/>
</p:column>
</p:selectOneMenu>
</h:panelGrid>
And here is how I enable/disable the selectOneMenu: 这是我启用/禁用selectOneMenu的方法:
<p:selectBooleanCheckbox id="dependsOnTask" value="#{task.dependsOn}" itemLabel="Depends On">
<p:ajax update="taskDependence" process="@this"/>
</p:selectBooleanCheckbox>
All this lives inside ap:tab of the p:accordionPanel where 'task' is the var of my DataObject-List. 所有这些都存在于p:accordionPanel的ap:tab中,其中“任务”是我的DataObject-List的变量。
As mentioned by @BalusC in this post: commandLink/commandButton/ajax backing bean action/listener method not invoked (Possible Causes: 2), 如@BalusC在这篇文章中所提到的: 未调用commandLink / commandButton / ajax支持bean操作/侦听器方法 (可能的原因:2),
"You cannot nest multiple UIForm components in each other."
“您不能相互嵌套多个UIForm组件。”
So, if i remove the h:form directive, the call to the listener in the bean works. 因此,如果我删除h:form指令,则对Bean中的侦听器的调用有效。 But now, the value of the p:selectBooleanCheckbox is always set to 'false', and thus the component is not being updated to visible.
但是现在,p:selectBooleanCheckbox的值始终设置为“ false”,因此该组件未更新为可见。
I found a post here , where OP had the same problem and solved it by adding the h:form directive. 我在这里找到了一篇文章,其中OP存在相同的问题,并通过添加h:form指令解决了该问题。
EDIT: My 'form' is a ui:composition and starts like this <ui:composition template="/templates/pages/mainPage.xhtml">
, where mainPage.xhtml contains h:head and includes the 'header.xhtml' by using ui:include, and there is ah:form. 编辑:我的“表单”是ui:composition,并且像这样
<ui:composition template="/templates/pages/mainPage.xhtml">
,其中mainPage.xhtml包含h:head并包含“ header.xhtml”使用ui:include,并且有ah:form。 But this h:form is already closed before, so the problem isn't here. 但是此h:form之前已经关闭,因此问题不在这里。
Well, I don't want to go the way with adding the h:form again, as it leads to unspecified behaviour. 好吧,我不想再添加h:form,因为它会导致未指定的行为。 But what am I doing wrong, if my p:selectBooleanCheckbox values are not being set correctly?
但是,如果我的p:selectBooleanCheckbox值设置不正确,那我在做什么错呢?
Thank you for your help! 谢谢您的帮助!
UPDATE 更新
The problem was not the h:form, as it actually wasn't nested. 问题不是h:form,因为它实际上不是嵌套的。 Now I'm just still stuck with the listeners for the p:selectOneMenu, as they aren't being called.
现在,我仍然停留在p:selectOneMenu的监听器上,因为它们没有被调用。 I also tried setting
partialSubmit="true"
on the <p:ajax />
, which did not lead to a solution so far. 我还尝试在
<p:ajax />
上设置partialSubmit="true"
,但到目前为止还没有找到解决方案。
Thanks for your help, guys. 伙计们,谢谢您的帮助。 With your help I fixed the problem.
在您的帮助下,我解决了问题。
Just as if someone else experiences similar problems, here a few things to check: 就像其他人遇到类似的问题一样,这里需要检查一些事项:
equals()
and hashCode()
of the object you're willing to show in the selectOneMenu. equals()
和hashCode()
。 The solution for my situation actually was mentioned in @irieill's comment: @irieill的评论中实际上提到了针对我的情况的解决方案:
[..]Not providing a proper converter does not raise any exceptions but faces error messages.
[..]不提供适当的转换器不会引发任何异常,但是会遇到错误消息。 So try to add a
<p:growl autoUpdate="true" />
to your page to see if any conversion error is raised.因此,请尝试在页面上添加
<p:growl autoUpdate="true" />
,以查看是否出现任何转换错误。 If so, add a propper converter to yourselectOneMenu
.如果是这样,请将propper转换器添加到
selectOneMenu
。
I think, that's also what @BalusC said at point 3 of his list of possible causes. 我认为,这也是@BalusC在其可能原因列表的第3点说的话。
See also: How to write a custom converter for <p:pickList>
, Custom converter in JSF 2.0 , PrimeFaces ShowCase: SelectOneMenu 另请参阅: 如何为
<p:pickList>
编写定制转换 器,JSF 2.0中的定制转换器 , PrimeFaces ShowCase:SelectOneMenu
As mentioned by @BalusC in this post: commandLink/commandButton/ajax backing bean action/listener method not invoked
就像@BalusC在这篇文章中提到的那样: 未调用commandLink / commandButton / ajax支持bean操作/侦听器方法
Also note point 1. You must enclose your input components with a <h:form />
tag. 还要注意第1点。您必须使用
<h:form />
标记将输入组件括起来。
Well, I don't want to go the way with adding the h:form again, as it leads to unspecified behaviour.
好吧,我不想再添加h:form,因为它会导致未指定的行为。
As i understand, you are misusing the tag or you do not understand how to use it. 据我了解,您正在滥用标签,或者您不知道如何使用它。 Just enclose your whole page (or at least all input components) in one
<h:form />
tag and it should work. 只需将整个页面(或至少所有输入组件)封装在一个
<h:form />
标记中,它就可以工作。
Can you please update your question with the page code also containing the lines where you placed the <h:form />
tag(s). 您能否用页面代码更新您的问题,该页面代码还包含放置
<h:form />
标记的行。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.