Uploaded image for project: 'PUBLIC - Liferay Faces'
  1. PUBLIC - Liferay Faces
  2. FACES-3234

Replace FacesRequestContext with static utility class storing scripts in a FacesContext attribute

    Details

      Description

      This task involves adding the following static utility class to util:

      public final class ScriptUtil {
      
          private ScriptUtil() {
              throw new AssertionError();
          }
      
          public static void addScript(Script script) {
      
              FacesContext facesContext = FacesContext.getCurrentInstance();
              addScript(facesContext, script);
          }
      
          public static void addScript(String script) {
      
              FacesContext facesContext = FacesContext.getCurrentInstance();
              addScript(facesContext, script);
          }
      
          public static void addScript(FacesContext facesContext, Script script) {
              getMutableScripts(facesContext).add(script);
          }
      
          public static void addScript(FacesContext facesContext, String script) {
      
              ExternalContext externalContext = facesContext.getExternalContext();
              Script scriptInstance = ScriptFactory.getScriptInstance(externalContext, script);
              addScript(facesContext, scriptInstance);
          }
      
          public static List<Script> getScripts() {
              FacesContext facesContext = FacesContext.getCurrentInstance();
      
              return getScripts(facesContext);
          }
      
          public static List<Script> getScripts(FacesContext facesContext) {
              return Collections.unmodifiableList(getMutableScripts(facesContext));
          }
      
          private static List<Script> getMutableScripts(FacesContext facesContext) {
      
              Map<Object, Object> attributes = facesContext.getAttributes();
      
              List<Script> scripts = (List<Script>) attributes.get(ScriptUtil.class.getClass());
      
              if (scripts == null) {
      
                  scripts = new ArrayList<Script>();
                  attributes.put(ScriptUtil.class.getClass(), scripts);
              }
      
              return scripts;
          }
      }
      

      This class will replace the FacesRequestContext class which can be removed in Util 4.0.0. In all other branches FacesRequestContext should be deprecated and call through to this static utility.

      The benefit of removing FacesRequestContext is that Util's FacesContextFactoryUtilImpl and all FacesRequestContext code can be removed. Also, there will be one less ThreadLocal singleton during each request because FacesRequestContext won't exist.

        Attachments

          Activity

            People

            • Assignee:
              kyle.stiemann Kyle Stiemann
              Reporter:
              kyle.stiemann Kyle Stiemann
              Participants of an Issue:
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated: