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

The following are Jave code examples for showing how to use setViewRoot() 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: oscm   File: SubscriptionWizardConversationTest.java   View Source Code Vote up 6 votes
@Test
public void validateSubscriptionId_ShowExternalConfiguratorIsFalse()
        throws Exception {
    // given

    model.setShowExternalConfigurator(false);

    UIViewRoot viewRoot = mock(UIViewRoot.class);
    viewRoot.setViewId(SUBSCRIPTIONADD_VIEWID);

    FacesContext context = mock(FacesContext.class);
    context.setViewRoot(viewRoot);

    // when
    UIComponent toValidate = mock(UIComponent.class);
    doReturn("").when(toValidate).getClientId();
    bean.validateSubscriptionId(context, toValidate,
            new String());

    // then
    assertEquals(Boolean.FALSE,
            Boolean.valueOf(model.isShowExternalConfigurator()));
}
 
Example 2
Project: oscm   File: UiDelegateTest.java   View Source Code Vote up 6 votes
private void prepareFacesContextforNullUser() {
    final HttpSession session = new HttpSessionStub(Locale.ENGLISH) {
        @Override
        public Object getAttribute(String arg0) {
            return null;
        }
    };
    new HttpServletRequestStub(Locale.ENGLISH) {
        @Override
        public HttpSession getSession() {
            return session;
        }
    };

    FacesContext facesContext = new FacesContextStub(Locale.ENGLISH);
    UIViewRootStub vrStub = new UIViewRootStub() {
        @Override
        public Locale getLocale() {
            return Locale.ENGLISH;
        };
    };
    facesContext.setViewRoot(vrStub);
}
 
Example 3
Project: myfaces-trinidad   File: PartialDemoUtilBean.java   View Source Code Vote up 5 votes
public void navigate(ValueChangeEvent vce)
{
  Object newValue = vce.getNewValue();
  if ((newValue != null) && !"".equals(newValue))
  {
    FacesContext fContext = FacesContext.getCurrentInstance(); 
    ViewHandler vh = fContext.getApplication().getViewHandler(); 
    UIViewRoot root = vh.createView(fContext, newValue.toString()); 
    fContext.setViewRoot(root); 
  }
}
 
Example 4
Project: myfaces-trinidad   File: NavigationHandlerImpl.java   View Source Code Vote up 4 votes
@Override
public void handleNavigation(
  FacesContext context,
  String       fromAction,
  String       outcome)
{
  if (_disableNavigationHandler(context))
  {
    _delegate.handleNavigation(context, fromAction, outcome);
    return;
  }
 
  RequestContext afc = RequestContext.getCurrentInstance();
  
  // We are interested for "dialog:" prefixed outcomes 
  if ((outcome != null) && (outcome.startsWith(afc.getDialogService().getDialogNavigationPrefix())))
  {
    // Handle "dialog:" URLs
    
    // First we try find a classic navigation case from faces-config.xml
    NavigationCase navigationCase = getNavigationCase(context, fromAction, outcome);
    
    // Then if there is no rule (but we are in dialog here) try interpret 
    // outcome as view id - JSF 2.0 Implicit Navigation.
    if (navigationCase == null)
    {
      navigationCase = getNavigationCase(context, fromAction, 
          outcome.substring(afc.getDialogService().getDialogNavigationPrefix().length()));
    } 
    
    UIViewRoot newRoot = null;
    UIViewRoot oldRoot = context.getViewRoot();
    
    if (navigationCase == null)
    {
      // Execute the old (pre-ConfigurableNavigation) code in case the navigation case
      // could not be determined
      
      // ViewMap is cleared during navigation, so save it here (we will be undoing the navigation
      // by restoring the old view root below)
      Map<String,Object> viewMap = oldRoot.getViewMap(false);
      Map<String,Object> cloneMap = (viewMap == null) ? null : new HashMap<String, Object>(viewMap);
      
      _delegate.handleNavigation(context, fromAction, outcome);
      
      newRoot = context.getViewRoot();
      
      if (newRoot != oldRoot)
      {
        // Navigate back to the original root
        context.setViewRoot(oldRoot);
        
        // Restore the old ViewMap because it gets cleared during setViewRoot()
        if (cloneMap != null)
        {
          oldRoot.getViewMap().putAll(cloneMap);
        }
      }
    }
    else
    {
      newRoot = context.getApplication().getViewHandler().createView(context, navigationCase.getToViewId(context));
    }
   
    if (newRoot != oldRoot)
    {
      // Give ourselves a new page flow scope
      afc.getPageFlowScopeProvider().pushPageFlowScope(context, true);
      // And ask the component to launch a dialog
      afc.getDialogService().queueLaunchEvent(newRoot);
    }
  }
  else
  {
     // not a dialog, call the wrapped NavigationHandler
    _delegate.handleNavigation(context, fromAction, outcome);
  }
}
 
Example 5
Project: myfaces-trinidad   File: DialogServiceImpl.java   View Source Code Vote up 4 votes
@SuppressWarnings("unchecked")
@Override
public void popView(boolean navigateToPoppedView)
{
  FacesContext context = _getFacesContext();
  // Pop the view, and navigate back
  if (navigateToPoppedView)
  {
    UIViewRoot poppedView = peekView();
    if (poppedView == null)
      throw new IllegalStateException(_LOG.getMessage(
        "POPVIEW_NO_VIEW_PUSHED"));

    // Set the view root
    context.setViewRoot(poppedView);

    // Re-execute any "binding" attributes
    _executeBindings(context, poppedView);
    _LOG.fine("Popped view {0}", poppedView.getViewId());
  }

  // Make a copy of the List;  never mutate the original list
  List<Object> list = (List<Object>) _getPageFlowScope().get(_PUSHED_VIEWS_KEY);
  if (list == null)
  {
    // For starters, this should only happen if we weren't navigating
    assert(!navigateToPoppedView);
    // But even then, it's an illegal state
    throw new IllegalStateException(_LOG.getMessage(
      ">POPVIEW_NO_VIEW_PUSHED"));
  }
  else if (list.size() == 1)
  {
    _getPageFlowScope().remove(_PUSHED_VIEWS_KEY);
  }
  else
  {
    list = new ArrayList<Object>(list);
    list.remove(list.size() - 1);
    _getPageFlowScope().put(_PUSHED_VIEWS_KEY, list);
  }
}