javaEE week 4

Analyze hello.java. Download link: https://github.com/javaee/tutorial-examples/tree/master/web/jsf/hello1

/** * Copyright (c) 2014 Oracle and/or its affiliates. All rights reserved. * * You may not modify, use, reproduce, or distribute this software except in * compliance with  the terms of the License at: * https://github.com/javaee/tutorial-examples/LICENSE.txt */ package javaeetutorial.hello1;

import javax.enterprise.context.RequestScoped; import javax.inject.Named;

@Named @RequestScoped public class Hello {

    private String name;

    public Hello() {     }

    public String getName() {         return name;     }

    public void setName(String user_name) {         this.name = user_name;     } }

The Hello class is called the management bean class. It provides getter and setter methods for the name attribute used by the facelets page expression. By default, the facelets page expression refers to the name of the Hello class, but the first letter is a lowercase letter (for example: hello.name).

        If you are using the default bean class name, you can annotate with @Model instead of @Named and @RequestScoped. The @Model annotation is called a prototype and is a term for an annotation that includes other annotations.

       In the Hello.java class, the annotations javax.inject.Named and javax.enterprise.context.RequestScoped use the request scope to identify the Hello class as a managed bean class. The scope defines how application data is stored and shared.

      The most commonly used scopes in JSF are as follows:

                 Request (@RequestScoped): The request scope persists during a single HTTP request in a web application. Like the hello1 application, which consists of a single request and response, the bean uses the request scope.

                 Session (@SessionScoped): A session scope persists across multiple HTTP requests in a web application. Beans use session scopes when the application contains multiple requests and responses that need to maintain data. 

                 Application (@ApplicationScoped): The application scope persists across all user interactions with the web application.

Article source: http://www.cnblogs.com/zgq0/p/8685612.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324734430&siteId=291194637