Thursday, January 19, 2012

One or more resources have the target of 'head', but no 'head' component has been defined within the view.

This error comes due to wrong namespace reference to your header tag. In JSF all html tags are used with prefix <h:YOU_HTML_TEG>

Your template before error

BasicTemplate.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">


<f:view>

<head>

<link href="css/default.css" rel="stylesheet" type="text/css" />
<title><ui:insert name="title">FREE ENGLISH WORDS</ui:insert></title>

</head>


<body>

<div id="header">
<ui:insert name="header">
<!-- include your header file or uncomment the include below and create header.xhtml in this directory -->
<ui:include src="./SALHeader.xhtml"/>
</ui:insert>
</div>


<div id="content">
<ui:insert name="content">
Content area. See comments below this line in the source.
<!-- include your content file or uncomment the include below and create content.xhtml in this directory -->
<!-- <div> -->
<!-- <ui:include src="content.xhtml"/> -->
<!-- </div> -->
</ui:insert>
</div>

<div id="footer">
<ui:insert name="footer">
<!-- include your header file or uncomment the include below and create footer.xhtml in this directory -->
<ui:include src="./SALFooter.xhtml"/>
</ui:insert>
</div>

</body>
</f:view>
</html>




After Error Removed

BasicTemplate.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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich">


<f:view>

<h:head>

<link href="css/default.css" rel="stylesheet" type="text/css" />
<title><ui:insert name="title">FREE ENGLISH WORDS</ui:insert></title>

</h:head>


<body>

<div id="header">
<ui:insert name="header">
<!-- include your header file or uncomment the include below and create header.xhtml in this directory -->
<ui:include src="./SALHeader.xhtml"/>
</ui:insert>
</div>


<div id="content">
<ui:insert name="content">
Content area. See comments below this line in the source.
<!-- include your content file or uncomment the include below and create content.xhtml in this directory -->
<!-- <div> -->
<!-- <ui:include src="content.xhtml"/> -->
<!-- </div> -->
</ui:insert>
</div>

<div id="footer">
<ui:insert name="footer">
<!-- include your header file or uncomment the include below and create footer.xhtml in this directory -->
<ui:include src="./SALFooter.xhtml"/>
</ui:insert>
</div>

</body>
</f:view>
</html>

Wednesday, January 18, 2012

Hibernet - Partial Loading of entity ,

May be for optimization of JVM memory we need partial loaded object with only specified fields with values from DB .
Without using projection you can get such partially loaded by using transformer .
But I think following code is elegant example ..


1. DB TABLE

USER_TABLE , DB Table >>

columns

USER_ID (INT(10))
USER_NAME(VARCHAR(50))


2. MODEL CLASS

User.java - Model Class

 Public class User{
private int userId;
private String userName ;
..
..
..
AND MANY OTHER PROPERTIES
// Getters and Setters for id and name and for other props
}


3. Hibernet settings

In hibernet config xml



 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.salpe.dao.model.User"
lazy="false" table="USER_TABLE" >
<id name="userId" column="USER_ID"/>
<property name="userName" column="USER_NAME" />
---
------
----
<!--MANY OTHER PROPERTIES -->
</class>
</hibernate-mapping>

4. DAO class

SessionFactoryUtil >> Way to get hibernet session 
 Public class UserDaoImpl {
public static List<User> getPariallyLoadedUsers(int userId){
Criteria crit = SessionFactoryUtil.getInstance().getCurrentSession()
.createCriteria(User.class);
ProjectionList usrList = Projections.projectionList();
// Laoding only user id and user name and Other properties as Null or default 0 ;
proList.add(Projections.property("userId"),"userId");
proList.add(Projections.property("userName"),"userName");
crit.setProjection(usrList);
crit.add(Restrictions.eq("userId",Integer.toString(projectId)));
crit.setResultTransformer(
Transformers.aliasToBean(User.class));
List<User> list = crit.list();
return list;
}

NOTE : FOR DB OPTIMIZATION IS BETTER TO OPTIMIZE ON NUMBER OF ROWS QUERY IS FETCHING RATHER THAN ON NUMBER OF FIELDS/COLUMNS.But I am giving this as just example .