2010-06-24 19 views
5

È possibile che l'aggiornamento JSF sia un componente posizionato al di fuori del contesto del componente?Aggiornamento di un componente al di fuori del contesto del componente <f:ajax>

Attualmente la pagina seguente non funziona:

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

so che se metto la componente #out all'interno <h:form> pagina sarà reso in modo corretto. Ma esiste un modo per posizionare il componente #out al di fuori del modulo (ad esempio, dove è ora)?

risposta

10

Risolto! È possibile fare riferimento a out come :out. In questo modo, findComponent lo cerca partendo dalla radice della vista. Quindi ecco la soluzione di lavoro:

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