//**************************************************************** //* Copyright (c) 2014 Ford Motor Company. All Rights Reserved. //**************************************************************** package com.ford.it.jsftest; import java.io.PrintStream; import javax.annotation.PostConstruct; import javax.faces.bean.SessionScoped; import javax.inject.Inject; import javax.inject.Named; /** * Named Bean that holds a greeting */ @Named @SessionScoped public class GreetingBean { private PhraseBuilder phraseBuilder; /** * Injects a PhraseBuilder instance into this bean. The @PostConstruct method in * PhraseBuilder builds a "hello" template and add that template the phraseBuilder * template map keyed by the string "hello" * * @param phraseBuilder the PhraseBuilder to inject into the GreetingBean */ @Inject public GreetingBean(final PhraseBuilder phraseBuilder) { this.phraseBuilder = phraseBuilder; } /** * Creates a unique greeting using the "hello" template in the phraseBuilder * template map * * @param name the unique name value to be added to the "hello" template greeting, e.g., * Julie * * @return the unique greeting string, e.g., Hello, Julie */ public String createGreeting(final String name) { return this.createGreeting("hello", name); } /** * Creates a unique greeting using the template in the phraseBuilder template map * identified by the "id" String * * @param id the template key * @param name the unique name value to be added to the greeting "id" template greeting, * e.g., Julie * * @return the unique greeting string, e.g., Hello, Julie */ public String createGreeting(final String id, final String name) { return this.phraseBuilder.buildPhrase(id, name); } /** * Sends a greeting to the PrintStream * * @param to the PrintStream to send the greeting * @param name the name parameter that is being injected into the greeting */ public void greet(final PrintStream to, final String name) { to.println(createGreeting(name)); } /** * Post constructor for the GreetingBean */ @PostConstruct public void initialize() { System.out.println("PostConstuct of GreetingBean called"); } }