问题描述
我有一个自定义TAGFILE与窗体:
I have a custom tagfile with a form:
<h:form>
<h:commandButton value="click">
<f:ajax event="click" listener="#{bean[method]}" />
</h:commandButton>
</h:form>
我有条件通过AJAX使得它如下:
I'm conditionally rendering it by ajax as below:
<h:panelGroup id="test">
<h:form>
<h:commandButton value="click">
<f:ajax event="click" listener="#{backingTest.updateFlag}" render=":test"/>
</h:commandButton>
</h:form>
<h:panelGroup rendered="#{backingTest.flag}">
<my:customtag bean="#{backingTest}" method="printMessage"/>
</h:panelGroup>
</h:panelGroup>
这是相关联的支持bean:
This is the associated backing bean:
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
@ManagedBean
@RequestScoped
public class BackingTest {
private boolean flag = false;
public void printMessage() {
System.out.println("hello");
}
public void updateFlag() {
flag = true;
}
public boolean getFlag() {
return flag;
}
}
当我点击第一个命令按钮,然后 updateFlag()
方法是否正确调用,第二个命令按钮的正常显示。但是,当我再单击第二个命令按钮,它从来没有击中 printMessage()
方法。在Web浏览器的JS控制台和HTTP流量监控器,我可以看到点击
事件被成功地发射,而且XHR POST请求被成功发送。
When I click the first command button, then the updateFlag()
method is properly invoked and the second command button is properly shown. But when I then click the second command button, it never hits the printMessage()
method. In the web browser's JS console and HTTP traffic monitor I can see that the click
event is successfully fired and that the XHR POST request is successfully being sent.
如果我删除渲染
属性,然后一切工作正常。
If I remove the rendered
attribute, then everything works as expected.
这是怎么造成的,我该怎么解决呢?我使用Mojarra 2.1.25。
How is this caused and how can I solve it? I'm using Mojarra 2.1.25.
推荐答案
您的具体问题是由2事实:
Your concrete problem is caused by 2 facts:
- 当JSF需要去codeA表单提交动作,它还会检查,如果组件呈现与否。
- 在请求范围豆重新对每个HTTP请求(Ajax请求数也可作为一个!)。
因此,渲染
病情评估假
而JSF需要去code中的表单提交动作因此,动作事件被从未排队。
So, the rendered
condition has evaluated false
while JSF needs to decode the form submit action and therefore the action event is never queued.
把豆考虑范围应该修复它。
Putting the bean in view scope should fix it.
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
这问题是无关的TAGFILE。
This problem is unrelated to the tagfile.
- h:commandLink / H:的commandButton没有被调用 - 5点
- How要选择合适的豆范围有多大?
- h:commandLink / h:commandButton is not being invoked - point 5
- How to choose the right bean scope?
这篇关于表单提交的有条件渲染的成分不被处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!