Use netbeans6.x to develop vjf programs

Source: Internet
Author: User
Use netbenas6.x to develop the visual web JSF Program



In the JSF summary article, we use a login page example to introduce how to use netbeans6.1 and jsf1.2 to develop web programs. In this example, we will use (and recommended) Visual Web JSF for the same development. This article compares the differences and similarities between the two technologies. I personally think that vjf is a more convenient framework developed on the JSF specification. It provides more advanced tags, designs page beans, and provides a visual development environment, this greatly improves the development efficiency. However, since it is based on JSF, the basic knowledge of JSF is still very important. We recommend that you read JSF summary first and then read this article.

Understand what the wizard has done for us

 






It is easy to create a project. Select a web application, select Visual Web Java Server faces in the wizard, and set the project name to vjfdemo. Now let's see what the wizard has done for us?

The wizard creates a page1.jsp file with the following source code:

<? XML version = "1.0" encoding = "UTF-8"?>

<! --

Document: page1

Created on:, 10:05:51

Author: freebird

-->

<JSP: Root
Version = "2.1" xmlns: F = "http://java.sun.com/jsf/core"
Xmlns: H = "http://java.sun.com/jsf/html"
Xmlns: JSP = "http://java.sun.com/JSP/Page"
Xmlns: webuijsf = "http://www.sun.com/webui/webuijsf">


<JSP: Directive. Page contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8"/>

<F: View>

<Webuijsf: Page id = "page1">

<Webuijsf: HTML id = "html1">

<Webuijsf: Head id = "head1">

<Webuijsf: link id = "link1" url = "/resources/stylesheet.css"/>

</Webuijsf: Head>

<Webuijsf: body id = "body1" style = "-Rave-layout: Grid">

<Webuijsf: Form ID = "form1">

</Webuijsf: Form>

</Webuijsf: Body>

</Webuijsf: HTML>

</Webuijsf: Page>

</F: View>

</Jsp: root>


Here we can see a lot of unfamiliar tags with a header called the project Woodstock 4.3 tag library. For specific usage, refer to the following URL:

Http://webdev2.sun.com/woodstock-tlddocs/index.html

In page1.jsp, the red line of code introduces the XML syntax of various tags. Xmlns: webuijsf = "http://www.sun.com/webui/webuijsf" is the XML syntax of the vjf tag. <Webuijsf: Page> the tag must be <webuijsf: HTML> and <webuijsf: Head>.




One feature of vjf is that each JSP page corresponds to a JavaBean, which is called a page bean. If the JSP page contains the UI control, the corresponding page bean contains
Widget object. You can also add the lifecycle method and event processing method to the page bean. In the following code, I added comments.

 

Package vjfdemo;


Import com. Sun. Rave. Web. UI. appbase. abstractpagebean;

Import javax. Faces. facesexception;


Public class page1 extends actpagebean {


// The Wizard will generate and implement this method, mainly the initialization of the UI component. Do not modify this method.

Private void _ Init () throws exception {

}


Public page1 (){

}


// When the webpage is accessed, the init method will be called

@ Override

Public void Init (){

Super. INIT ();

// Add the initialization code here, which will be called before the UI component is initialized





// The Code cannot be modified here

Try {

_ Init ();

} Catch (exception e ){

Log ("page1 initialization failure", e );

Throw e instanceof facesexception? (Facesexception) E: New facesexception (E );

}



// Add your own code here, which will be called after the UI component initialization ends

}


// This method is called before any event is processed after the view restoration stage is complete. This method is called only when a form is submitted. You can rewrite this method to prepare for subsequent event processing.

@ Override

Public void preprocess (){

}


// This method will be called before the webpage is drawn. If you navigate to another page, this method will not be called. To rewrite this method, you can prepare for the subsequent web pages.

@ Override

Public void prerender (){

}


// After the web page is drawn, this method is called. This method is usually used to release resources.

@ Override

Public void destroy (){

}




Protected sessionbean1 getsessionbean1 (){

Return (sessionbean1) getbean ("sessionbean1 ");

}



Protected requestbean1 getrequestbean1 (){

Return (requestbean1) getbean ("requestbean1 ");

}


Protected applicationbean1 getapplicationbean1 (){

Return (applicationbean1) getbean ("applicationbean1 ");

}


}

Getsessionbean1/getrequestbean1/getapplicationbean1 will be detailed later.



The Wizard will also configure page1/sessionbean1/requestbean1/applicationbean1 for us. Below is the content of the faces-config.xml file:

<? XML version = '1. 0' encoding = 'utf-8'?>


<! -- =========== Full configuration file ====================================== ===========-->


<Faces-config version = "1.2"

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-facesconfig_1_2.xsd">

<Managed-bean>

<Managed-bean-Name> sessionbean1 </managed-bean-Name>

<Managed-bean-class> vjfdemo. sessionbean1 </managed-bean-class>

<Managed-bean-scope> session </managed-bean-scope>

</Managed-bean>

<Managed-bean>

<Managed-bean-Name> page1 </managed-bean-Name>

<Managed-bean-class> vjfdemo. page1 </managed-bean-class>

<Managed-bean-scope> request </managed-bean-scope>

</Managed-bean>

<Managed-bean>

<Managed-bean-Name> applicationbean1 </managed-bean-Name>

<Managed-bean-class> vjfdemo. applicationbean1 </managed-bean-class>

<Managed-bean-scope> application </managed-bean-scope>

</Managed-bean>

<Managed-bean>

<Managed-bean-Name> requestbean1 </managed-bean-Name>

<Managed-bean-class> vjfdemo. requestbean1 </managed-bean-class>

<Managed-bean-scope> request </managed-bean-scope>

</Managed-bean>

</Faces-config>

As you can see, these beans are actually managed beans.

Write logon page

First, we will introduce some useful resources. This article will help us learn how to use netbeans6.1 to develop the vjf program: http://www.netbeans.org/kb/60/web/intro_zh_cn.html. The development process is not described in detail in this article. It is so tired.

See my vjfdemo project. Note that the user class is no longer a managed bean, but a business logic class that assumes the role of model.


 

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.