Development of JSF applications in netbeans (2)

Source: Internet
Author: User
Tags netbeans

Purpose: To use managed beans in JSF applications. In the previous section, we used the JSF component to create a simple web application. However, our web applications cannot do anything meaningful. To enrich the functions of our JSF application, we can establish association between the backing bean and the UI component. The auxiliary bean, also known as the JSF management bean, is a common JavaBean Component, but its attributes and methods can be accessed by the JSF component. In our example, we will create a userbean management bean with two attributes: name and birthday. 1. Right-click the project, select new, and then select File/folder. In the Web category, select the JSF managed bean template and click Next. 2. Name the bean Userbean , Put in Astrologer. User Other settings and default values do not need to be modified, and then click Finish . IDE Will be opened in the source code editing area Userbean. Java , And Faces-config.xml Add the following Bean Statement:
    <managed-bean>
        <managed-bean-name>UserBean</managed-bean-name>
        <managed-bean-class>astrologer.user.UserBean</managed-bean-class>
        <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
3. Add the following domain declaration in userbean. java.
public class UserBean {
 
    String name;
    String birthday;
4. Generate the getter and setter methods for the domain. Right-click anywhere in the file and select encapsulate fields in refactor. Select next in the dialog box and refactor it in the refactoring window. IDE changes the access control of the domain to private, and then creates the getter and setter methods. 5. In Greeting. jsp (In bold ). Note: Userbeans. Java You can use the code completor.
    <f:view>
        
            <p>Enter your name: 
            <p>Enter your birthday: 
            
        
    </f:view>
6. In Success. jsp Add JSF Tag library declaration, which can be viewed from Greeting. jsp .7. Click the JSF form button in the control window and drag it to the H1 mark in the original file editor. Success. jsp Add an empty JSF Form.8. Modify success. jsp as follows:
    
    <f:view>
        
            <p>You've successfully registered with jAstrologer.</p>
            <p>Your name is 
            <p>Your birthday is 
        
    </f:view>
9. Right-click the project and select Run project. After the project is deployed, you will see the same welcome page. Enter the value and click Submit, success. JSP will display the value you entered, as shown in: for auxiliary beans, refer to chapter 198 auxiliary bean book on page 1: Java ee 5 practical tutorial

 

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.