0

我需要从 sessionScoped 托管 bean 中获取 viewScoped 托管 bean。我首先尝试使用@ManagedProperty注释,但我立即发现它不起作用,我知道为什么。其次,我尝试使用以下方法:

Map<String, Object> viewMap = FacesContext.getCurrentInstance().getViewRoot().getViewMap();   
PulsantieraBean pulsantiera = (PulsantieraBean) viewMap.get("#{pulsantiera}");

但是当我在调试中访问对象时,pulsantiera 为空,并且 viewMap 对象仅包含另一个 viewScoped 托管 bean。PulsantieraBean类的声明方式如下

@ViewScoped
@ManagedBean(name = NomeBean.PULSANTIERA)
public class PulsantieraBean extends ControllerBaseBean implements Serializable {

而我提出请求的类声明如下

@SessionScoped
@ManagedBean(name = NomeBean.IDF_TAB_IMPORTI)
public class IdfTabImportiBean extends ControllerBaseBean implements Serializable {

我在我确定 viewScoped 托管 bean PulsantieraBean存在的方法中执行请求。

任何帮助,将不胜感激。谢谢,马可

4

1 回答 1

-1
@Named(value = "controladorMB")
@SessionScoped
public class ControladorMB implements Serializable {}

从 ListadoFacturasMB 调用 ControladorMB

@Named(value = "listadoFacturasMB")
@SessionScoped
public class ListadoFacturasMB implements Serializable {

public void example() {
    try {
        FacesContext ctx = FacesContext.getCurrentInstance();
        ValueExpression vex =ctx.getApplication().getExpressionFactory().createValueExpression(ctx.getELContext(), "#{controladorMB}", ControladorMB.class);
        ControladorMB gMB = (ControladorMB) vex.getValue(ctx.getELContext());
       } catch (Exception e) {
        JsfUtil.addErrorMessage(e, "Error: buscarPersonalizado() " + e.getMessage());
       }
   }
}
于 2014-10-30T17:58:04.353 回答