【发布时间】:2014-01-09 13:51:55
【问题描述】:
我的测试应用程序包含两个h:inputText 和一个a4j:outputPanel,这是重新呈现两个文本字段的触发器。两个文本字段一开始都是空的,第二个也是不可见的。单击面板后,将调用一个方法,该方法设置输入值以及用于显示第二个文本字段的布尔值。代码如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:fm30x="http://myfaces.inter-forum.de/fm30x/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
<h:outputStylesheet name="stylesheet.css" library="css" />
</h:head>
<h:body>
<h:form id="mainForm">
<h:panelGrid>
<h:inputText id="text" value="#{testBean.testString}"/>
<h:inputText id="text2" value="#{testBean.trackingId}" rendered="#{testBean.showString}"/>
<a4j:outputPanel layout="block" styleClass="quote" onmousedown="begin();">
<h:outputText value="Thats a test" ></h:outputText>
</a4j:outputPanel>
</h:panelGrid>
<a4j:jsFunction name="begin" actionListener="#{testBean.start}" render="text text2" />
</h:form>
</h:body>
</html>
问题是,当点击面板时,只有第一个文本字段被渲染,而第二个文本字段仍然不可见,尽管我已经更新了 bean 内 ajax 方法中的布尔值。同样奇怪的是,当我总是为 getter 中的 showString 值返回 true 时,第二个文本字段值被更新(这次我可以看到它,因为那时第二个文本字段将始终呈现)。所以总而言之,我可以说实际值的更新是正确的,但是 ajax 没有正确评估 h:inputText 的 render 属性。我做错了什么?
【问题讨论】: