Java Code Examples for javax.faces.context.FacesContext.getAttributes()

The following are Jave code examples for showing how to use getAttributes() of the javax.faces.context.FacesContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: myfaces-trinidad   File: PartialPageUtils.java   View Source Code Vote up 5 votes
/**
 * Returns <code>true</code> if optimized PPR is enabled for this request.
 * @return <code>true</code> if optimized PPR is enabled for this request
 */
public static boolean isOptimizedPPREnabled(FacesContext context, boolean checkIsPPR)
{
  boolean optimizedPPREnabled = false;
        
  if (!checkIsPPR ||
      (PartialPageUtils.isPartialRequest(context) && PartialPageUtils.isPPRActive(context)))
  {
    Map<Object, Object> contextAttributes = context.getAttributes();
    
    Object optimizedPPR = contextAttributes.get(_OPTIMIZED_PPR_ENABLED_PROP);
    
    if (optimizedPPR != null)
    {
      optimizedPPREnabled = ((Boolean)optimizedPPR).booleanValue();
    }
    else
    {
      // default optimized ppr to off
      optimizedPPREnabled = "on".equalsIgnoreCase(_getPprOptimization(context));
      
      // cache the result into the context attributes
      contextAttributes.put(_OPTIMIZED_PPR_ENABLED_PROP, optimizedPPREnabled);
    }
  }
  
  return optimizedPPREnabled;
}
 
Example 2
Project: myfaces-trinidad   File: ComponentUtils.java   View Source Code Vote up 5 votes
/**
 * @param visitContext
 * @return <code>true</code> if this is a non-iterating visit.
 */
public static boolean isSkipIterationVisit(VisitContext visitContext)
{
  FacesContext context = visitContext.getFacesContext();
  Map<Object, Object> attrs = context.getAttributes();
  Object skipIteration = attrs.get("javax.faces.visit.SKIP_ITERATION");

  return Boolean.TRUE.equals(skipIteration);
}
 
Example 3
Project: myfaces-trinidad   File: StateManagerImpl.java   View Source Code Vote up 4 votes
@SuppressWarnings("deprecation")
@Override
public Object saveView(FacesContext context)
{
  assert(context != null);

  // see if a view has been saved on the request
  Object viewState = _getCachedViewState(context);

  if (viewState != null)
  {
    // TODO gcrawfor
    //        when is this not null, meaning when is saveView being called multiple times
    //        per request?
    return viewState;
  }

  // if the root is transient don't state save
  UIViewRoot viewRoot = context.getViewRoot();

  if (viewRoot.isTransient())
  {
    return null;
  }

  String viewId = viewRoot.getViewId();
  StateManagementStrategy sms = _getStateManagementStrategy(context, viewId);
  Map<Object, Object> contextAttributes = context.getAttributes();
  
  try
  {
    contextAttributes.put(StateManager.IS_SAVING_STATE, Boolean.TRUE);
    
    if (sms != null)
    {
      // Force view root to use full state saving
      // This is necessary because we recreate the view root on postback when view root caching
      // is enabled and assume that that we can apply the full state
      if (_useViewRootCache(context, RequestContext.getCurrentInstance()))
      {
        viewRoot.clearInitialState();
      }
      
      viewState = sms.saveView(context);
    }
    else
    {
      // if there's no stateManagementStrategy handle saving the state ourselves
      _removeTransientComponents(viewRoot);

      Object structure = !_needStructure(context) ? null : new Structure(viewRoot);
      Object state = viewRoot.processSaveState(context);
      viewState = new Object[]{structure, state};

    }        
  }
  finally 
  {
    contextAttributes.remove(StateManager.IS_SAVING_STATE);
  }

  if (_saveAsToken(context, false))
  {
    viewState = _saveStateToCache(context, viewState, viewRoot);
  }

  _saveCachedViewState(context, viewState);
  return viewState;
}