cancel
Showing results for 
Search instead for 
Did you mean: 

Extending JSP pages

simon
Champ in-the-making
Champ in-the-making
Alfresco,

Another question on extending the Alfresco code. I can extend the beans by adding a new JAR file in the <extension> folder and changing the faces-config-beans.xml file, it's not perfect but we'll see what 1.3 brings us.

Now I would like to extend the login.jsp (I need to add a support link for our customers). I can just change the JSP code for this webpage and that does work but it's horribly wrong to edit a page directly.

How can I extend the JSP pages? Should I change / override some XML file? And if so, which one?

Thanks for the help!
7 REPLIES 7

simon
Champ in-the-making
Champ in-the-making
No thoughts on this?

gavinc
Champ in-the-making
Champ in-the-making
Hi,

You don't have to change faces-config-beans.xml, you can create a faces-config.xml file and place it in a META-INF folder in the JAR file you mention.

There are quite a few JSP pages that you can now override (or replace) via the dialog and wizard framework (see web-client-config-dialogs.xml and web-client-config-wizards.xml). These mechanism's also allow you to easily add new pages or remove pages from the wizards in the application.

However, login.jsp is one JSP file that is not part of a dialog or wizard so this is one of those pages that we have to handle specially. This is on our list to look at so hopefully there will be a customisation mechanism in place for this file in the 1.3 release.

gavinc
Champ in-the-making
Champ in-the-making
I should also mention that you can replace/override most JSPs in the application by overriding the navigation rule for that area of the application.

For example to make the "advSearch" outcome go to a different page you could replace the config below


<navigation-rule>
   <from-view-id>/jsp/*</from-view-id>
   <navigation-case>
      <from-outcome>advSearch</from-outcome>
      <to-view-id>/jsp/dialog/advanced-search.jsp</to-view-id>
   </navigation-case>
</navigation-rule>

with the following config in your custom faces-config.xml…


<navigation-rule>
   <from-view-id>/jsp/*</from-view-id>
   <navigation-case>
      <from-outcome>advSearch</from-outcome>
      <to-view-id>/jsp/custom/your-advanced-search.jsp</to-view-id>
   </navigation-case>
</navigation-rule>

simon
Champ in-the-making
Champ in-the-making
Thanks Gavin.

I tried to override the faces-config-beans.xml but can't get it to work.

1. Define a new faces-config.xml

I shouldn't copy all the contents form the faces-config-beans.xml, should I? I assume that only the relevant part is needed in this new faces-config.xml file. My faces-config.xml now looks like this (copy & paste from the faces-config-beans.xml, replaced the managed-bean-class and removed the other rules):

<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
                              "http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
   <!– ==================== MANAGED BEANS ==================== –>
   <managed-bean>
      <description>
         The bean that backs up the Login screen
      </description>
      <managed-bean-name>LoginBean</managed-bean-name>
      <managed-bean-class>be.company.access.LoginBean</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>authenticationService</property-name>
         <value>#{AuthenticationService}</value>
      </managed-property>
      <managed-property>
         <property-name>personService</property-name>
         <value>#{PersonService}</value>
      </managed-property>
      <managed-property>
         <property-name>navigator</property-name>
         <value>#{NavigationBean}</value>
      </managed-property>
      <managed-property>
         <property-name>browseBean</property-name>
         <value>#{BrowseBean}</value>
      </managed-property>
   </managed-bean>
</faces-config>

2. Bundle this file with the Java code in a JAR

company.jar

– META-INF
—- Manifest.mf
—- faces-config.xml
– be
—- company
—— access
——– LoginBean.class

3. Move the JAR & restart Alfresco

Move the JAR file to <tomcat>/webapps/alfresco/WEB-INF/lib/ and restart Alfresco. I tried to move it to the <tomcat>/shared/lib/ as well but this doesn't work as described in your reply.

Problems

- Everything works if I change the managed-bean-class in the Alfresco faces-config-beans.xml file but it seems that the faces-config.xml in my JAR is ignored. What do I do wrong here?

- Where should I place my JSP page in the JAR structure and which rules do I need to define in the faces-config.xml file? And how do I reference to the JSP file, can it stay inside the JAR file or should I copy it to some /jsp/custom type folder? I tried this last option and changed the navigation rules in my faces-config.xml file but it seems like this file isn't loaded at boot time.

gavinc
Champ in-the-making
Champ in-the-making
Hi Simon,

It looks like you have done everything correctly to me. Yes, you only need to put the relevant bits in the faces-config.xml file.

Do you find that your bean definition is not picked up? Is that the problem you are seeing? Have you tried defining a new bean and seeing if that gets picked up?

As a reference, FacesTrace (http://sourceforge.net/projects/facestrace) uses a similar technique to add their debug component into a JSF app.

Your JSP files will have to live outside the JAR file. The web containers expect to find them on the filesystem so your /jsp/custom/ approach is exactly what we would recommend in most cases.

What navigation rules are you looking at overriding?

simon
Champ in-the-making
Champ in-the-making
Thanks Gavin, almost there!

I found the reason why my JSP file didt show up. I noticed that it did show up when I logged off from the system but not when I needed to authenticate before accessing Alfresco. I forgot to change one navigation rule:
         <!– the login page the client will use –>
         <login-page>/jsp/login.jsp</login-page>
in the <tomcat>/webapps/alfresco/WEB-INF/classes/alfresco/web-client-config.xml file. How should I override this line? Can I add this in the faces-config.xml file in my JAR?

gavinc
Champ in-the-making
Champ in-the-making
Hi Simon,

Glad to hear you're close!

web-client-config.xml is one of our config files, those starting "faces-" are JSF config files. JSF config files can go into the JAR file but our "web-client-config-*" files can not currently (I was hoping to get this feature into 1.3 but due to time constraints it looks unlikely now).

However, for any of the web-client-config-* files you can use our config overriding mechanism so that you don't have to change ours.

Take a look at http://wiki.alfresco.com/wiki/Web_Client_Configuration_Guide for the steps on how to use web-client-config-custom.xml.

You could then add the following config to web-client-config-custom.xml


<config>
   <client>
      <login-page>/jsp/custom/your-login.jsp</login-page>
   </client>
</config>

Hope that all makes sense!