JSF 2.0 Accessing Application Scope bean from another Bean

前端 未结 3 655
鱼传尺愫
鱼传尺愫 2020-12-29 00:44

I am using jsf 2.0 and I have two bean Navigation (Application Scope ) and Module (Request Scope). I want to use methods of Navigation bean in Module Bean. I am doing in thi

3条回答
  •  旧时难觅i
    2020-12-29 01:35

    I got The solution

    I have a method in application signature boolean getReadAccess(String role, String module ). If i want to use in another bean then i have to follow these steps

        `javax.el.MethodExpression readAccess;
         javax.el.ELContext elContext = null;
         javax.faces.context.FacesContext context = FacesContext.getCurrentInstance();
         elContext = ((FacesContext) context).getELContext();
         javax.faces.application.Application application = FacesContext.getCurrentInstance().getApplication();
         javax.el.ExpressionFactory expressionFactory = application.getExpressionFactory();
         readAccess = expressionFactory.createMethodExpression(elContext,
                "#{navigationBean.getReadAccess}", Void.class, new Class[] {
                        String.class, String.class });
    
        //--------Call----------------------------
        return (Boolean) readAccess.invoke(elContext, new Object[] {
                    "roleName", "moduleName" });
    

    `

提交回复
热议问题