javax.faces.component.UIViewRoot Java Examples

The following examples show how to use javax.faces.component.UIViewRoot. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SubscriptionWizardConversationTest.java    From development with Apache License 2.0 7 votes vote down vote up
@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
Source File: HideDivisionRenderer.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void encodeEnd(FacesContext context, UIComponent component) throws
  IOException {
    if (!component.isRendered()) {
      return;
    }

    ResponseWriter writer = context.getResponseWriter();

    String jsfId = (String) RendererUtil.getAttribute(context, component, "id");
    String id = jsfId;

    if (component.getId() != null &&
        !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
    {
      id = component.getClientId(context);
    }

    writer.write("</div>");

//    writer.write("<script type=\"text/javascript\">");
//    writer.write("  showHideDiv('" + id +
//        "', '" +  RESOURCE_PATH + "');");
//    writer.write("</script>");
  }
 
Example #3
Source File: NavigatorContainerNodeTest.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
public void testNavigatorContainerNode() throws Exception {
        FacesContext context = TestProject.createFacesContext(this); // [0]first get request
        ((FacesContextEx)context).setSessionProperty("xsp.theme", "oneuiv3.0.2");
        String name = "/pages/testNavigatorContainerNode.xsp";
        UIViewRoot root = TestProject.loadView(this, context, name);
        ResponseBuffer.initContext(context);
        
        // this used to throw a NullPointerException:
        String page = ResponseBuffer.encode(root, context);
//        System.out.println("NavigatorContainerNodeTest.testNavigatorContainerNode()\n"+page);
        
        // verify container node renders ok:
        String expectedContent = "";
        expectedContent+="<li><div";
        expectedContent+=" class=\"lotusMenuSubsection\"";
        expectedContent+=" style=\"margin-top: 0\"";
        expectedContent+="><ul>";
        AssertUtil.assertContains(page, expectedContent);
    }
 
Example #4
Source File: F5Detector.java    From BootsFaces-Examples with Apache License 2.0 6 votes vote down vote up
public void checkF5() {
	String msg = "";
	UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
	String id = viewRoot.getViewId();
	if (previousPage == null) {
		msg = "First page ever";
	} else if (previousPage.equals(id)) {
		msg = "F5 or reload";
	} else if (FacesContext.getCurrentInstance().isPostback()) {
		msg = "It's a postback";
	} else
		msg = "It's a navigation";
	previousPage = id;
	FacesMessage fm = new FacesMessage(msg);
	FacesContext.getCurrentInstance().addMessage(null, fm);
}
 
Example #5
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
/**
 * Check if there is almost one bootsfaces component in page. If yes, load the
 * correct items.
 *
 * To ensure that, it checks first the viewMap to find specific bootsfaces key.
 * If it found nothing, it check for components that has as a resource lib, the
 * "bsf" lib.
 *
 * @param root    the UIViewRoot
 * @param context the faces context
 * @return
 */
private boolean ensureExistBootsfacesComponent(UIViewRoot root, FacesContext context) {
	Map<String, Object> viewMap = root.getViewMap();

	// check explicit js request
	if (viewMap.get(RESOURCE_KEY) != null) {
		return true;
	}
	// check explicit css request
	if (viewMap.get(THEME_RESOURCE_KEY) != null) {
		return true;
	}
	// check explicit css request
	if (viewMap.get(EXT_RESOURCE_KEY) != null) {
		return true;
	}
	// check referenced bsf request
	if (findBsfComponent(root, C.BSF_LIBRARY) != null) {
		return true;
	}

	return false;
}
 
Example #6
Source File: JSFUtils.java    From development with Apache License 2.0 6 votes vote down vote up
private static void verifyViewLocale(FacesContext fc) {
    HttpServletRequest request = (HttpServletRequest) fc
            .getExternalContext().getRequest();
    String localeString = localeStringFrom(request);

    // if the view locale differs from the users locale change the view
    // locale
    UIViewRoot viewRoot = fc.getViewRoot();
    if (localeString != null
            && !viewRoot.getLocale().toString().equals(localeString)) {
        Iterator<Locale> it = fc.getApplication().getSupportedLocales();
        while (it.hasNext()) {
            Locale locale = it.next();
            if (locale.toString().equals(localeString)) {
                viewRoot.setLocale(locale);
                return;
            }
        }
        // we use the default locale if the requested locale was not
        // found
        if (!viewRoot.getLocale().equals(
                fc.getApplication().getDefaultLocale())) {
            viewRoot.setLocale(fc.getApplication().getDefaultLocale());
        }
    }
}
 
Example #7
Source File: DojoCheckBoxDefaultValueDisabledTest.java    From XPagesExtensionLibrary with Apache License 2.0 6 votes vote down vote up
/**
 * @param root
 * @param contextForPost
 * @return
 * @throws IOException
 */
private String doSubmitAndRedisplay(UIViewRoot root, FacesContext contextForPost) throws IOException {
    String page;
    // now fake the JSF lifecycle
    root.processDecodes(contextForPost);
    root.processValidators(contextForPost);
    if( contextForPost.getMessages().hasNext() ){
        fail("messages found after validate");
    }
    root.processUpdates(contextForPost);
    root.processApplication(contextForPost);
    if( contextForPost.getMessages().hasNext() ) fail("messages found");
    ResponseBuffer.initContext(contextForPost);
    page = ResponseBuffer.encode(root, contextForPost);
    return page;
}
 
Example #8
Source File: SakaiViewHandlerWrapper.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException {
	// SAK-20286 start
	// Get the request
	HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
	String requestURI = req.getRequestURI();
	// Make the attribute name unique to the request 
	String attrName = "sakai.jsf.tool.URL.loopDetect.viewId-" + requestURI;
	// Try to fetch the attribute
	Object attribute = req.getAttribute(attrName);
	// If the attribute is null, this is the first request for this view
	if (attribute == null) {
		req.setAttribute(attrName, "true");
	} else if ("true".equals(attribute)) { // A looping request is detected.
		HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getResponse();
		// Send a 404
		res.sendError(404, "File not found: " + requestURI);
	}
	// SAK-20286 end
	getWrapped().renderView(context, root);
}
 
Example #9
Source File: SakaiViewHandlerWrapper.java    From sakai with Educational Community License v2.0 6 votes vote down vote up
public void renderView(FacesContext context, UIViewRoot root) throws IOException, FacesException {
	// SAK-20286 start
	// Get the request
	HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
	String requestURI = req.getRequestURI();
	// Make the attribute name unique to the request 
	String attrName = "sakai.jsf.tool.URL.loopDetect.viewId-" + requestURI;
	// Try to fetch the attribute
	Object attribute = req.getAttribute(attrName);
	// If the attribute is null, this is the first request for this view
	if (attribute == null) {
		req.setAttribute(attrName, "true");
	} else if ("true".equals(attribute)) { // A looping request is detected.
		HttpServletResponse res = (HttpServletResponse) context.getExternalContext().getResponse();
		// Send a 404
		res.sendError(404, "File not found: " + requestURI);
	}
	// SAK-20286 end
	getWrapped().renderView(context, root);
}
 
Example #10
Source File: MessageListener.java    From development with Apache License 2.0 6 votes vote down vote up
/**
 * Ids of fields inside tables look like <code>tableId:rowNr:fieldId</code>.
 * So we try to cut the fieldId and the rowNr parts to get the table id and
 * then check if it is inside a section and return the section id.
 * 
 * @param clientId
 *            the id of the field inside of a table
 * @param root
 *            the {@link UIViewRoot}
 * @return the section id or <code>null</code>
 */
private String getTableSectionId(String clientId, UIViewRoot root) {
    if (!clientId.contains(":")) {
        return null;
    }
    // cut the field id
    clientId = clientId.substring(0, clientId.lastIndexOf(':'));
    if (!clientId.contains(":")) {
        return null;
    }
    // cut the row number - we should have the table id
    clientId = clientId.substring(0, clientId.lastIndexOf(':'));
    UIComponent comp = root.findComponent(clientId);
    if (comp != null) {
        return getSectionId(comp);
    }
    return null;
}
 
Example #11
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
/**
 * Look whether a b:iconAwesome component is used. If so, the font-awesome.css
 * is removed from the resource list because it's loaded from the CDN.
 *
 * @return true, if the font-awesome.css is found in the resource list. Note the
 *         side effect of this method!
 */
private boolean isFontAwesomeComponentUsedAndRemoveIt() {
	FacesContext fc = FacesContext.getCurrentInstance();
	UIViewRoot viewRoot = fc.getViewRoot();
	ListIterator<UIComponent> resourceIterator = (viewRoot.getComponentResources(fc, "head")).listIterator();
	UIComponent fontAwesomeResource = null;
	while (resourceIterator.hasNext()) {
		UIComponent resource = resourceIterator.next();
		String name = (String) resource.getAttributes().get("name");
		// rw.write("\n<!-- res: '"+name+"' -->" );
		if (name != null) {
			if (name.endsWith("font-awesome.css")) {
				fontAwesomeResource = resource;
			}
		}
	}
	if (null != fontAwesomeResource) {
		fontAwesomeResource.setInView(false);
		viewRoot.removeComponentResource(fc, fontAwesomeResource);
		// System.out.println("-3" + fontAwesomeResource.getClientId());
		return true;
	}
	return false;
}
 
Example #12
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
/**
 * Add the viewport meta tag if not disabled from context-param
 *
 * @param root
 * @param context
 * @param isProduction
 */
private void addMetaTags(UIViewRoot root, FacesContext context) {
	// Check context-param
	String viewportParam = BsfUtils.getInitParam(C.P_VIEWPORT, context);

	viewportParam = evalELIfPossible(viewportParam);
	String content = "width=device-width, initial-scale=1";
	if (!viewportParam.isEmpty() && isFalseOrNo(viewportParam)) {
		return;
	}
	if (!viewportParam.isEmpty() && !isTrueOrYes(viewportParam)) {
		content = viewportParam;
	}

	// Otherwise
	String viewportMeta = "<meta name=\"viewport\" content=\"" + content + "\"/>";
	UIOutput viewport = new UIOutput();
	viewport.setRendererType("javax.faces.Text");
	viewport.getAttributes().put("escape", false);
	viewport.setValue(viewportMeta);

	UIComponent header = findHeader(root);
	if (header != null) {
		header.getChildren().add(0, viewport);
	}
}
 
Example #13
Source File: FindIdExpressionResolver.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId,
		String originalExpression, String[] parameters) {

	List<UIComponent> result = new ArrayList<UIComponent>();
	for (UIComponent parent : parentComponents) {
		UIComponent searchRoot = parent;
		while ((!(searchRoot instanceof UIViewRoot)) && (!(searchRoot instanceof NamingContainer))) {
			searchRoot = searchRoot.getParent();
		}
			
		UIComponent c = findId(searchRoot, parameters[0]);
		if (null != c) {
			result.add(c);
		}
	}
	if (result.size() > 0) {
		return result;
	}

	throw new FacesException("Invalid search expression - couldn't find id " + currentId + ". Complete search expression: " + originalExpression);
}
 
Example #14
Source File: FindPartialIdExpressionResolver.java    From BootsFaces-OSP with Apache License 2.0 6 votes vote down vote up
public List<UIComponent> resolve(UIComponent component, List<UIComponent> parentComponents, String currentId,
		String originalExpression, String[] parameters) {

	List<UIComponent> result = new ArrayList<UIComponent>();
	for (UIComponent parent : parentComponents) {
		UIComponent searchRoot = parent;
		while ((!(searchRoot instanceof UIViewRoot)) && (!(searchRoot instanceof NamingContainer))) {
			searchRoot = searchRoot.getParent();
		}
			
		List<UIComponent> c = findId(searchRoot, parameters[0]);
		if (null != c) {
			result.addAll(c);
		}
	}
	if (result.size() > 0) {
		return result;
	}

	throw new FacesException("Invalid search expression - couldn't find id " + currentId + ". Complete search expression: " + originalExpression);
}
 
Example #15
Source File: ExternalCustomerPriceModelCtrlTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeClass() {
    ctrl = spy(new ExternalCustomerPriceModelCtrl());
    model = spy(new ExternalPriceModelModel());
    ctrl.setModel(model);
    ctrl.ui = mock(UiDelegate.class);

    appbean = mock(ApplicationBean.class);
    sessionBean = mock(SessionBean.class);
    doReturn(sessionBean).when(ctrl).getSessionBean();

    externalPriceModelService = mock(ExternalPriceModelService.class);
    externalPriceModelCtrl = mock(ExternalPriceModelCtrl.class);

    doReturn(locale).when(appbean).getDefaultLocale();
    doReturn(externalPriceModelService).when(ctrl)
            .getExternalPriceModelService();

    UIViewRoot viewRoot = mock(UIViewRoot.class);
    given(viewRoot.getLocale()).willReturn(locale);
    new FacesContextStub(locale).setViewRoot(viewRoot);
}
 
