cancel
Showing results for 
Search instead for 
Did you mean: 

Extend NavigationBean.java

mesa2e
Champ in-the-making
Champ in-the-making
Hi,

I've extended the class NavigationBean, because I don't want the final user could see 'Guest Home' Panel, in that way:

public class MyNavigationBean extends NavigationBean{
   public boolean getGuestHomeVisible()
   {
    if(authService.guestUserAuthenticationAllowed())
    {
        Node guestHome = getGuestHomeNode();
       // return guestHome != null && guestHome.hasPermission("Read");
       // Show Guest Home only to admin user
        User user = Application.getCurrentUser(FacesContext.getCurrentInstance());
        return user.isAdmin();

    } else
    {
        return false;
    }
   }
}

My question is:
If I include my class in the alfresco-web-client.jar, how can I say to Alfresco that it should use the new class?
I need to extend more classes and I wanted to know how can I configure Alfresco.

Thanks in advance,
Elena.
6 REPLIES 6

dgenard
Champ on-the-rise
Champ on-the-rise
- Extend the class NavigationBean with your custom class (CustomNavigationBean.java)
- Compile and deploy this class in a jar placed in WEB-INF/lib
- Override the bean named "NavigationBean" with your custom bean, by inserting something like this in faces-config-custom.xml :
   <managed-bean>
      <description>A customization of default NavigationBean bean</description>
      <managed-bean-name>NavigationBean</managed-bean-name>
      <managed-bean-class>be.cediti.alfresco.web.bean.CustomNavigationBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>searchService</property-name>
         <value>#{SearchService}</value>
      </managed-property>
      <managed-property>
         <property-name>namespaceService</property-name>
         <value>#{NamespaceService}</value>
      </managed-property>
      <managed-property>
         <property-name>cifsServer</property-name>
         <value>#{cifsServer}</value>
      </managed-property>
      <managed-property>
         <property-name>ruleService</property-name>
         <value>#{RuleService}</value>
      </managed-property>
      <managed-property>
         <property-name>userPreferencesBean</property-name>
         <value>#{UserPreferencesBean}</value>
      </managed-property>
      <managed-property>
         <property-name>authenticationService</property-name>
         <value>#{AuthenticationService}</value>
      </managed-property>
        <managed-property>
            <property-name>permissionService</property-name>
            <value>#{PermissionService}</value>
        </managed-property>
   </managed-bean>
See details on http://wiki.alfresco.com/wiki/Packaging_And_Deploying_Extensions
Hope it heps,

Denis

mesa2e
Champ in-the-making
Champ in-the-making
Hi Denis, Thanks for your response.
I'm try it, and i got the following errors:

javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/login.jsp][Class: javax.faces.component.html.HtmlForm,Id: loginForm][Class: javax.faces.component.html.HtmlInputText,Id: user-name]}
caused by:
org.apache.jasper.JasperException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/login.jsp][Class: javax.faces.component.html.HtmlForm,Id: loginForm][Class: javax.faces.component.html.HtmlInputText,Id: user-name]}
caused by:
javax.faces.FacesException: Could not retrieve value of component with path : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/login.jsp][Class: javax.faces.component.html.HtmlForm,Id: loginForm][Class: javax.faces.component.html.HtmlInputText,Id: user-name]}
caused by:
javax.faces.el.EvaluationException: Cannot get value for expression '#{LoginBean.username}'
caused by:
javax.faces.el.EvaluationException: Cannot get value for expression '#{NavigationBean}'
caused by:
javax.faces.FacesException: java.lang.ClassNotFoundException: org.web.bean.MyNavigationBean
caused by:
java.lang.ClassNotFoundException: org.web.bean.MyNavigationBean

Do I have to include the .class in the original .jar?

Thanks in advance,
Elena.

dgenard
Champ on-the-rise
Champ on-the-rise
Your class (org.web.bean.MyNavigationBean) is not found.
The cleanest solution is to create your own jar and place it in a location where it will be found by the tomcat classloader (typically WEB-INF/lib).

Denis

mesa2e
Champ in-the-making
Champ in-the-making
Denis,

I had a mistake in the class package. I set the correct one, but now I get errors when I restart tomcat:

11:07:49,077 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco]] Excepción enviando evento inicializado de contexto a instancia de escuchador de clase org.alfresco.web.app.ContextListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [alfresco/core-services-context.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
Caused by:
java.io.IOException: Cannot bind to URL [rmi://localhost:50500/alfresco/jmxrmi]: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
   at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:814)
   at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:431)
   at org.springframework.jmx.support.ConnectorServerFactoryBean.afterPropertiesSet(ConnectorServerFactoryBean.java:168)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1118)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1085)
   at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:429)
   at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:250)
   at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:141)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:247)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:161)
   at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:270)
   at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:346)
   at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:156)
   at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:246)
   at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:184)
   at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:49)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3764)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4216)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:544)
   at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:825)
   at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:714)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:490)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:736)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
   at org.apache.catalina.core.StandardService.start(StandardService.java:448)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:700)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:295)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:433)
Caused by: javax.naming.NameAlreadyBoundException: alfresco/jmxrmi [Root exception is java.rmi.AlreadyBoundException: alfresco/jmxrmi]
   at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:118)
   at com.sun.jndi.toolkit.url.GenericURLContext.bind(GenericURLContext.java:208)
   at javax.naming.InitialContext.bind(InitialContext.java:359)
   at javax.management.remote.rmi.RMIConnectorServer.bind(RMIConnectorServer.java:635)
   at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:427)
   … 38 more
Caused by: java.rmi.AlreadyBoundException: alfresco/jmxrmi
   at sun.rmi.registry.RegistryImpl.bind(RegistryImpl.java:123)
   at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source)
   at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:375)
   at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:240)
   at sun.rmi.transport.Transport$1.run(Transport.java:153)
   at java.security.AccessController.doPrivileged(Native Method)
   at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
   at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:466)
   at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:707)
   at java.lang.Thread.run(Thread.java:595)
   at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
   at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
   at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:343)
   at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source)
   at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:116)
   … 42 more

dgenard
Champ on-the-rise
Champ on-the-rise
Looks like a previous Alfresco process was not fully terminated.
To be sure, try rebooting your machine…

Denis

mesa2e
Champ in-the-making
Champ in-the-making
It works!!!!

Thanks Denis, I really appreciate your help!!

Other question I have related with it would be…

What would I have to include in faces-config-custom.xml if I have to extend methods like:
UINavigator or PageTag? How can I know that?

Thanks a lot,
Elena.