开发者

Updating a component outside of the <f:ajax> component's context

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>
    <ti开发者_运维百科tle>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>

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)?


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