Query Example

Hibernate Query Example In this simple query I’ll bring active clubs and memberships. In the query we use object names, not the names seen in the persistence unit SQL Query SELECT c.name as clubname, c.legacyId as clublegacyId, c.clubCity as clubcity, c.isclubactive as clubactive, m.id as membershipId , m.type as membershiptype, m.legacy_id as membershiplegacyid, m.ismembershipactive as

One to Many relationship in a separated table

The Entites Club: one to many Facility: many to one in this example the relation will be held in a separated table, ClubTable.java @Entity @Table(name = "club_table") public class ClubTable { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id") private Long id; @Column(name = "name", nullable = false) private String name; @Column(name = "latitude") private String

JSF Multiple EL String concatenation

Today I’ve come to experience an usual situation which did result me to concatenate two strings values exceptionally derived from different EL sources. One is derived from database/controller the other is the messages/language sources. As you apprehend the situation from the below screenshot, Annual and Monthly values which pointed in the red color are fetched

Enabling auto reconnect in mysql hibernate spring

in your spring config file append the url entry with the below sample   <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${database.driverClassName}" /> <property name="url" value="${database.url}?characterEncoding=UTF-8&amp;autoReconnect=true"/> <property name="username" value="${database.user}" /> <property name="password" value="${database.password}" /> </bean>

Loading CSS JS Resources in JSF

  <?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:h=”http://java.sun.com/jsf/html” xmlns:ui=”http://java.sun.com/jsf/facelets”> <h:head> <h:outputStylesheet name=”basetemplate.css” library=”css”/> <h:outputStylesheet name=”shCore.css” library=”css”/> <h:outputStylesheet name=”shThemeDefault.css” library=”css”/> <h:outputScript name=”shCore.js” library=”js”/> <h:outputScript name=”shBrushXml.js” library=”js”/> <h:outputScript name=”shBrushJScript.js” library=”js”/> </h:head>  

Catching Primefaces form elements in jquery and preventing copy paste and cut operations

xhtml <p:inputText id="firstName" placeholder="#{msg.member_name}" value="#{memberController.order.firstName}" size="30" maxlength="30" widgetVar="firstNameVar" required="true" styleClass="#{not component.valid ? 'ui-input-invalid default-input-text' : 'default-input-text'}" onkeypress="return disallowNonAlphabethCharacters(event);"> <p:ajax delay="1000" event="keyup" oncomplete="rc([{name: 'component', value: ':primeForm:firstName'}, {name: 'widget', value: 'firstNameVar'}]);" /> </p:inputText> javascript <script type="text/javascript"> $( document ).ready(function() { PF('firstNameVar').jq.bind('cut copy paste', function(e) { e.preventDefault(); }); PF('firstNameVar').jq.bind("contextmenu", function(e) { e.preventDefault(); }); }); </script>

Disabling non alphabet characters while entering the input

<p:inputText id="firstName" placeholder="#{msg.member_name}" value="#{memberController.order.firstName}" size="30" maxlength="30" widgetVar="firstNameVar" required="true" styleClass="#{not component.valid ? 'ui-input-invalid default-input-text' : 'default-input-text'}" onkeypress="return disallowNonAlphabethCharacters(event);"> <p:ajax delay="1000" event="keyup" oncomplete="rc([{name: 'component', value: ':primeForm:firstName'}, {name: 'widget', value: 'firstNameVar'}]);" /> </p:inputText>   Javascript <script language="javascript" type="text/javascript"> // <![CDATA[ function disallowNonAlphabethCharacters(e) { var charCode; if (window.event) charCode = window.event.keyCode; //for IE else charCode = e.charCode; //for firefox

Hibernate C3P0 pooling integration

hibernate.cfg.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!– Hibernate Settings –> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://10.10.100.106:3306/nuspa?autoReconnect=true</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">xxxx</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <property name="hibernate.current_session_context_class">thread</property> <property name="hibernate.hbm2ddl.auto">validate</property> <property name="show_sql">true</property> <!– C3P0 Pooling settings –> <property name="hibernate.c3p0.min_size">7</property> <property name="hibernate.c3p0.max_size">53</property> <property name="hibernate.c3p0.timeout">100</property> <property name="hibernate.c3p0.max_statements">50</property> <property name="hibernate.c3p0.idle_test_period">1000</property> <property name="hibernate.c3p0.validate">true</property> <!– Mapping Entity classes

JSTL Else if equivalence

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <html> <head> <title>JSTL test page</title> </head> <body> <c:choose> <c:when test="${order.statusDisplay == 'waitingForPayment' || order.statusDisplay == 'awaitingBankTransferApproval'}"> <c:set var="searchengine" scope="session" value="google" /> </c:when> <c:when test="${order.statusDisplay == 'created'}"> <c:set var="searchengine" scope="session" value="yahoo" /> </c:when> <c:otherwise> <c:set var="searchengine" scope="session" value="empty" /> </c:otherwise> </c:choose> <c:out value="${searchengine}" /> </body> </html>