# SEVERE: Managedbean could not be created



## Verena22 (10. Jan 2008)

Hi Leute!
Hat schon mal irgendwer folgenden Fehler bekommen? 

SEVERE: Managedbean appConstraints could not be created Klasse kann nicht instanziiert werden: 'susi.backing.AppAuthorConstraints'.. class
  susi.backing.AppAuthorConstraints : java.lang.NullPointerException

Ich arbeite derzeit an einem JSF-Tool, das auf einem Oracle 10g ApplicationServer laufen soll, wenn da nicht der Fehler wäre...

Ich versuche mir da eigentlich nur aus einem ManagedBean Informationen zu holen, funktioniert beim erstem Einloggen einwandfrei. Logge ich mich dann aus meiner Anwendung aus und dann mit dem gleichen Benutzer wieder ein, crashed die Anwendung mit obigen Fehler. 

Deswegen hatte ich eigentlich gedacht, dass es ein Session-Fehler sein könnte und habe noch in meine JSF-Anwendung ein session.invalidate() beim Logout eingebaut. Verändert hat sich aber leider nichts. Läuft immer noch nicht wie erwartet...

Weiß jemand von euch wo der Fehler liegen könnte? Oder hat jemand einen Anhaltspunkt für mich?

Ich bin für jede Antwort dankbar.

Gruß
Verena


----------



## maki (10. Jan 2008)

Der Fehler ist im Code oder in der Config, selten auch in der JSF Implementierung.

Du wirst uns schon Code & Config zeigen müssen.


----------



## Verena22 (10. Jan 2008)

Auf den JSP-Seiten sollen Funktionen abhängig von den Benutzergruppen sein. Um diese Funktionen zu enablen bzw. disablen, wird zum Beispiel beim CommandMenuItem Attribut gesetzt über die EL. 

appConstraints ist hier mein ManagedBean und rightRightsView eine Variable der Klasse vom Datentyp boolean.

Beispiel commandMenuItem aus meiner index.jsp

```
<af:commandMenuItem text="#{bundle.view_rights}"
                                    id="bViewRights" action="rights"
                                    disabled="#{appConstraints.rightRightsView}"/>
```

Hier der zugehörige faces-config-Eintrag zu meinem Bean:

```
<managed-bean>
    <managed-bean-name>appConstraints</managed-bean-name>
    <managed-bean-class>susi.backing.AppAuthorConstraints</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
  </managed-bean>
```

Über den Konstruktor meines Beans sollen sich die verschiedenen Berechtigungsvariablen füllen. 

Dazu hier die Funktionen aus dem Bean und die Variablen:

```
private boolean rightTemplateEdit = false;
    private boolean rightTemplateDelete = false;
    private boolean rightRightsView = false;
    private boolean rightLanguageCreate = false;
    private boolean rightLanguageEdit = false;
    private boolean rightAuthorization = false;
    private boolean rightMasterData = false;

    public AppAuthorConstraints() {
        //FacesContext ctx = FacesContext.getCurrentInstance();
        //String l_return_url = ctx.getExternalContext().getRequestContextPath();
        getAuthorListForUser(AdfUtils.getUsername());
    }

    private void getAuthorListForUser(String user) {
        ContentServiceInterface csi = ContentServiceInterfaceFactory.getFactory().getPooledInstance();
        try{
            // get all Authorizations for the user whose logged in in a map
            Map authorMapForUser = csi.getAuthorMapForUser(user);
            
            if(authorMapForUser != null){
                rightLanguageCreate = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_LANGUAGE_CREATE));            
                rightLanguageEdit = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_LANGUAGE_EDIT));
                rightRightsView = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_RIGHTS_VIEW));
                rightTemplateDelete = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_TEMPLATE_DELETE));
                rightTemplateEdit = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_TEMPLATE_EDIT));
                rightAuthorization = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_AUTHORIZATION));
                rightMasterData = isFunctionDisabled((String)authorMapForUser.get(F_SUSI_RIGHT_MASTER_DATA));
            } else {
                rightLanguageCreate = true;            
                rightLanguageEdit = true;
                rightRightsView = true;
                rightTemplateDelete = true;
                rightTemplateEdit = true;
                rightAuthorization = true;
                rightMasterData = true;
            }
            
            authorMapForUser = null;
        } catch(SusiException susiEx){
            handleException(susiEx);
        } finally {
            csi.release();
        }
    }

    public boolean isFunctionDisabled(String disableString){
        if(disableString != null && disableString.equals("false")){
            return false;
        }else{
            return true;
        }
    }
```

Die Funktion csi.getAuthorMapForUser(user) sieht wie folgt aus.

