Monday, May 31, 2010

Hello world in JSF 2.0

XHTML is clean format html which follows strict rules for styles of tags .
Use of expression language in EL eases to keep code neat and clean .
JSF libraries support used of EL with xhtml .

In JSF 2.0 , it’s recommended to create JSF page in XHTML file format.
I am giving example of a web.xml with JSF and rich faces (Jboss components )

web.xml

 <?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>JavaServerFaces</display-name>
<!-- Change to "Production" when you are ready to deploy -->
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<!-- Welcome page -->
<welcome-file-list>
<welcome-file>faces/hello.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF mapping -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map these files with JSF -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.faces</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
</web-app>


Navigation of pages need to be configured in a xml called faces-config.xml.
In JSF 2.0 you can manage bean in code using annotation
Still to control page flow this xml should be used .

example

 <?xml version='1.0' encoding='UTF-8'?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee" version="1.2" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd" xi="http://www.w3.org/2001/XInclude">
<application>
<view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
---
managed beans
--
navigation rules
---
</faces-config>

Thursday, May 13, 2010

Rename table name in SQL

RENAME TABLE TABLEA TO TABLEB

Sunday, May 9, 2010

SQL table change order of column if we have already populated table

Example if table TAB has c1 - int(11) , c2 - varchar(40) , c3 - varchar (40)

/ -------- Table name - TAB ---------- ---/
--------------------------------------------------------
C1 INT (11) l C2 VARCHAR (11) l C3 VARCHAR (11)
--------------------------------------------------------

But now we want order C1, C2, C3 as C1,C3,C2 ... ofcourse you may go to views without changing physical data table . But if we want change in physical data table then ??

sample querry -

ALTER TABLE TAB MODIFY COLUMN C2 varchar(60) AFTER C3


ALTER TABLE TABLE_NAME MODIFY COLUMN COLUMN_NAME_TO_BE SHIFTED DATA_TYPE_OF_THE_COLUMN AFTER COLUMN_NAME

** Replace red colored fields with real values of your table
AFTER Querry


/ -------- Table name - TAB ---------- ---/
--------------------------------------------------------
C1 INT (11) l C3 VARCHAR (11) l C2 VARCHAR (11)
--------------------------------------------------------