JSF是否可以更新放置在组件上下文之外的组件?
当前以下页面无法正常工作:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<p><h:outputText id="out" value="#{user.greeting}" /></p>
<h:form id="form1">
<h:inputText value="#{user.name}" id="user-name" />
<p><h:inputSecret value="#{user.password}" id="password" /></p>
<p>
<h:commandButton value="Login" id="login-button">
<f:ajax execute="user-name password" render="out" />
</h:commandButton>
</p>
</h:form>
</h:body>
</html>
我知道,如果我将
#out
组件放入<h:form>
中,则该页面将正确呈现。但是有没有办法将#out
组件放置在表单之外(例如,现在所在的位置)? 最佳答案
解决了!可以将out
称为:out
。这样,findComponent
从 View 根开始搜索它。所以这是可行的解决方案:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:f="http://java.sun.com/jsf/core">
<h:head>
<title>Welcome</title>
</h:head>
<h:body>
<p><h:outputText id="out" value="#{user.greeting}" /></p>
<h:form id="form1">
<h:inputText value="#{user.name}" id="user-name" />
<p><h:inputSecret value="#{user.password}" id="password" /></p>
<p>
<h:commandButton value="Login" id="login-button">
<f:ajax execute="user-name password" render=":out" />
</h:commandButton>
</p>
</h:form>
</h:body>
</html>
关于jsf - 更新<f :ajax> component's context之外的组件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3111919/