-1

Im new to web programming so this is a beginner question.

In my web application which is a maven project with JSF framework(university project), I have some pages with just text that displays various information about my fake air line company(only consists of <p> and <h1>). Now, to my question. Should I just "hard code" the information on the JSF Page or should I use beans to get my text and titles from?

The information that will be on my info pages will remain the same and never change.

If this question is inappropriate to ask here, please let me know and Ill remove it.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
CJR
  • 3,174
  • 6
  • 34
  • 78
  • What does your xhtml and Java class look like? – nityan Oct 19 '14 at 01:02
  • @nityan I dont have any managedbean class yet. There is no class in my model that handles this text that I want to dispay. THe xhtml for the pages is just a regular xhtml page without any head, since it uses a template that have the necessary head information. – CJR Oct 19 '14 at 01:05
  • In that case I suggest for proper practice you should store the airline information somewhere and use the bean class to display the information (if that is in the scope of your project/assignment) – nityan Oct 19 '14 at 01:09
  • @nityan where do you suggest to store it? In a final string in the bean class? Also, should I use viewscoped for getting that text? – CJR Oct 19 '14 at 01:12

1 Answers1

0

Since you've stated that the information will never change, storing it in a string in the bean class would work, and use getter methods to retrieve the data

@ManagedBean
@SessionScoped
public final class Airlineimplements Serializable
{
    private static final long serialVersionUID = 47493274L;

    private String title = "Air Canada";
    private String headquarters = "Toronto Ontario Canada";

    public Airline()
    {
    }

    public String getTitle()
    {
        return title;
    }

    public String getHeadquarters()
    {
        return headquarters;
    }
}

This is @RequestScoped so that you retrieve the information on each request and the information is garbaged after the request.

A @RequestScoped bean will be garbaged by end of every request and recreated on every new request.

Full answer here about @ViewScoped vs @RequestScoped

Difference between View and Request scope in managed beans

Although this should be @SessionScoped which keeps the information for the life of the session.

For the Serializable UID, the serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to ensure that the caller and receiver of a Serialized object have the same loaded classes.

More information about Serializable

http://docs.oracle.com/javase/7/docs/api/java/io/Serializable.html

Here are some additional tutorials on JSF for beginners

http://www.tutorialspoint.com/jsf/

http://www.vogella.com/tutorials/JavaServerFaces/article.html

Community
  • 1
  • 1
nityan
  • 316
  • 3
  • 11
  • Just another beginner question, what does this mean: private static final long serialVersionUID = 47493274L; ? Also, what is the reason to prefer Requestscoped for this? – CJR Oct 19 '14 at 01:22
  • @BalusC Thank you for the advice, I've added some links on JSF tutorials. Also you are correct resource bundles should be used here. My apologies, I was only providing some JSF knowledge to help people get started. – nityan Oct 19 '14 at 21:44