Example #16
Source File: ExternalPriceModelCtrlTest.java    From development with Apache License 2.0 6 votes vote down vote up
@Before
public void beforeClass() {
    ctrl = Mockito.mock(ExternalPriceModelCtrl.class,
            Mockito.CALLS_REAL_METHODS);
    model = spy(new ExternalPriceModelModel());
    ctrl.setModel(model);
    ctrl.ui = mock(UiDelegate.class);

    appbean = mock(ApplicationBean.class);
    doReturn(appbean).when(ctrl).getAppBean();
    doReturn(locale).when(appbean).getDefaultLocale();

    externalPriceModelService = mock(ExternalPriceModelService.class);
    doReturn(externalPriceModelService).when(ctrl)
            .getExternalPriceModelService();

    sessionBean = mock(SessionBean.class);
    doReturn(sessionBean).when(ctrl).getSessionBean();

    UIViewRoot viewRoot = mock(UIViewRoot.class);
    given(viewRoot.getLocale()).willReturn(locale);
    new FacesContextStub(locale).setViewRoot(viewRoot);
}
 
Example #17
Source File: TimerBarRenderer.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
/**
* <p>Faces render output method .</p>
* <p>Method Generator: org.sakaiproject.tool.assessment.devtools.RenderMaker</p>
*
*  @param context   <code>FacesContext</code> for the current request
*  @param component <code>UIComponent</code> being rendered
*
* @throws IOException if an input/output error occurs
*/
 public void encodeEnd(FacesContext context, UIComponent component)
   throws IOException {

    if (!component.isRendered())
    {
      return;
     }

     ResponseWriter writer = context.getResponseWriter();

     String clientId = null;

     if (component.getId() != null &&
       !component.getId().startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
     {
       clientId = component.getClientId(context);
     }

     if (clientId != null)
     {
       writer.startElement("span", component);
       writer.writeAttribute("id", clientId, "id");
     }

      String contextPath = context.getExternalContext().getRequestContextPath();
      writer.write("\n<script type=\"text/javascript\" src=\"" +
        contextPath + SCRIPT_PATH + "timerbar.js\"></script>");
      writer.write("\n");

     if (clientId != null)
       {
       writer.endElement("span");
     }
 }
 
Example #18
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
private boolean needsFontAwesome4() {
	FacesContext context = FacesContext.getCurrentInstance();
	UIViewRoot root = context.getViewRoot();
	Map<String, Object> viewMap = root.getViewMap();
	@SuppressWarnings("unchecked")
	Map<Object, Boolean> v5 = (Map<Object, Boolean>) viewMap.get(FONTAWESOME_NEW_VERSION);
	@SuppressWarnings("unchecked")
	ArrayList<Object> all = (ArrayList<Object>) viewMap.get(FONTAWESOME_USED);
	viewMap.remove(FONTAWESOME_NEW_VERSION);
	viewMap.remove(FONTAWESOME_USED);
	if (all == null) {
		return false;
	}
	if (v5 == null) {
		all.clear();
		return true;
	}
	boolean v4 = false;
	for (Object o : all) {
		if (!v5.containsKey(o)) {
			v4 = true;
			break;
		}
	}
	all.clear();
	v5.clear();
	return v4;
}
 
Example #19
Source File: MockedJsf2TestContainer.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
protected void initDefaultView()
{
    UIViewRoot root = new UIViewRoot();
    root.setViewId("/viewId");
    root.setLocale(getLocale());
    root.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    this.facesContext.setViewRoot(root);
}
 
Example #20
Source File: SakaiViewHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public UIViewRoot restoreView(FacesContext arg0, String arg1)
{
	UIViewRoot root = m_wrapped.restoreView(arg0, arg1);

	if (root != null)
	{
		// restore messages
		MessageSaver.restoreMessages(arg0);
	}

	return root;
}
 
Example #21
Source File: SakaiViewHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public UIViewRoot createView(FacesContext arg0, String arg1)
{
	UIViewRoot root = m_wrapped.createView(arg0, arg1);

	if (root != null)
	{
		// restore messages
		MessageSaver.restoreMessages(arg0);
	}

	return root;
}
 
Example #22
Source File: SakaiViewHandler.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public UIViewRoot restoreView(FacesContext arg0, String arg1)
{
	UIViewRoot root = m_wrapped.restoreView(arg0, arg1);

	if (root != null)
	{
		// restore messages
		MessageSaver.restoreMessages(arg0);
	}

	return root;
}
 
Example #23
Source File: MockedJsfContainerTest.java    From deltaspike with Apache License 2.0 5 votes vote down vote up
@Test
public void secondTest()
{
    Assert.assertEquals(0, requestScopedBean.getCount());
    requestScopedBean.increaseCount();
    Assert.assertEquals(1, requestScopedBean.getCount());

    Assert.assertEquals(0, sessionScopedBean.getCount());
    sessionScopedBean.increaseCount();
    Assert.assertEquals(1, sessionScopedBean.getCount());

    Assert.assertNotNull(FacesContext.getCurrentInstance().getViewRoot());
    Assert.assertEquals("/viewId", FacesContext.getCurrentInstance().getViewRoot().getViewId());

    UIViewRoot uiViewRoot = new UIViewRoot();
    uiViewRoot.setViewId("/test2.xhtml");
    uiViewRoot.setRenderKitId(RenderKitFactory.HTML_BASIC_RENDER_KIT);
    FacesContext.getCurrentInstance().setViewRoot(uiViewRoot);
    Assert.assertEquals("/test2.xhtml", FacesContext.getCurrentInstance().getViewRoot().getViewId());

    Assert.assertNotNull(FacesContext.getCurrentInstance().getExternalContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getApplication());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getELContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getPartialViewContext());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getRenderKit());
    Assert.assertNotNull(FacesContext.getCurrentInstance().getExceptionHandler());

    Assert.assertNull(FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
    FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("test", "2");
    Assert.assertEquals("2", FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("test"));
}
 
Example #24
Source File: AbstractRestService.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected void writeId(ResponseWriter writer, FacesContext context, UIComponent component) throws IOException {
    // only write valid user defined ids
    String id = component.getId();
    if (id != null && !id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX)) {
        writer.writeAttribute("id", component.getClientId(context), "id"); // $NON-NLS-1$ $NON-NLS-2$
    }
}
 
Example #25
Source File: NotImplementedRenderer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
protected NotImplementedException createNotImplementedEx(FacesContext context){
    String theme = null;
    if( context instanceof FacesContextEx ){
        theme = ((FacesContextEx)context).getStyleKitId();
    }
    String renderKitId = null;
    UIViewRoot viewRoot = context.getViewRoot();
    if( null != viewRoot ){
        renderKitId = viewRoot.getRenderKitId();
    }
    String msg = "This control is not implemented for the current theme ({0}) and render-kit({1}), try a different theme, perhaps {2}."; // $NLX-NotImplementedRenderer_ThisControlIsNotImplemented-1$
    msg = StringUtil.format(msg, theme, renderKitId, getSuggestedTheme());
    throw new NotImplementedException(msg);
}
 
Example #26
Source File: SakaiViewHandlerWrapper.java    From sakai with Educational Community License v2.0 5 votes vote down vote up
public UIViewRoot createView(FacesContext arg0, String arg1)
{
	UIViewRoot root = getWrapped().createView(arg0, arg1);

	if (root != null)
	{
		// restore messages
		MessageSaver.restoreMessages(arg0);
	}

	return root;
}
 