```
public Map getAuthorMapForUser(String user)throws SusiException{
        String userId = webservice.getUserIdFromUserName(user);
        if(userId != null){
            try{
                // Besorgt alle Gruppen vom Schnittstellen-System in denen der eingeloggte Benutzer eine Mitgliedschaft besitzt.                 

                Identity[] groups = webservice.findUsersGroups(userId);
                List lUserGroups = null;
                if(groups != null && groups.length > 0){
                    lUserGroups = Arrays.asList(groups);
                }
                groups = null;
                // Liest alle Berechtigungen für die Gruppen aus der Datenbank und kumuliert die Berechtigungen, die in einer Map zurückgegeben werden an das Bean.
                return getUsersAuthorsByGroups(lUserGroups);
            }catch(FdkException fdkEx){
                throw new SusiException(handleFdkException(fdkEx.getDetailedErrorCode()));
            }catch(MalformedURLException malEx){
                throw new SusiException(malEx);
            }catch(RemoteException rmEx){
                throw new SusiException(handleFdkException(rmEx.getMessage()));
            }catch(ServiceException servEx){
                throw new SusiException(servEx);
            } catch (NullPointerException nullEx) {
                throw new SusiException(bundle.getString(F_SUSI_EXCEPTION_NULLPOINTER_EXCEPTION));
            }
        } else {
            return null;
        }
    }

    // setzte eine Liste mit Berechtigungen für Gruppen zusammen
    private Map getUsersAuthorsByGroups(List lUserGroups) throws SusiException{
        Map userAuthorizations = new HashMap(); 
        if(lUserGroups != null && !lUserGroups.isEmpty()){
            Iterator itUserGroups = lUserGroups.iterator();
            while(itUserGroups.hasNext()){
                Identity groupIdent = (Identity)itUserGroups.next();
                
                List groupAuthorizations = getGroupAuthorizations(groupIdent.getName());
                
                Iterator itGroupAuthorizations = groupAuthorizations.iterator();
                while(itGroupAuthorizations.hasNext()){
                    String authorization = (String)itGroupAuthorizations.next();
                    
                    Iterator it = userAuthorizations.entrySet().iterator();
                    boolean hasAuthorization = false;
                    while ( it.hasNext() ) {
                       Map.Entry entry = (Map.Entry) it.next();
                         if(entry.getValue().equals(authorization)){
                            hasAuthorization = true;
                         }
                        entry = null;
                    }
                    
                    it = null;
                    
                    if(!hasAuthorization){
                        userAuthorizations.put(authorization, "false");
                    }
                    authorization = null;
                }
                itGroupAuthorizations = null;
                groupAuthorizations = null;
                groupIdent = null;
            }
            itUserGroups = null;
        }
        lUserGroups = null;
        return userAuthorizations;
    }

    // Hollt alle Berechtigungen für eine Gruppe aus der DB
    private List getGroupAuthorizations(String groupName) throws SusiException{
        getJNDIConnectionToSusiDB();
        List groupAuthorizations = new ArrayList();
        try{
            ps = conn.prepareStatement(F_SELECT_ATH_FOR_GROUP);
            ps.setString(1, groupName);
            ResultSet result = ps.executeQuery();
            
            while(result.next()){
                groupAuthorizations.add(result.getString(F_ATH_AUTHORIZATION));
            }
        }catch(SQLException sqlEx){
            throw new SusiException(sqlEx);
        } catch (NullPointerException nullEx) {
            throw new SusiException(bundle.getString(F_SUSI_EXCEPTION_NULLPOINTER_EXCEPTION));
        }finally{
            if(conn != null){
                disconnectConnectionToSusiDB();
            }
        }
        
        return groupAuthorizations;
    }
```

und hier noch die Funktion findUsersGroups:

```
public Identity[] findUsersGroups(String userId)
        throws FdkException, MalformedURLException, RemoteException, 
               ServiceException {


        // we need the user-name for S2S-Login.... get item by using commonmanager
        AttributeRequest[] requestedUserAttributes = new AttributeRequest[]
            { new AttributeRequest(Attributes.NAME, null), };
        CommonManager cm = wsConnection.getCommonManager();

        long idLong = Long.parseLong(userId);

        Item UserItem = cm.getItem(idLong, requestedUserAttributes);
        //get the ServiceToService-Connection
        wsConnection.S2Slogin(UserItem.getName());
        try {
            ArrayList listOfGroups = new ArrayList();

            NamedValue[] groupOptions = 
                WsUtility.newNamedValueArray(new Object[][]
                    {
                        { Options.HAS_MEMBER, new Long(userId) } });

            GroupManager gm = Managers.getGroupManager(wsConnection.session);
            
            Identity[] listOfGroupsArray = null;
            if(gm != null){
                Item[] groups = gm.findGroups(groupOptions, null);
    
                if (groups != null) {
                    for (int i = 0; i < groups.length; i++) {
                        Identity member_identity = new Identity();
                        member_identity.setItemId(String.valueOf(groups[i].getId()));
                        member_identity.setName(groups[i].getName());
                        member_identity.setType(groups[i].getType());
                        listOfGroups.add(member_identity);
                    }
                    listOfGroupsArray = new Identity[listOfGroups.size()];
                    int x = -1;
                    //add users to returnlist listOfGroupsArray
                    for (Iterator i = listOfGroups.iterator(); i.hasNext(); ) {
                        x++;
                        listOfGroupsArray[x] = (Identity)i.next();
                    }
                }
            }
            
            return listOfGroupsArray;
        } finally {
            wsConnection.session.disconnect();
        }

    }
```


