Listings 2-14 + Additional Code

Listing 1

    public void welcomeUser(){
        FacesContext facesContext =
FacesContext.getCurrentInstance();
        String username = getParam(facesContext, "username");
        writeResponse(facesContext, "Welcome " + username + " and hello world!");
    }

    private static String getParam( FacesContext facesContext, String param ){
        String value = (String)facesContext
            .getExternalContext()
            .getRequestParameterMap().get(param);
        return value;
    }

    private static void writeResponse(FacesContext context, String text) {
        if(context == null || text == null) return;        
        ResponseWriter writer =
 	(new ResponseFactory()).getResponseWriter(context, "text/plain");
        try {
            writer.startDocument();
            writer.writeText(text, null);
            writer.endDocument();
            writer.close();
            context.responseComplete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

Listings 2-14 + Additional Code