RichFaces server-side paging with DataTable.

Most of the component toolkits have build in support for server-side paging this days but in rest of the cases you need to customize a little the data model or data provider or component itself to have data paging. The reason why I write this post is because when I first saw richfaces everythink was perfect except the server-side paging. They have paging but it was client side based on JavaScript witch just doesn't work in many cases and I loose a lot of time to understand all models, which model I must extend and how to do it to create a data model with server side paging. At the current version of RichFaces on the demo page information about how to do server-side paging at least exist http://livedemo.exadel.com/richfaces-demo/richfaces/dataTable.jsf?tab=dataModel&cid=3608154 but like always the JBoss/RedHat/Exadel doesn’t provide us a fast full easy working example and we must loose a lot of time to search for classes in the demo. The reason why I write this post is to give you simple application that uses server side paging and a little “directions” what you need to customize to have server side paging in all cases. If you have read my previous post about hibernate + spring + jsf + richfaces you will have very easy way to extend this simple demo and to make all Richfaces tables to have server-side paging instead of client-side javascript paging. So lets start. First what we want to create ? We want to create a serveri-side paging that looks like this : When you click on the pager at the bottom it will make ajax...

Hibernate Generic DAO.

When you use Hibernate and DAO pattern it is a good idea to use a Generic Base Dao. The fallowing code snippet contains GenericDAO that is a base class for all my DAO classes. This GenericDAO uses HibernateDaoSupport from Spring for its implementation if you want you can use JpaDaoSupport or JdbcDaoSupport in your projects. My Generic DAO interface looks like this : package org.joke.myproject.dao.base; import java.io.Serializable; import java.util.List; /** * @author Naiden Gochev * @param <E> * @param <PK> */ public interface GenericDao<E,PK  extends Serializable> {     PK save(E newInstance);     void update(E transientObject);     void saveOrUpdate(E transientObject);     void delete(E persistentObject);     E findById(PK id);     List<E> findAll();     List<E> findAllByProperty(String propertyName,Object value); } All method names are very common so I don't think they need some explanation. The implementation of this GenericDAO : package org.joke.myproject.dao.base;   import java.io.Serializable; import java.util.List; import org.hibernate.criterion.DetachedCriteria; import org.hibernate.criterion.Restrictions; import org.springframework.orm.hibernate3.support.HibernateDaoSupport; /** * @author JOKe * @param <E> * @param <PK> */ public abstract class GenericDaoImpl<E, PK extends Serializable> extends             HibernateDaoSupport implements GenericDao<E, PK> {       @SuppressWarnings("unchecked")       public PK save(E newInstance) {             return (PK) getHibernateTemplate().save(newInstance);       }       @SuppressWarnings("unchecked")       public E findById(PK id) {             return (E) getHibernateTemplate().get(getEntityClass(), id);       }       @SuppressWarnings("unchecked")       public List<E> findAll() {             return getHibernateTemplate().findByCriteria(createDetachedCriteria());       }       @SuppressWarnings("unchecked")       public List<E> findAllByProperty(String propertyName, Object value) {             DetachedCriteria criteria = createDetachedCriteria();             criteria.add(Restrictions.eq(propertyName, value));             return getHibernateTemplate().findByCriteria(criteria);       }       public List<E> findByExample(E object) {             List<E> resultList = getHibernateTemplate().findByExample(object, 0, 1);             return resultList;       }       public List<E> findByExample(E object, int firstResult, int maxResults) {             List<E> resultList...

JSF, RichFaces, Spring, Hibernate – lets make development easy.

The goal of this article is to show you how you can use Hibernate, Spring and JSF 1.2 in the most easiest way. Used technologies : maven 2 JSF 1.2 (MyFaces) Spring 2.5.6 Hibernate 3.2.1.GA In the example I will use mysql just for the configuration. You can use whatever you want. The goal that we want is to use Spring for management of transactions and as IoC container. The beast way for us is to make everything spring beans. In typical application we will have Services, DAOs, Entity objects and JSF managed beans. We will make all of them spring beans and use @Autowired annotation (included in Spring). We will use GenericDAO implementation which is explained in this article: http://gochev.blogspot.com/2009/08/hibernate-generic-dao.html. First lets create a maven 2 project and add replace update it’s pom.xml to looks like this, note that the pom is big we will explain important sections after the whole content. <?xml version="1.0" encoding="UTF-8"?>   <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">       <modelVersion>4.0.0</modelVersion>       <groupId>myproject-web</groupId>       <artifactId>myproject-web</artifactId>       <packaging>war</packaging>       <version>0.0.1-SNAPSHOT</version>       <name>A custom project using myfaces</name>       <url>http://www.myorganization.org</url>         <build>             <finalName>myproject-web</finalName>             <plugins>                   <plugin>                         <!--This plugin allows to run the example using mvn jetty:run -->                         <groupId>org.mortbay.jetty</groupId>                         <artifactId>maven-jetty-plugin</artifactId>                         <version>6.1.8</version>                         <configuration>                              <scanIntervalSeconds>10</scanIntervalSeconds>                         </configuration>                   </plugin>                   <plugin>                         <artifactId>maven-compiler-plugin</artifactId>                         <configuration>                               <source>1.5</source>                               <target>1.5</target>                         </configuration>                   </plugin>                     <plugin>                         <artifactId>maven-eclipse-plugin</artifactId>                         <configuration>                               <wtpversion>2.0</wtpversion>                              <wtpapplicationxml>true</wtpapplicationxml>                               <wtpmanifest>true</wtpmanifest>                               <downloadSources>true</downloadSources>                               <downloadJavadocs>true</downloadJavadocs>                           <manifest>${basedir}/src/main/resources/META-INF/MANIFEST.MF</manifest>                         </configuration>                     </plugin>             </plugins>       </build>       <repositories>             <repository>                   <releases>                         <enabled>false</enabled>                   </releases>                  ...

Code Formater at Google App Engine

Check this out : http://xzfv.appspot.com/s/about.html you can use it to format your source code before paste it in the blog. Just copy your code, submit and copy the result Example :package org.joke.ui;import java.net.URL;import org.eclipse.e4.xwt.XWT;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;public class Hello extends Composite { public Hello(Composite parent, int style) { super(parent, style); } /** * @param event */ public void onSelectionEvent(Event event) { MessageDialog.openInformation(getShell(), "test", "Hello"); } public static void main(String[] args) throws Exception { URL url = Hello.class.getResource("Hello.xwt");// Shell shell = XWT.load(url).getShell();// shell.pack();// shell.open();// while (!shell.isDisposed()) {// if (!shell.getDisplay().readAndDispatch()) {// shell.getDisplay().sleep();// }// } try { XWT.open(url); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }}Check this out : http://xzfv.appspot.com/s/about.html you can use it to format your source code before paste it in the blog. Just copy your code, submit and copy the result Example :package org.joke.ui;import java.net.URL;import org.eclipse.e4.xwt.XWT;import org.eclipse.jface.dialogs.MessageDialog;import org.eclipse.swt.widgets.Composite;import org.eclipse.swt.widgets.Event;public class Hello extends Composite { public Hello(Composite parent, int style) { super(parent, style); } /** * @param event */ public void onSelectionEvent(Event event) { MessageDialog.openInformation(getShell(), "test", "Hello"); } public static void main(String[] args) throws Exception { URL url = Hello.class.getResource("Hello.xwt");// Shell shell = XWT.load(url).getShell();// shell.pack();// shell.open();// while (!shell.isDisposed()) {// if (!shell.getDisplay().readAndDispatch()) {// shell.getDisplay().sleep();// }// } try { XWT.open(url); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); }...