• Viernes 17 de Mayo de 2024, 06:59

Autor Tema:  JSF 2.0 - Comunicacion entre managed beans  (Leído 5696 veces)

SFRJ

  • Miembro MUY activo
  • ***
  • Mensajes: 115
    • Ver Perfil
JSF 2.0 - Comunicacion entre managed beans
« en: Jueves 10 de Febrero de 2011, 13:58 »
0
Me gustaria saber si existe alguna alternativa, en JSF 2.0 para comunicar entre beans.
Concretamente, me gustaria saber, como puedo pasar un valor String a la URL desde un managedbean o desde una pagina .xhtml, para poder luego leerlo en la pagina destino.

Yo utilizo la siguiente tecninca para pasar valores, cuando mi managed bean es @Stateless, aunque no me gusta mucho, ya que luego tengo que llamar al metodo clear(), para vaciar el pool del FacesContext. Sabe alguien si se puede hacer de otra manera?

Código: Java
  1.  
  2. BEAN1:
  3. //Save a value to the context
  4. FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("clickedLink", "" + selectedLinkIndex);
  5.        
  6. BEAN2:
  7. @PostConstruct//This annotation is needed otherwise the value will be lost
  8.     public void init() {
  9.         //Read a value from the context
  10.         currentCity = FacesContext.getCurrentInstance().getExternalContext()
  11.                 .getRequestMap().get("clickedLink").toString();
  12. //Clearing the resources in the instance map after ussing.
  13.         FacesContext.getCurrentInstance().getCurrentInstance()
  14.                 .getExternalContext().getRequestMap().clear();
  15.     }
  16.  
  17.