JSF2.0 与只能工作一次
我在 JSF2.0 中的标签有问题,我希望有人能指出我做错了什么。这是我在 UI 中得到的内容:
<h:panelGroup>
<h:form id="theForm">
<h:selectOneMenu id="theMenu" value="#{viewBean.selectedItem}">
<f:ajax event="change" render="selectedItemText"/>
<f:selectItem itemLabel=""/>
<f:selectItems value="#{viewBean.selectableItems}"/>
</h:selectOneMenu>
<h:outputText id="selectedItemText" value="#{viewBean.selectedItemText}" />
</h:form>
</h:panelGroup>
这非常有效 - 我的对话范围支持 bean 有一个方法 setSelectedItem
,当我第一次从其中选择不同的项目时,它会被调用并执行其操作菜单;输出文本在前端更新,我很高兴。但是,对菜单选择的进一步更改不会触发通过 ajax 对设置器的调用。我还在 f:ajax
标记上尝试过使用侦听器 - 侦听器方法也仅在第一次被调用(代码中的断点来解决这个问题)。
我做错了什么吗?
I'm having a problem with the tag in JSF2.0 and I hope someone can point out what I'm doing wrong. Here's what I've got in the UI:
<h:panelGroup>
<h:form id="theForm">
<h:selectOneMenu id="theMenu" value="#{viewBean.selectedItem}">
<f:ajax event="change" render="selectedItemText"/>
<f:selectItem itemLabel=""/>
<f:selectItems value="#{viewBean.selectableItems}"/>
</h:selectOneMenu>
<h:outputText id="selectedItemText" value="#{viewBean.selectedItemText}" />
</h:form>
</h:panelGroup>
This is working great - my conversation-scoped backing bean has a method setSelectedItem
, and it's called and it does its thing the first time I select a different item from the menu; the output text is updated in the frontend, and I'm happy. However, further changes to the menu selection do not trigger a call to the setter via ajax. I've also tried this with a listener on the f:ajax
tag - the listener method is only called that first time as well (breakpoints in the code to figure this out).
Am I doing something incorrectly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我有同样的问题。
对于下面的代码,ajax 仅运行一次。
当我将正在执行的元素添加到渲染属性时,每次都会触发ajax。
I had the same issue.
For the code below ajax was run only once.
When I add to render attribute the element which I'm executing then the ajax is triggered every time.
我有一个类似的问题,在我的例子中,除了 IE9 中 ajax 只被触发一次之外,所有浏览器都工作正常。
我正在使用
render="@form"
,当我将其更改为render="@all"
时,它工作得很好。我不知道为什么,因为我在该页面中只有一个表单,而我的所有组件都是该表单。所以我建议你检查
render
和execute
标签,至少在我的情况下这是解决方案I had a similar problem, in my case everithing worked fine in all browsers except that in IE9 the ajax was fired only once.
I was using
render="@form"
and when I changed it torender="@all"
, it worked fine. I dunno why, since I only have one Form in that page, and all my components are in that form.So I would advise you to check the
render
andexecute
tags, at least in my case it was the solution我有同样的错误,使用
Primeface's
p:ajax
而不是f:ajax
修复了它。I had the same bug, fixed it using
Primeface's
p:ajax
instead off:ajax
.我有类似的问题。
下面的第二个 commandButton 仅在下面具有视图参数的 JSF 视图中工作一次。将
添加到我的第一个 commandButton 解决了问题。 BalusC 的非常有用的讨论未涵盖这种情况。我的 FooManager 和 BarManager 看起来是一样的:
当它不工作时,我的 Weblogic/Mojarra 库不会给出任何有用的提示。任何地方都没有错误。经过多次尝试后,我才想出了一个像上面第一个按钮一样的工作按钮。
I had a similar problem.
My second commandButton below only works once in the JSF view below that has a view param. Adding
<f:param>
to my first commandButton solved the problem. This is a situation not covered by BalusC's very helpful discussion.And my FooManager and BarManager look the same:
When it is not working, my Weblogic/Mojarra library does not give any helpful hint. There is no error anywhere. It was only after numerous tries that I came up with a working button like the first one above.