本文整理汇总了Java中javax.faces.context.FacesContext.setViewRoot方法的典型用法代码示例。如果您正苦于以下问题:Java FacesContext.setViewRoot方法的具体用法?Java FacesContext.setViewRoot怎么用?Java FacesContext.setViewRoot使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.faces.context.FacesContext
的用法示例。
在下文中一共展示了FacesContext.setViewRoot方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateSubscriptionId_ShowExternalConfiguratorIsFalse
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@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()));
}
示例2: prepareFacesContextforNullUser
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
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);
}
示例3: navigate
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
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);
}
}
示例4: handleNavigation
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@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);
}
}
示例5: popView
import javax.faces.context.FacesContext; //导入方法依赖的package包/类
@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);
}
}