【问题标题】:Updating a component outside of the <f:ajax> component's context在 <f:ajax> 组件的上下文之外更新组件
【发布时间】:2010-06-24 16:33:01
【问题描述】:

是否可以让 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 组件放在&lt;h:form&gt; 中,页面将正确呈现。但是有没有办法将#out 组件放置在表单之外(例如它现在所在的位置)?

【问题讨论】:

    标签: jsf jsf-2


    【解决方案1】:

    解决了!可以将out 称为:out。这样findComponent 从视图根开始搜索它。所以这是可行的解决方案:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-26
      • 2011-11-23
      • 1970-01-01
      • 1970-01-01
      • 2020-01-01
      • 1970-01-01
      相关资源
      最近更新 更多