Some essential knowledge of Seam

Source: Internet
Author: User
Tags jboss

some essential knowledge of Seam

The seam framework itself is based on JSF and EJB3.0, so JSF and EJB3 are the things that must be understood, and for better use of JSF you need to understand facelets (JSF and JSP-related).

A JSF tutorial can refer to Sang Shin (sang.shin@sun.com) 's Java EE tutorial

http://www.javapassion.com/j2ee/

EJB3 and JPA can also refer to this tutorial:

http://www.javapassion.com/j2ee/

The only drawback of the above two tutorials is that they are written in English, but they are also good, authentic, but overly biased towards Sun (personal opinion).

Facelets can refer to the above IBM article: "Facelets very and is JSF"

http://www.ibm.com/developerworks/cn/java/j-facelets/

Development tools, I like to use idea, deploy and build dependent ant, and now I haven't studied how Maven uses seam.

But it's best that MAVEN can support seam and do a seam starter maven plugin that works like a Struts2 plug-in.

Facelets

facelets Configuration

We're here to talk about how to make applications that use the Facelets feature run in Jboss-4.2.2ga.

The facelets version is 1.1.14

Directory structure:

Facelets-number-guess

│guess.xhtml
│index.jsp
│response.xhtml
│template.xhtml

└─web-inf
│faces-config.xml
│web.xml

├─classes
│└─tutorial
│numberbean.class

└─lib
Jsf-facelets.jar

The files in the Lib library are copied from the C:/seam/facelets-1.1.13/lib directory, and you need to be aware of the following files:

El-api-1.0.jar
El-impl-1.0.jar
Jsf-api-1.2_04-p02.jar
Servlet-api-2.4.jar

The Web-inf/lib directory does not work under JBoss because JBoss has already provided the class library for these APIs, and when it is repeatedly discovered that JBoss cannot load the class libraries, there is an error.

The contents of the Web.xml are:

<?xml version= "1.0" encoding= "UTF-8"?>
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee
Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version= "2.5" >

<!--use Documents Saved as *.xhtml-->
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>

<!--Special Debug Output for Development-->
<context-param>
<param-name>facelets. Development</param-name>
<param-value>true</param-value>
</context-param>

    <!--Optional Jsf-ri Parameters to help Debug;
    <context-param
        <param-name>com.sun.faces.validatexml</param-name
        <param-value>true</param-value>
     </CONTEXT-PARAM>
    <context-param>
         <param-name>com.sun.faces.verifyobjects</param-name>
         <param-value>true</param-value>
    </context-param>

<!--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>
</web-app>


The contents of the bold section above are facelets configuration and will be used later.

The contents of the Faces-config.xml are:

<?xml version= ' 1.0 ' encoding= ' UTF-8 '?>

<! DOCTYPE Faces-config Public
"-//sun Microsystems, Inc.//dtd JavaServer Faces Config 1.0//en"
"Http://java.sun.com/dtd/web-facesconfig_1_0.dtd" >

<faces-config>

<application>
<view-handler>
Com.sun.facelets.FaceletViewHandler
</view-handler>
</application>

<!--Our numberbean we just created-->
<managed-bean>
<managed-bean-name>NumberBean</managed-bean-name>
<managed-bean-class>tutorial. Numberbean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
<managed-property>
<property-name>min</property-name>
<value>1</value>
</managed-property>
<managed-property>
<property-name>max</property-name>
<value>10</value>
</managed-property>
</managed-bean>


    <!--going from guess.xhtml to response.xhtml
    < Navigation-rule>
        <from-view-id>/guess.xhtml</ From-view-id>
        <navigation-case>
             <from-outcome>success</from-outcome>
             <to-view-id>/response.xhtml</to-view-id
        </navigation-case>
    </ Navigation-rule>

<!--going from response.xhtml to guess.xhtml-->
<navigation-rule>
<from-view-id>/response.xhtml</from-view-id>
<navigation-case>
<from-outcome>success</from-outcome>
<to-view-id>/guess.xhtml</to-view-id>
</navigation-case>
</navigation-rule>


</faces-config>

The contents of the bold section above are facelets configuration, the two parts of the configuration content together, can come to the following conclusions:

When a single user requests *.JSF content from the server, it is interpreted by the Facelets framework as the processing of *.xhtml, which completes the Facelets function in the process of interpretation.

facelets Template Features

A simple feature of facelets is similar to the functionality of tile templates, for example, We have two pages guess.xhtml and response.xhtml, we need to use a common layout, then we can set up a common framework template template.xhtml file.

Description: XHTML file as a subset of HTML file, must satisfy the XML specification, is a well-formed XML file

The contents of the template.xhtml file are:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
xmlns:ui= "http://java.sun.com/jsf/facelets">
<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 "/>
<title>facelets:number Guess tutorial</title>
<style type= "Text/css" >
<!--
Body {
Font-family:verdana, Arial, Helvetica, Sans-serif;
Font-size:small;
}
-->
</style>
<body>
<ui:insert name= "title" >default title</ui:insert>
<p>
<ui:insert name= "Body" >default body</ui:insert>
</p>
</body>

Some description of the content:

introduced the Facelets template label

Placeholders are defined and can then be replaced with dynamic content.

Contents of guess.xhtml File

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en"
"Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" >
Xmlns:ui= "Http://java.sun.com/jsf/facelets"
Xmlns:h= "Http://java.sun.com/jsf/html" >
<body>

This text above won't be displayed.

<ui:composition template= "/template.xhtml" >

This text won't be displayed.

<ui:define name= "title" >
I ' m thinking of a number from #{numberbean.min} to #{numberbean.max}. Can you guess it?
</ui:define>

This text would also not to be displayed.

<ui:define name= "Body" >
<br/>
<br/>
For= "Userno"/>
</ui:define>

This text won't be displayed.

</ui:composition>

This text below would also not to be displayed.

</body>

The above content is believed that everybody will be easy to understand, the xmlns part introduced the facelets tag and JSF's H type label, <ui:define name= "title" > ... Part and <ui:define name= "body" .... The two sections define the dynamic parts of the template.

It is also important to note that the contents of the bold section are not output.

response.xhtml File Contents:

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Xmlns:ui= "Http://java.sun.com/jsf/facelets"
Xmlns:h= "Http://java.sun.com/jsf/html" >
<body>

<ui:composition template= "/template.xhtml" >

<ui:define name= "title" >
#{numberbean.message}
</ui:define>

<ui:define name= "Body" >
<form jsfc= "H:form" >
<input jsfc= "H:commandbutton" type= "submit" id= "Back" value= "Back" action= "Success"/>
</form>

</ui:define>

</ui:composition>

</body>

facelets support for templates

Facelets can use HTML-formatted tags to process JSF tags, which makes it easy for designers to design, such as using tools such as Dreamwaver, and automatically handle data binding and event binding in a JSF label when implemented.

For example, the label content in the above response.xhtml:

<form jsfc= "H:form" >
<input jsfc= "H:commandbutton" type= "submit" id= "Back" value= "Back" action= "Success"/>
</form>

The above code will be translated into the following code when executed:

The JSFC attribute plays a symbolic role in the above process.

In addition, the use of Facelets also supports part of the JSTL label, although not comprehensive, but solves the problem of the lack of tags in JSF, facelets supported by the tag:

<c:if/>
<c:forEach/>
<c:catch/>
<c:set/>

The foreach tag solves the problem that there is no real cyclic tag in JSF (the DataTable is not really a cyclic label);

facelets Support Expression language (EL)

For example:

<span>your Basket has ${basket.linecount} items</span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.