Posts Tagged ‘sorting

20
Dec
09

column sorting using JSF and Tomahawk

This page describes the process of sorting results generated by a JSF based application.

Installation

		<dependency>
			<groupId>org.apache.myfaces.tomahawk</groupId>
			<artifactId>tomahawk</artifactId>
			<version>1.1.9</version>
		</dependency>  

Configuration

Not 100% sure if the following is needed in web.xml or not. Just here for reference.

<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>20m</param-value>
        <description>Set the size limit for uploaded files.
            Format: 10 - 10 bytes
                    10k - 10 KB
                    10m - 10 MB
                    1g - 1 GB
        </description>
    </init-param>
</filter>

<!-- extension mapping for adding <script/>, <link/>, and other resource tags to JSF-pages  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <!-- servlet-name must match the name of your javax.faces.webapp.FacesServlet entry -->
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>

<!-- extension mapping for serving page-independent resources (javascript, stylesheets, images, etc.)  -->
<filter-mapping>
    <filter-name>MyFacesExtensionsFilter</filter-name>
    <url-pattern>/faces/myFacesExtensionResource/*</url-pattern>
</filter-mapping>

Programming the JSP

Ensure that you have the following taglib in each JSP.

<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>

Example Page

Notice in the following example the h: tags are converted to t: tomahawk tags. Also observe the highlighted lines below.

<%@ taglib prefix="f" uri="http://java.sun.com/jsf/core" %>
<%@ taglib prefix="h" uri="http://java.sun.com/jsf/html" %>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"  %>
<%@ taglib uri="http://myfaces.apache.org/tomahawk" prefix="t" %>

<f:subview id="genre_tile">

    <h3>Genre Table</h3>

    <h:form>
    <p>
    	<t:dataTable styleClass="data_table" value="#{genreBean.allGenre}" var="genre">
    		<t:column sortable="true">
    		    <f:facet name="header">
		        	<h:outputText value="id" />
        		</f:facet> 
    			<h:outputText value="#{genre.id}"/>
    		</t:column>
    		<t:column sortable="true">
    		    <f:facet name="header">
		        	<h:outputText value="Name" />
        		</f:facet> 
    			<t:outputText value="#{genre.name}"/>
    		</t:column>
    	</t:dataTable>
		<h:commandButton value="Submit" action="#{genreBean.process}"/>
    </h:form>    	
    </p>
</f:subview>



Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 75 other followers

May 2017
S M T W T F S
« Mar    
 123456
78910111213
14151617181920
21222324252627
28293031  

Blog Stats

  • 813,774 hits