----------



## Verena22 (10. Jan 2008)

```
SEVERE: Managedbean appConstraints could not be created Klasse kann nicht instanziiert werden: 'susi.backing.AppAuthorConstraints'.. class
  susi.backing.AppAuthorConstraints : java.lang.NullPointerException
javax.faces.FacesException: Klasse kann nicht instanziiert werden: 'susi.backing.AppAuthorConstraints'.. class susi.backing.AppAuthorConstraints
  : java.lang.NullPointerException
    at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:229)
    at com.sun.faces.application.ApplicationAssociate.createAndMaybeStoreManagedBeans(ApplicationAssociate.java:306)
    at com.sun.faces.el.VariableResolverImpl.resolveVariable(VariableResolverImpl.java:97)
    at oracle.adfinternal.view.faces.el.AdfFacesVariableResolver.resolveVariable(AdfFacesVariableResolver.java:40)
    at com.sun.faces.el.impl.NamedValue.evaluate(NamedValue.java:145)
    at com.sun.faces.el.impl.ComplexValue.evaluate(ComplexValue.java:166)
    at com.sun.faces.el.impl.ExpressionEvaluatorImpl.evaluate(ExpressionEvaluatorImpl.java:263)
    at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:160)
    at com.sun.faces.el.ValueBindingImpl.getValue(ValueBindingImpl.java:143)
    at oracle.adfinternal.view.faces.uinode.ValueBindingBoundValue.getValue(ValueBindingBoundValue.java:30)
    at oracle.adfinternal.view.faces.uinode.UIXComponentUINode.getAttributeValueImpl(UIXComponentUINode.java:392)
    at oracle.adfinternal.view.faces.uinode.UIXComponentUINode.getAttributeValue(UIXComponentUINode.java:127)
    at oracle.adfinternal.view.faces.ui.laf.base.BaseLafRenderer.isDisabled(BaseLafRenderer.java:67)
    at oracle.adfinternal.view.faces.ui.laf.oracle.desktop.GlobalButtonRenderer.getStyleClass(GlobalButtonRenderer.java:487)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer._getLocalStyleClass(XhtmlLafRenderer.java:2247)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer.prerender(XhtmlLafRenderer.java:188)
    at oracle.adfinternal.view.faces.ui.laf.oracle.desktop.GlobalButtonRenderer.prerender(GlobalButtonRenderer.java:66)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.render(BaseRenderer.java:79)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer.render(XhtmlLafRenderer.java:69)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.AliasRenderer.render(AliasRenderer.java:28)
    at oracle.adfinternal.view.faces.uinode.UIXComponentUINode.renderInternal(UIXComponentUINode.java:177)
    at oracle.adfinternal.view.faces.uinode.UINodeRendererBase.encodeEnd(UINodeRendererBase.java:53)
    at oracle.adf.view.faces.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:624)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode._renderComponent(UIComponentUINode.java:317)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode.render(UIComponentUINode.java:262)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode.render(UIComponentUINode.java:239)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderChild(BaseRenderer.java:412)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.RowLayoutRenderer.renderChild(RowLayoutRenderer.java:90)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderIndexedChild(BaseRenderer.java:330)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderIndexedChild(BaseRenderer.java:222)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderContent(BaseRenderer.java:129)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.GlobalButtonBarRenderer.renderContent(GlobalButtonBarRenderer.java:116)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.render(BaseRenderer.java:81)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer.render(XhtmlLafRenderer.java:69)
    at oracle.adfinternal.view.faces.uinode.UIXComponentUINode.renderInternal(UIXComponentUINode.java:177)
    at oracle.adfinternal.view.faces.uinode.UINodeRendererBase.encodeEnd(UINodeRendererBase.java:53)
    at oracle.adf.view.faces.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:624)
    at oracle.adf.view.faces.component.UIXCollection.encodeEnd(UIXCollection.java:456)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode._renderComponent(UIComponentUINode.java:317)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode.render(UIComponentUINode.java:262)
    at oracle.adfinternal.view.faces.uinode.UIComponentUINode.render(UIComponentUINode.java:239)
    at oracle.adfinternal.view.faces.ui.composite.ContextPoppingUINode$ContextPoppingRenderer.render(ContextPoppingUINode.java:224)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:346)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:301)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderChild(BaseRenderer.java:412)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderNamedChild(BaseRenderer.java:384)
    at oracle.adfinternal.view.faces.ui.laf.base.desktop.PageHeaderLayoutRenderer.renderContent(PageHeaderLayoutRenderer.java:404)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.render(BaseRenderer.java:81)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer.render(XhtmlLafRenderer.java:69)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:346)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:301)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderChild(BaseRenderer.java:412)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderIndexedChild(BaseRenderer.java:330)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderIndexedChild(BaseRenderer.java:222)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.renderContent(BaseRenderer.java:129)
    at oracle.adfinternal.view.faces.ui.BaseRenderer.render(BaseRenderer.java:81)
    at oracle.adfinternal.view.faces.ui.laf.base.xhtml.XhtmlLafRenderer.render(XhtmlLafRenderer.java:69)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:346)
    at oracle.adfinternal.view.faces.ui.BaseUINode.render(BaseUINode.java:301)
    at oracle.adfinternal.view.faces.ui.composite.UINodeRenderer.renderWithNode(UINodeRenderer.java:90)
    at oracle.adfinternal.view.faces.ui.composite.UINodeRenderer.render(UINodeRenderer.java:36)
    at oracle.adfinternal.view.faces.ui.laf.oracle.desktop.PageLayoutRenderer.render(PageLayoutRenderer.java:76)
    at oracle.adfinternal.view.faces.uinode.UIXComponentUINode.renderInternal(UIXComponentUINode.java:177)
    at oracle.adfinternal.view.faces.uinode.UINodeRendererBase.encodeEnd(UINodeRendererBase.java:53)
    at oracle.adf.view.faces.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:624)
    at oracle.adfinternal.view.faces.renderkit.RenderUtils.encodeRecursive(RenderUtils.java:54)
    at oracle.adfinternal.view.faces.renderkit.core.CoreRenderer.encodeChild(CoreRenderer.java:242)
    at oracle.adfinternal.view.faces.renderkit.core.CoreRenderer.encodeAllChildren(CoreRenderer.java:265)
    at oracle.adfinternal.view.faces.renderkit.core.xhtml.PanelPartialRootRenderer.renderContent(PanelPartialRootRenderer.java:65)
    at oracle.adfinternal.view.faces.renderkit.core.xhtml.BodyRenderer.renderContent(BodyRenderer.java:117)
    at oracle.adfinternal.view.faces.renderkit.core.xhtml.PanelPartialRootRenderer.encodeAll(PanelPartialRootRenderer.java:147)
    at oracle.adfinternal.view.faces.renderkit.core.xhtml.BodyRenderer.encodeAll(BodyRenderer.java:60)
    at oracle.adfinternal.view.faces.renderkit.core.CoreRenderer.encodeEnd(CoreRenderer.java:169)
    at oracle.adf.view.faces.component.UIXComponentBase.encodeEnd(UIXComponentBase.java:624)
    at javax.faces.webapp.UIComponentTag.encodeEnd(UIComponentTag.java:645)
    at javax.faces.webapp.UIComponentTag.doEndTag(UIComponentTag.java:568)
    at oracle.adf.view.faces.webapp.UIXComponentTag.doEndTag(UIXComponentTag.java:100)
    at _index._jspService(_index.java:372)
    at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:56)
    at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:350)
    at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:509)
    at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:413)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:824)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330)
    at com.evermind.server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:253)
    at com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:346)
    at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:152)
    at oracle.adfinternal.view.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:157)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:107)
    at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:245)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:137)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:214)
    at com.evermind.server.http.ResourceFilterChain.doFilter(ResourceFilterChain.java:65)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._invokeDoFilter(AdfFacesFilterImpl.java:228)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl._doFilterImpl(AdfFacesFilterImpl.java:197)
    at oracle.adfinternal.view.faces.webapp.AdfFacesFilterImpl.doFilter(AdfFacesFilterImpl.java:123)
    at oracle.adf.view.faces.webapp.AdfFacesFilter.doFilter(AdfFacesFilter.java:103)
    at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:663)
    at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:330)
    at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:224)
    at com.evermind.server.http.AJPRequestHandler.run(AJPRequestHandler.java:133)
    at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
    at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.ClassNotFoundException: class susi.backing.AppAuthorConstraints : java.lang.NullPointerException
    at java.beans.Beans.instantiate(Beans.java:208)
    at java.beans.Beans.instantiate(Beans.java:48)
    at com.sun.faces.config.ManagedBeanFactory.newInstance(ManagedBeanFactory.java:223)
    ... 104 more
```


----------

