Icefaces Facelets to get a template effect

31 03 2008

I am planning to make it dynamic, but haven’t yet done the hands on.

Preparation:

include icefaces-facelets.jar

and put the following into web.xml

<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.jspx</param-value>
</context-param>

This tells JSF to assume a prefix of jspx, which the Facelet’s rendered can interpret. Facelets can use many other parameters depending on your application.

put the following into faces-config.xml

<application>
<view-handler>com.icesoft.faces.facelets.D2DFaceletViewHandler

</view-handler>

</application>

tell JSF about the Facelets view handler. This is a plug-in that handles the Render Response and Restore View phases of the JSF request-processing life cycle.

Template Idea

And then comes the confusing part, I can’t understand this after reading the document twice. I have to jump into the source and do some hands on to figure this out. I think I have a better way to present it. This may be my wrong intepretation.

You need three things.

1. a jsp that load the template

2. a jspx which is the template

3. some jspx which are components you put inside the template.

1. load template

  • <ui:composition> - This is a templating tag that wraps content to be included in another facelet. Any content outside the composition tag will be ignored by the Facelets view handler.
  • <ui:define> - This tag is a templating tag that defines named content to be inserted into a template.

example:

            <ui:composition template="mainTemplate.jspx">
<ui:define name="faceletHeader">
<meta http-equiv="Content-Type"
content="text/html; charset=utf-8"></meta>
<title>
<ice:outputText value="Facelet Dynamic Include Tutorial"/>
</title>
<link href="./xmlhttp/css/xp/xp.css" rel="stylesheet" type="text/css"/>
</ui:define>
</ui:composition>

2. The template

  • <ui:insert>- A templating tag that declares a named content element to be defined by another Facelet. Used effectively with the ui:define tag.
  • <ui:include>- A server-side include tag for Facelets. It simply includes the document pointed to by the “src” attribute as part of the current JSF page.

example:

<ui:insert name="content">
<ui:include src="./content-facelet.jspx" />
</ui:insert>

3. Contents

just icefaces jspx that you normally write.

Conclusion:

The confusing part is when you load the template, you will have two way to actually put content inside <ui:insert>.

1. use <ui:define> inside “template load” to put content directly into it.

2. use <ui:include> inside “template” to reference a jspx.

And if I am not getting it wrong, any content inside <ui:insert> which is not <ui:include> will be replace by <ui:define> stuff.

I will update this post when I get the dynamic reference content work.

Have fun~





Open Source License Research

30 03 2008

因為使用open source的比例越來越重

也是時候研究一下他們的license

不過那些條款實在太難懂了

先記下來以後再慢慢看

Apache License, Version 2.0

GNU General Public License version 3 (GPLv3)

The GNU Lesser General Public License (LGPLv3)

Mozilla Public License 1.1 (MPL 1.1) :Licensing

Common Development and Distribution License (CDDL)

Common Public License Version 1.0 (CPL)

最好是有研究過的人跟我講是有甚麼分別啦~ :P





Centering horizontally with CSS

30 03 2008

Try to center a web page like wordpress blog with css.

center01

add this to you main container inside <body>

usually a <form> with this css properties.

.maxiForm{

  margin-left : auto ;

  margin-right : auto ;

  width : 700px ;

  height : 100% ;

  text-align : left;

}

width means the width of the content you want to show.

text-align : left I am going to explain it.

with this setting you can see the aligning is working in FF.

center02

But IE6 will fail because it ignores margin-left and margin-right.

We need to get around this by adding this CSS property.

body
{
text-align: center;
}

This will going to cause you trouble since all the things inside <body> is

now centered! That’s why we set text-align : left previously.

center03

I play this with Icefaces and Tomcat.

Your page should look alright now.





Netbeans project with UTF-8

29 03 2008

基本上,NetBeans預設的file encoding是系統語系,所以在繁中版Windows是MS950,遇到”堃”、”綉”等字時會發生錯誤。鳥毅這幾年都用UTF-8編碼,必須手動改 Tools->Options->Advanced Options->Editing->Java Sources->Default EncodingUTF-8。但這樣編譯時會錯,因此還得改Project的Properties->Build->Compiling->Additional Compiler Options加上 -encoding UTF-8

來源鳥毅的Blog





Icefaces Application on Tomcat 6 using Netbeans

29 03 2008

Similar to the portlet development but simpler.

download latest icefaces 1.7 RC1

pack these in library manager as Icefaces 1.7 library

backport-util-concurrent.jar

commons-beanutils.jar

commons-digester.jar

commons-discovery.jar

commons-fileupload.jar

commons-logging.jar

icefaces.jar

icefaces-comps.jar

Create a web application project and use JavaServerFace framework.

include Icefaces 1.7 library that we create.

