Get your CodeRanch badge!*
The moose likes JSF and the fly likes JSF + Tiles = no navigation-rules Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSF
Bookmark "JSF + Tiles = no navigation-rules" Watch "JSF + Tiles = no navigation-rules" New topic
Author

JSF + Tiles = no navigation-rules

Matthew Snow
Ranch Hand

Joined: May 02, 2007
Posts: 80
I've added Tiles to my facelets application and now my navigation-rules don't work. When I click on any of my links, it just reload the current page. I've tried changing the <from-view-id> from the templated jsf page to the page including the templates and still nothing. I'm including these templates using http://java.sun.com/jsf/facelets:composition and include tags (not both on the same page). Here is a sample template page with links and my faces-conig.xml and parts of the web.xml.

header.xhtml -------------------------------------------
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:c="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html">

<h:panelGrid columns="2" columnClasses="mainColumn, logoutColumn">
<h:form style="margin:0">
<h:commandLink action="main">
<hutputText value="Main" />
</h:commandLink>
</h:form>

<h:form style="margin:0">
<h:commandLink action="logout">
<hutputText value="Logout"/>
</h:commandLink>
</h:form>
</h:panelGrid>
</html>

faces-config.xml ------------------------------------
<?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>
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
<variable-resolver>org.springframework.web.jsf.DelegatingVariableResolver</variable-resolver>
<locale-config />
</application>

<navigation-rule>
<from-view-id>/layout/header.jsf</from-view-id>
<navigation-case>
<from-outcome>main</from-outcome>
<to-view-id>/pages/index.jsf</to-view-id>
</navigation-case>
<navigation-case>
<from-outcome>logout</from-outcome>
<to-view-id>/security/login.jsf</to-view-id>
<redirect />
</navigation-case>
</navigation-rule>
</faces-config>

web.xml ---------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<context-param>
<param-name>facelets.SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>

<listener>
<listener-class>com.sun.faces.config.ConfigureListener</listener-class>
</listener>

<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>

<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>

<context-param>
<param-name>com.sun.faces.compressViewState</param-name>
<param-value>true</param-value>
</context-param>

<filter>
<filter-name>MyFacesExtensionsFilter</filter-name>
<filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
<init-param>
<param-name>uploadMaxFileSize</param-name>
<param-value>100m</param-value>
</init-param>
<init-param>
<param-name>uploadThresholdSize</param-name>
<param-value>100k</param-value>
</init-param>
</filter>

<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>*.jsf</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
</web-app>


When you break the big rules, you get a lot of little rules.
Matthew Snow
Ranch Hand

Joined: May 02, 2007
Posts: 80
Solution:

First, in my faces-config.xml, I have the template header.jsf as my from-view-id, I need to change this to reflect the page in the actual url used to navigate to this page (in this case, my index.xhtml page).

Second, according to my current configuration, in the from-view-id I need to use the .xhtml extension, which is what I'm using for my jsf pages (I can still use the .jsf in the to-view-id though).

Third, in my web.xml I have the filter
<filter-mapping>
<filter-name>MyFacesExtensionsFilter</filter-name>
<url-pattern>/faces/*</url-pattern>
</filter-mapping>
which is looking in the folder /faces for patterns, not /layout, so I opted to change my folder name to faces and the from-view-id to /faces/index.xhtml.

Fourth, since this header.xhtml will appear on each page and the from-outcome's main and logout are never used elsewhere, I can just set these naviations as global by removing the from-view-id line all together in the faces-config.xml.

Oh, and for all you facelets out there, it's called 'Templating', not Tiles, *noob!*
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Can you please tell me, what mean Tiles???
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JSF + Tiles = no navigation-rules
 
Similar Threads
Error while accessing hibernate session through JSF
Field display problem
Acegi Configuration
Error: Target Unreachable, identifier 'StoreNameBean' resolved to null
Navigation issue