更新< f:ajax>之外的组件组件的上下文 [英] Updating a component outside of the <f:ajax> component's context
本文介绍了更新< f:ajax>之外的组件组件的上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以让JSF更新放置在组件上下文之外的组件?
Is it possible to have the JSF update a component that's placed outside the component's context?
当前以下页面无法正常工作:
Currently the following page is not working:
<?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
组件放置在表单之外(例如,现在所在的位置)?
I know that if I put the #out
component inside <h:form>
the page will be rendered correctly. But is there a way to place the #out
component outside of the form (e.g. where it is right now)?
推荐答案
已解决!可以将out
称为:out
.这样,findComponent
从视图根开始搜索它.所以这是可行的解决方案:
Solved! It is possible to refer to out
as :out
. In this way findComponent
searches for it starting from the view root. So here's the working solution:
<?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>
这篇关于更新< f:ajax>之外的组件组件的上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文