Example #27
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Trigger adding the resources if and only if the event has been fired by
 * UIViewRoot.
 */
public void processEvent(SystemEvent event) throws AbortProcessingException {
	FacesContext context = FacesContext.getCurrentInstance();
	UIViewRoot root = context.getViewRoot();

	// render the resources only if there is at least one bsf component
	if (ensureExistBootsfacesComponent(root, context)) {
		addCSS(root, context);
		addJavascript(root, context);
		addMetaTags(root, context);
	}
}
 
Example #28
Source File: AddResourcesListener.java    From BootsFaces-OSP with Apache License 2.0 5 votes vote down vote up
/**
 * Add the default datatables.net resource if and only if the user doesn't bring
 * their own copy, and if they didn't disallow it in the web.xml by setting the
 * context paramter net.bootsfaces.get_datatable_from_cdn to true.
 *
 * @param defaultFilename The URL of the file to be loaded
 * @param type            either "js" or "css"
 */
public static void addDatatablesResourceIfNecessary(String defaultFilename, String type) {
	boolean loadDatatables = shouldLibraryBeLoaded(P_GET_DATATABLE_FROM_CDN, true);
	// Do we have to add datatables.min.{css|js}, or are the resources already
	// there?
	FacesContext context = FacesContext.getCurrentInstance();
	UIViewRoot root = context.getViewRoot();

	String[] positions = { "head", "body", "form" };
	for (String position : positions) {
		if (loadDatatables) {
			List<UIComponent> availableResources = root.getComponentResources(context, position);
			for (UIComponent ava : availableResources) {
				if (ava.isRendered()) {
					String name = (String) ava.getAttributes().get("name");
					if (null != name) {
						name = name.toLowerCase();
						if (name.contains("datatables") && name.endsWith("." + type)) {
							loadDatatables = false;
							break;
						}
					}
				}
			}
		}
	}
	if (loadDatatables) {
		addResourceIfNecessary(defaultFilename);
	}
}
 
Example #29
Source File: ReflectionCompareSerializer.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public String compareRoot(UIViewRoot restored) {
    // compare the initial view and the restored view
    SerializationFullComparator comparator = new SerializationFullComparator(compareContext);
    
    String viewFails = comparator.compareWithFailsResult(root, restored);
    return viewFails;
}
 
Example #30
Source File: TestProject.java    From XPagesExtensionLibrary with Apache License 2.0 5 votes vote down vote up
public static UIViewRoot loadEmptyPage(AbstractXspTest test, FacesContext context) throws Exception{
    String pageName = "/pages/pregenerated/empty.xsp";
    Application application = lazyApplication(test);
    ViewHandler viewHandler = application.getViewHandler();
    UIViewRoot root = viewHandler.createView(context, pageName);
    if( null == root ){
        throw new RuntimeException("JUnit test could not load the empty page "+pageName);
    }
    context.setViewRoot(root);
    return root;
}