Add these to your web.xml

   <servlet>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <servlet-class>
            com.icesoft.faces.webapp.xmlhttp.PersistentFacesServlet
        </servlet-class>
        <load-on-startup> 1 </load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Blocking Servlet</servlet-name>
        <servlet-class>com.icesoft.faces.webapp.xmlhttp.BlockingServlet</servlet-class>
        <load-on-startup> 1 </load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>*.iface</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Persistent Faces Servlet</servlet-name>
        <url-pattern>/xmlhttp/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Blocking Servlet</servlet-name>
        <url-pattern>/block/*</url-pattern>
    </servlet-mapping>

Add a jspx to you project, if you put that under Web pages/jspx/foo.jspx

You will need to use it by http://localhost:8080/projectName/jspx/foo.iface

you are all set.

Enjoy!





Java AS, Container的體驗

29 03 2008

早前因為研究portlet用到Jboss AS, Portal.

但他的startup超慢,因為要處理很多東西和支持EJB3吧

但如果自己玩開發,聽VP的Angus說,他們只用Tomcat,20秒不到就reboot完了.

我自己又還沒用到EJB,只是用來玩,那就想試一下Tomcat,以後要用web service再來弄JBoss AS吧.

一用之下發現Tomcat真的爽很多,幾秒就能讓用start起來試你的web app了 .





Develop JSF1.2 with Netbeans 5.5.1 running on Tomcat 6 with Mysql backend

29 03 2008

My Environment

JSF 1.2

Netbeans 5.5.1

Tomcat 6

Mysql 5

Prepare Tomcat 6

Download and unpack Tomcat 6.

Run: [tomcat6]\bin\startup.bat in windows

Shutdowm: [tomcat6]\bin\shutdown.bat in windows

Change port: [tomcat6]\apache-tomcat-6.0.16\conf\server.xml

Add user: [tomcat6]\apache-tomcat-6.0.16\conf\tomcat-user.xml

<role rolename="manager"/> <user username="tomcat" password="s3cret" roles="manager"/>

Open server manager in Netbeans-> Add Server, choose Tomcat 5.5(I don’t see Tomcat 6 and don’t know how to add it). Catalina Home means where you unpack Tomcat 6. username/password is the manager username/password we set previously.

You can run and deploy project using Tomcat 6 by now.

Prepare Mysql

Download and run it as a service from Mysq which will be trivial to teach.

Copy JDB-connecter for Mysql under [tomcat6]\lib

Add the following setting in your context

<Context path="/DBTest" docBase="DBTest"
debug="5" reloadable="true" crossContext="true">
<Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="root" password="root" driverClassName="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/javatest?autoReconnect=true"
removeAbandoned="true" emoveAbandonedTimeout="60"/>
</Context>

Context for tomcat 6 can be in the following ways!

  • in the $CATALINA_HOME/conf/context.xml file: the Context element information will be loaded by all webapps
  • in the $CATALINA_HOME/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host
  • in individual files (with a “.xml” extension) in the $CATALINA_HOME/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. context#path.xml. The default web application may be defined by using a file called ROOT.xml.
  • if the previous file was not found for this application, in an individual file at /META-INF/context.xml inside the application files
  • inside a Host element in the main conf/server.xml

I prefer the /META-INF/context.xml in your project under <web-app>

Put this in your web.xml in your project:

<description>MySQL Test App</description>
 <resource-ref> 
<description>DB Connection</description> 
<res-ref-name>jdbc/TestDB</res-ref-name>       
<res-type>javax.sql.DataSource</res-type> 
<res-auth>Container</res-auth>   
</resource-ref>

***注意:如果你在Netbeans5.5裡面run你的project會有問題,因為netbeans5.5自動include mysql connector,會跟[tomcat 6]\lib裡面的相沖

You are now ready to use Myql in your project.

Prepare JSF

JSF1.2 need Servlet 2.5 and JSP 2.1 which tomcat 6 can provide.

Download JSF and JSTL

Create Web project and Add JSF framework in project properties.

This is the same as doing JSF setting in web.xml, netbeans user don’t need to do this by hand.

<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>
javax.faces.webapp.FacesServlet
</servlet-class>
<load-on-startup> 1 </load-on-startup>
</servlet>

<!-- Faces Servlet Mapping -->
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.jsf</url-pattern>
</servlet-mapping>

Add JSF managed bean by right clicking in project navigator.

Which will automatically add setting in faces-config.xml by Netbeans,

you can do it yourself by adding the following in faces-config.xml:

<managed-bean>
<managed-bean-name>ManagedBean</managed-bean-name>
<managed-bean-class>maxi.fun.ManagedBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

Replace library with those we download previously : jsf-api.jar and jsf-impl.jar for JSF ;standard.jar and jstl.jar for JSTL

JSF file can be .jsf or .jsp, I don’t know how to create .jsf. so I just use .jsp instead.

You are all set. Have Fun





NetBeans Hot Key

29 03 2008

NetBeans 常用 Hot-Key:
Ctrl + Shift + F
: Reformat Code (與 eclipse 一樣)
Alt + Shift + F : Fix Imports
Alt + Shift + W : Surround With try-catch
Alt + O : Go to Source
Alt + F7 : Find Usages
Ctrl + F : Find
Ctrl + H : Replace
Ctrl + Shift + T : Comment
Ctrl + Shift + D : Uncomment
Ctrl + \ : Code Completion





This one is for Mr. 馬

29 03 2008

我希望下一屆也是Mr馬

為甚麼呢?
因為過去八年
阿扁已把台灣搞出一個爛攤子
負債十三兆 那可不是普通的爛攤子
如果阿扁也可以當兩屆
我想負責收拾爛攤子的人
也有八年時間不為過吧
不過我想這四年如果做得還不算太差
下一屆也大概沒問題
加油 Mr馬




Develop Java GUI Application with Netbeans

29 03 2008