public void afterPhase(PhaseEvent event) {
   FacesContext facesContext = event.getFacesContext();
   AddResource addResource = AddResourceFactory.getInstance(facesContext);
   String jsTxt = genJavaScriptCodeForMessages(facesContext);
   if (jsTxt != null) {
     addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, jsTxt);
   }
 }
  @SuppressWarnings("unchecked")
  public void beforePhase(PhaseEvent event) {
    FacesContext facesContext = event.getFacesContext();
    UIViewRoot root = facesContext.getViewRoot();
    AddResource addResource = AddResourceFactory.getInstance(facesContext);
    addReferences(facesContext, addResource);
    visitComponent(facesContext, root);
    //        String jsTxt = genJavaScriptCodeForMessages(facesContext);
    //        if (jsTxt != null) {
    //            addResource.addInlineScriptAtPosition(facesContext,
    //                AddResource.HEADER_BEGIN, jsTxt);
    //        }

    String styleSheetCode = genStyleCode(facesContext);
    if (styleSheetCode != null) {
      addResource.addInlineStyleAtPosition(facesContext, AddResource.HEADER_BEGIN, styleSheetCode);
    }
  }
  private static void addReferences(FacesContext facesContext, AddResource addResource) {

    //        addBodyEndJavaScriptRef(facesContext, addResource, "prototype.js");
    //        addBodyEndJavaScriptRef(facesContext, addResource, "fx4web.js");
    addJavaScriptRef(facesContext, addResource, "jquery-1.10.2.js");
    //        addResource.addJavaScriptAtPosition(facesContext,
    //            AddResource.HEADER_BEGIN,
    // "http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js");
    addResource.addInlineScriptAtPosition(
        facesContext, AddResource.HEADER_BEGIN, "var $j = jQuery.noConflict();");
    addJavaScriptRef(facesContext, addResource, "initPages.js");
    addJavaScriptRef(facesContext, addResource, "prototype.js");
    addJavaScriptRef(facesContext, addResource, "fx4web.js");

    addJavaScriptRef(facesContext, addResource, "ieSpell.js");
    addStyleSheetRef(facesContext, addResource, "fx4web.css");

    // get the district id from config file and set the appropriate css
    String district =
        ConfigService.getInstance().getAttributeString("ereg", "appSettings", "district");
    addStyleSheetRef(facesContext, addResource, district.toLowerCase() + ".css");
  }
 private static void addBodyEndJavaScriptRef(
     FacesContext facesContext, AddResource addResource, String uri) {
   addResource.addJavaScriptAtPosition(facesContext, AddResource.BODY_END, "/js/" + uri);
 }
 private static void addJavaScriptRef(
     FacesContext facesContext, AddResource addResource, String uri) {
   addResource.addJavaScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, "/js/" + uri);
 }
 private static void addStyleSheetRef(
     FacesContext facesContext, AddResource addResource, String uri) {
   addResource.addStyleSheet(facesContext, AddResource.HEADER_BEGIN, "/css/" + uri);
 }