2010-06-24 14 views
5

¿Es posible que la actualización JSF sea un componente que se encuentra fuera del contexto del componente?Actualizar un componente fuera del contexto del componente <f:ajax>

Actualmente la página siguiente no está funcionando:

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

sé que si pongo el componente #out dentro <h:form> la página se procesa de forma correcta. Pero, ¿hay alguna forma de colocar el componente #out fuera del formulario (por ejemplo, donde está ahora)?

Respuesta

10

¡Resuelto! Es posible referirse a out como :out. De esta forma, findComponent la busca a partir de la raíz de la vista. Así que aquí está la solución de trabajo:

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