Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.util » [javadoc | source]

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    * http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law
    9    * or agreed to in writing, software distributed under the License is
   10    * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   11    * KIND, either express or implied. See the License for the specific language
   12    * governing permissions and limitations under the License.
   13    */
   14   package org.apache.webbeans.util;
   15   
   16   import javax.faces.application.Application;
   17   import javax.faces.application.FacesMessage;
   18   import javax.faces.application.ViewHandler;
   19   import javax.faces.component.UIViewRoot;
   20   import javax.faces.context.ExternalContext;
   21   import javax.faces.context.FacesContext;
   22   import javax.servlet.http.HttpSession;
   23   
   24   import org.apache.webbeans.jsf.WebBeansPhaseListener;
   25   
   26   public final class JSFUtil
   27   {
   28       private JSFUtil()
   29       {
   30   
   31       }
   32   
   33       public static FacesContext getCurrentFacesContext()
   34       {
   35           return FacesContext.getCurrentInstance();
   36       }
   37   
   38       public static ExternalContext getExternalContext()
   39       {
   40           return getCurrentFacesContext().getExternalContext();
   41       }
   42   
   43       public static HttpSession getSession()
   44       {
   45           return (HttpSession) getExternalContext().getSession(true);
   46       }
   47   
   48       public static boolean isPostBack()
   49       {
   50           return getCurrentFacesContext().getRenderKit().getResponseStateManager().isPostback(getCurrentFacesContext());
   51       }
   52   
   53       public static String getViewId()
   54       {
   55           return getCurrentFacesContext().getViewRoot().getViewId();
   56       }
   57   
   58       public static ViewHandler getViewHandler()
   59       {
   60           return getCurrentFacesContext().getApplication().getViewHandler();
   61       }
   62   
   63       public static Application getApplication()
   64       {
   65           return getCurrentFacesContext().getApplication();
   66       }
   67       
   68       public static void addInfoMessage(String message)
   69       {
   70           FacesMessage fm = new FacesMessage(FacesMessage.SEVERITY_INFO,message,"");
   71           getCurrentFacesContext().addMessage(null, fm);
   72       }
   73   
   74       public static String getRedirectViewId(String redirectId)
   75       {
   76           Asserts.assertNotNull(redirectId, "redirectId parameter can not be null");
   77           String path = getExternalContext().getRequestContextPath();
   78   
   79           int index = redirectId.indexOf(path);
   80   
   81           return redirectId.substring(index + path.length(), redirectId.length());
   82       }
   83   
   84       public static UIViewRoot getViewRoot()
   85       {
   86           return getCurrentFacesContext().getViewRoot();
   87       }
   88   
   89       public static String getConversationId()
   90       {
   91           UIViewRoot viewRoot = JSFUtil.getViewRoot();
   92           
   93           if(viewRoot != null)
   94           {
   95               Object conversationId = viewRoot.getAttributes().get(WebBeansPhaseListener.CONVERSATION_ATTR_ID);
   96   
   97               if (conversationId != null)
   98               {
   99                   return conversationId.toString();
  100               }            
  101           }
  102           
  103           return null;
  104       }
  105   }

Home » apache-openwebbeans-1.0.0-incubating-M3-sources » org.apache.webbeans.util » [javadoc | source]