Java Code Examples for javax.faces.component.UIViewRoot

The following are top voted examples for showing how to use javax.faces.component.UIViewRoot. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 7 votes vote down vote up
public void testRIManyAttributes() throws IOException
{
  HtmlOutputText out = _createHtmlOutputText();
  out.setValue("Plain value");
  out.setEscape(true);
  out.setId("OutId");
  out.setTitle("Short Desc");
  out.setStyleClass("Style Class");
  out.setStyle("The Style");

  UIViewRoot root = createTestTree(out, "testRIManyAttributes()");
  renderRoot(root);

  root = createTestTree(out, "testRIManyAttributes() 2");
  renderRoot(root);
}
 
Example 2
Project: oscm   File: MessageListener.java   View source code 7 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 3
Project: myfaces-trinidad   File: UIXComponentELTag.java   View source code 7 votes vote down vote up
/**
 * Logs a message at a specified level when a stale component is detected during create component.
 * @param context FacesContext
 * @param child the UIComponent being created
 * @param oldParent the parent UIComponent
 * @param level the level at which to log the message
 */
private void _logStaleParentAtLevel(FacesContext context,
                                    UIComponent child,
                                    UIComponent oldParent,
                                    Level level)
{
  if (_LOG.isLoggable(level))
  {
    UIViewRoot viewRoot = context.getViewRoot();

    String scopedId = ComponentUtils.getScopedIdForComponent(child, viewRoot);
    String oldParentScopedId = ComponentUtils.getScopedIdForComponent(oldParent, viewRoot);
    String newParentScopedId = _getParentScopedId(viewRoot);

    String bindingEL = _getBindingExpression();

    _LOG.log(level, "ERROR_CREATE_COMPONENT_STALE",
                new Object[] {scopedId, oldParentScopedId, newParentScopedId, bindingEL});
  }
}
 
Example 4
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testSelectOneChoice() throws IOException
{
  CoreSelectOneChoice choice = new CoreSelectOneChoice();
  choice.setSimple(true);
  choice.setValue(new Integer(2));
  for (int i = 0 ; i < 10; i++)
  {
    UISelectItem selectItem  = new UISelectItem();
    selectItem.setItemLabel("Item " + i);
    selectItem.setItemValue(new Integer(i));
    choice.getChildren().add(selectItem);
  }

  UIViewRoot root = createTestTree(choice, "testSelectOneChoice");
  renderRoot(root);

  root = createTestTree(choice, "testSelectOneChoice2");
  renderRoot(root);
}
 
Example 5
Project: myfaces-trinidad   File: ComponentReferenceTest.java   View source code 6 votes vote down vote up
public void testNamingContainerViewRoot()
{
  UIViewRoot root = facesContext.getViewRoot();
  root.setId("root");
  UINamingContainer nc1 = new UINamingContainer(); nc1.setId("nc1");
  UINamingContainer nc2 = new UINamingContainer(); nc2.setId("nc2");
  UINamingContainer nc3 = new UINamingContainer(); nc3.setId("nc3");

  // build the tree
  root.getChildren().add(nc1);
  nc1.getChildren().add(nc2);
  nc2.getChildren().add(nc3);

  // Get the ComponentReference util
  ComponentReference<UINamingContainer> uiRef = ComponentReference.newUIComponentReference(nc3);

  // find the component...
  UINamingContainer referencedComp = uiRef.getComponent();

  assertEquals(nc3, referencedComp);
}
 
Example 6
Project: myfaces-trinidad   File: RenderKitTestCase.java   View source code 6 votes vote down vote up
@Override
protected void setUp() throws IOException
{
  _facesContext = createMockFacesContext(MApplication.sharedInstance(), true);
  _requestContext = createRequestContext();
  _requestContext.setSkinFamily(_skinFamily);
  _requestContext.setAgent(_agent);
  _requestContext.setRightToLeft(_rightToLeft);
  _requestContext.setOutputMode(_outputMode);
  _requestContext.setAccessibilityMode(_accMode);
  _facesContext.setCurrentPhaseId(PhaseId.RENDER_RESPONSE);

  UIViewRoot root = RenderKitBootstrap.createUIViewRoot(_facesContext);
  root.setRenderKitId(getRenderKitId());
  _facesContext.setViewRoot(root);

  ExtendedRenderKitService service =
    _getExtendedRenderKitService(_facesContext);

  if (service != null)
    service.encodeBegin(_facesContext);
}
 
Example 7
Project: oscm   File: ExternalCustomerPriceModelCtrlTest.java   View source code 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 8
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testRISelectOneMenu() throws IOException
{
  //
  HtmlSelectOneMenu menu = new HtmlSelectOneMenu();
  menu.setValue(new Integer(2));
  for (int i = 0 ; i < 10; i++)
  {
    UISelectItem selectItem  = new UISelectItem();
    selectItem.setItemLabel("Item " + i);
    selectItem.setItemValue("" + i);
    menu.getChildren().add(selectItem);
  }

  UIViewRoot root = createTestTree(menu, "testRISelectOneMenu");
  renderRoot(root);

  root = createTestTree(menu, "testRISelectOneNavigation2");
  renderRoot(root);
}
 
Example 9
Project: myfaces-trinidad   File: GenericEntry.java   View source code 6 votes vote down vote up
@Override
public void renderView(
  FacesContext context,
  UIViewRoot   viewToRender) throws IOException, FacesException
{
  String entryKey = (String) context.getExternalContext().getRequestParameterMap().get(__ENTRY_KEY_PARAM);
  if (entryKey == null)
  {
    RequestContext requestContext = RequestContext.getCurrentInstance();
    if (requestContext != null)
    {
      Object o = requestContext.getPageFlowScope().get(__ENTRY_KEY_PARAM);
      if (o != null)
        entryKey = o.toString();
    }
  }

  service(context,entryKey);
}
 
Example 10
Project: myfaces-trinidad   File: FacesTestCase.java   View source code 6 votes vote down vote up
@Override
protected void setUp() throws Exception
{
  super.setUp();
  FacesContext oldFacesContext = facesContext;
  UIViewRoot oldViewRoot = oldFacesContext.getViewRoot();
  oldFacesContext.release();
  facesContext = new MockFacesContext12(externalContext,
                                        lifecycle,
                                        application);
  facesContext.setViewRoot(oldViewRoot);
  facesContext.setApplication(application);

  facesContext.getViewRoot().setRenderKitId("org.apache.myfaces.trinidad.core"); 
  RenderKitFactory renderKitFactory = (RenderKitFactory)
  FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
  Mock mockRenderKitty = mock(RenderKit.class);
  RenderKit renderKit = (RenderKit) mockRenderKitty.proxy();
  _mockRenderKit = new MockRenderKitWrapper(mockRenderKitty, renderKit);
  renderKitFactory.addRenderKit("org.apache.myfaces.trinidad.core", renderKit);
}
 
Example 11
Project: myfaces-trinidad   File: CoreRenderer.java   View source code 6 votes vote down vote up
/**
 * Returns true if the component should render an ID.  Components
 * that deliver events should always return "true".
 */
// TODO Is this a bottleneck?  If so, optimize!
protected boolean shouldRenderId(
  FacesContext context,
  UIComponent component)
{
  String id = component.getId();

  // Otherwise, if ID isn't set, don't bother
  if (id == null)
    return false;

  // ... or if the ID was generated, don't bother
  if (id.startsWith(UIViewRoot.UNIQUE_ID_PREFIX))
    return false;

  return true;
}
 
Example 12
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testRISelectOneRadio() throws IOException
{
  //
  HtmlSelectOneRadio radio = new HtmlSelectOneRadio();
  radio.setValue(new Integer(2));
  for (int i = 0 ; i < 10; i++)
  {
    UISelectItem selectItem  = new UISelectItem();
    selectItem.setItemLabel("Item " + i);
    selectItem.setItemValue("" + i);
    radio.getChildren().add(selectItem);
  }

  UIViewRoot root = createTestTree(radio, "testRISelectOneRadio");
  renderRoot(root);

  root = createTestTree(radio, "testRISelectOneRadio2");
  renderRoot(root);
}
 
Example 13
Project: myfaces-trinidad   File: ForEachTag.java   View source code 6 votes vote down vote up
static void installListener(
  FacesContext facesContext)
{
  UIViewRoot viewRoot = facesContext.getViewRoot();

  // See if the phase listener has already been added (only add it once)
  Map<String, Object> viewAttrs = viewRoot.getAttributes();
  if (!viewAttrs.containsKey(_PL_KEY))
  {
    PhaseListener newPhaseListener = new CleanupPhaseListener();
    viewRoot.addPhaseListener(newPhaseListener);

    viewAttrs.put(_PL_KEY, Boolean.TRUE);

    _LOG.finer("Cleanup phase listener has been installed");
  }
  else
  {
    _LOG.finest("Cleanup phase listener has already been installed on the current view");
  }
}
 
Example 14
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testPanelGroupPerf() throws IOException
{
  CorePanelGroupLayout group = new CorePanelGroupLayout();
  group.setLayout(CorePanelGroupLayout.LAYOUT_VERTICAL);
  for (int i = 0; i < 8; i++)
  {
    /*
    CoreOutputText out = _createCoreOutputText();
    out.setValue("Plain value");
    group.getChildren().add(out);*/
    group.getChildren().add(new NullComp());
  }

  UIViewRoot root = createTestTree(group, "testPanelGroup()");
  renderRoot(root);

  root = createTestTree(group, "testPanelGroup() 2");
  renderRoot(root);
}
 
Example 15
Project: myfaces-trinidad   File: DialogServiceImpl.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void pushView(UIViewRoot viewRoot)
{
  FacesContext context = _getFacesContext();
  Object savedOld = StateManagerImpl.saveViewRoot(context, viewRoot);

  List<Object> list = (List<Object>) _getPageFlowScope().get(_PUSHED_VIEWS_KEY);
  if (list == null)
    list = new ArrayList<Object>(1);
  else
  {
    List<Object> tmp = new ArrayList<Object>(list.size() + 1);
    tmp.addAll(list);
    list = tmp;
  }

  list.add(savedOld);
  _getPageFlowScope().put(_PUSHED_VIEWS_KEY, list);

  _LOG.fine("Pushed view {0}", viewRoot.getViewId());
}
 
Example 16
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testSelectOneRadio() throws IOException
{
  CoreSelectOneRadio radio = new CoreSelectOneRadio();
  radio.setSimple(true);
  radio.setValue(new Integer(2));
  for (int i = 0 ; i < 10; i++)
  {
    UISelectItem selectItem  = new UISelectItem();
    selectItem.setItemLabel("Item " + i);
    selectItem.setItemValue(new Integer(i));
    radio.getChildren().add(selectItem);
  }

  UIViewRoot root = createTestTree(radio, "testSelectOneRadio");
  renderRoot(root);

  root = createTestTree(radio, "testSelectOneRadio2");
  renderRoot(root);
}
 
Example 17
Project: myfaces-trinidad   File: SkinPregenerationService.java   View source code 6 votes vote down vote up
@Override
public void renderView(FacesContext context, UIViewRoot viewToRender)
  throws IOException, FacesException
{
  if (!isEnabled())
  {
    _sendPregenerationDisabledError(context);
    return;
  }
  
  long duration = _pregenerateSkin(context);    
  
  if (!context.getResponseComplete())
  {
    _renderResponse(context, duration);
  }
}
 
Example 18
Project: myfaces-trinidad   File: RenderKitPerfTestCase.java   View source code 6 votes vote down vote up
@SuppressWarnings("unchecked")
protected UIViewRoot createTestTree(
             UIComponent compToTest, String testName, int count)
  throws IOException
{
  if (_fileWriter != null)
  {
    _fileWriter.write("\nRunning test " + testName + "\n");
    _fileWriter.write("----------------------------------\n");
  }
  UIViewRoot root = RenderKitBootstrap.createUIViewRoot(_facesContext);
  root.setRenderKitId(getRenderKitId());

  CoreDocument doc = new CoreDocument();
  doc.setId("docId");
  root.getChildren().add(doc);
  CoreForm form = new CoreForm();
  form.setId("formId");
  doc.getChildren().add(form);

  PerfComp perfer = new PerfComp(count, testName);
  form.getChildren().add(perfer);
  perfer.getChildren().add(compToTest);

  return root;
}
 
Example 19
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 6 votes vote down vote up
public void testRIManyInputAttributes() throws IOException
{
  HtmlInputText out = new HtmlInputText();
  out.setValue("Plain value");
  out.setId("OutId");
  out.setTitle("Title");
  out.setStyleClass("Style Class");
  out.setOnclick("on click");

  out.setOnclick("on click");
  out.setOndblclick("on dblclick");
  out.setOnkeydown("on keydown");
  out.setOnkeyup("on keyup");
  out.setOnkeypress("on keypress ");
  out.setOnmousedown("on mousedown");
  out.setOnmousemove("on mousemove");
  out.setOnmouseout("on mouseout ");
  out.setOnmouseover("on mouseover ");
  out.setOnmouseup("on mouseup ");

  UIViewRoot root = createTestTree(out, "testRIManyInputAttributes()");
  renderRoot(root);

  root = createTestTree(out, "testRIManyInputAttributes() 2");
  renderRoot(root);
}
 
Example 20
Project: Mastering-Java-EE-Development-with-WildFly   File: JSFUtil.java   View source code 5 votes vote down vote up
public static void removeComponent(String componentId) {
	UIViewRoot root = getCurrentInstance().getViewRoot();
	UIComponent component = root.findComponent(componentId);

	if (component != null) {
		UIComponent parent = component.getParent();
		parent.getChildren().remove(component);
	}
}
 
Example 21
Project: Mastering-Java-EE-Development-with-WildFly   File: JSFUtil.java   View source code 5 votes vote down vote up
public static String getBundleMessage(String bundleName, String messageKey) {
	String bundleMessage = null;

	FacesContext ctx = getCurrentInstance();
	UIViewRoot uiRoot = ctx.getViewRoot();
	Locale locale = uiRoot.getLocale();
	ClassLoader ldr = currentThread().getContextClassLoader();
	ResourceBundle bundle = getBundle(bundleName, locale, ldr);

	bundleMessage = bundle.getString(messageKey);

	return bundleMessage;
}
 
Example 22
Project: Mastering-Java-EE-Development-with-WildFly   File: ForumUtil.java   View source code 5 votes vote down vote up
private static ToHTMLRenderer getToHTMLRenderer(Object req) {
	ToHTMLRenderer renderer = null;
	if (renderer == null) {

		FacesContext ctx = getCurrentInstance();
		UIViewRoot uiRoot = ctx.getViewRoot();
		Locale locale = uiRoot.getLocale();
		ClassLoader ldr = currentThread().getContextClassLoader();
		ResourceBundle bundle = getBundle("ResourceJSF", locale, ldr);

		ToHTMLConfig config = new ToHTMLConfig();
		renderer = new ToHTMLRenderer(config, bundle);
	}
	return renderer;
}
 
Example 23
Project: myfaces-trinidad   File: CoreRenderKitTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected UIComponent populateDefaultComponentTree(
  UIViewRoot  root,
  TestScript  script)
{
  String componentType =
         script.getDefinition().getComponentInfo().componentType;

  if ("org.apache.myfaces.trinidad.HtmlHtml".equals(componentType))
  {
    return root;
  }

  if (_HTML_COMPONENTS.contains(componentType))
  {
    HtmlHtml html = new HtmlHtml();
    html.setId("htmlId");
    root.getChildren().add(html);
    return html;
  }
  else
  {
    CoreDocument doc = new CoreDocument();
    doc.setId("docId");
    root.getChildren().add(doc);
    CoreForm form = new CoreForm();
    form.setId("formId");
    if (script.getDefinition().isUsesUpload())
      form.setUsesUpload(true);
    doc.getChildren().add(form);
    return form;
  }
}
 
Example 24
Project: oscm   File: TemplateBeanTest.java   View source code 5 votes vote down vote up
/**
 * Init and return testing bean
 */
private TemplateBean getTestBean() throws Exception {
    InitialContext context = new InitialContext();
    context.bind(APPTemplateService.JNDI_NAME, templateService);

    templateService = new APPTemplateServiceMockup();
    facesContext = Mockito.mock(FacesContext.class);
    externalContext = Mockito.mock(ExternalContext.class);
    httpSession = Mockito.mock(HttpSession.class);
    application = Mockito.mock(Application.class);
    controllerAccess = Mockito.mock(ControllerAccess.class);
    viewRoot = Mockito.mock(UIViewRoot.class);

    Mockito.when(facesContext.getExternalContext())
            .thenReturn(externalContext);
    Mockito.when(facesContext.getApplication()).thenReturn(application);
    Mockito.when(externalContext.getSession(Matchers.anyBoolean()))
            .thenReturn(httpSession);
    Mockito.when(httpSession.getAttribute(Matchers.anyString()))
            .thenReturn("aValue");
    Mockito.when(facesContext.getViewRoot()).thenReturn(viewRoot);
    Mockito.when(viewRoot.getLocale()).thenReturn(new Locale("en"));
    Mockito.when(controllerAccess.getControllerId())
            .thenReturn("ess.common");

    // Init testing bean
    TemplateBean bean = new TemplateBean() {

        @Override
        protected FacesContext getContext() {
            return facesContext;
        }
    };
    bean.setTemplateService(templateService);
    bean.setControllerAccess(controllerAccess);
    return bean;
}
 
Example 25
Project: oscm   File: PhaseLoggerListener.java   View source code 5 votes vote down vote up
public void beforePhase(PhaseEvent event) {
    if (logger.isDebugLoggingEnabled()) {
        List<FacesMessage> msgs = event.getFacesContext().getMessageList();
        UIViewRoot viewRoot = event.getFacesContext().getViewRoot();
        if (viewRoot != null) {
            logger.logDebug("------------------\nSTART PHASE: " + viewRoot.getViewId());
            for (FacesMessage msg : msgs) {
                logger.logDebug("Message " + msg.getSummary() + " :: " + msg.getDetail());
            }
        }
    }
}
 
Example 26
Project: myfaces-trinidad   File: ComponentReferenceTest.java   View source code 5 votes vote down vote up
public void testCustomFacet()
{
  UIViewRoot root = facesContext.getViewRoot();
  root.setId("root");
  UIForm form = new UIForm(); form.setId("form");
  UINamingContainer nc1 = new UINamingContainer(); nc1.setId("nc1");
  UINamingContainer nc2 = new UINamingContainer(); nc2.setId("nc2");
  UINamingContainer nc3 = new UINamingContainer(); nc3.setId("nc3");
  UIPanel panel = new UIPanel(); panel.setId("panel");
  UIInput input = new UIInput(); input.setId("input1");

  // build the Tree...
  panel.getFacets().put("fancyFacet", input);
  nc3.getChildren().add(panel);
  nc2.getChildren().add(new UIOutput());
  nc2.getChildren().add(new UIOutput());
  nc2.getChildren().add(nc3);
  nc1.getChildren().add(nc2);
  form.getChildren().add(new UIOutput());
  form.getChildren().add(new UIOutput());
  form.getChildren().add(new UIOutput());
  form.getChildren().add(nc1);
  root.getChildren().add(new UIOutput());
  root.getChildren().add(form);

  // Get the ComponentReference util
  ComponentReference<UIInput> uiRef = ComponentReference.newUIComponentReference(input);

  // find the component...
  UIInput referencedComp = uiRef.getComponent();
  assertEquals(input, referencedComp);
  
  // find it again!
  assertEquals(input, uiRef.getComponent());
}
 
Example 27
Project: myfaces-trinidad   File: UIXTableTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doTestApplyRequestValues(
  FacesContext context,
  UIViewRoot   root,
  UIComponent  component)
{
  root.getChildren().add(component);
  root.processDecodes(context);
}
 
Example 28
Project: oscm   File: AddGroupCtrlTest.java   View source code 5 votes vote down vote up
@Before
public void setup() throws Exception {
    UIViewRoot viewRoot = mock(UIViewRoot.class);
    tableStatus = mock(TableState.class);
    given(viewRoot.getLocale()).willReturn(Locale.ENGLISH);
    new FacesContextStub(Locale.ENGLISH).setViewRoot(viewRoot);
    searchServiceInternal = mock(SearchServiceInternal.class);
    userGroupService = mock(UserGroupService.class);
    exContext = mock(ExternalContext.class);
    model = spy(new ManageGroupModel());
    ctrl = spy(new AddGroupCtrl());
    ctrl.setUserGroupService(userGroupService);
    ctrl.setSearchServiceInternal(searchServiceInternal);
    ctrl.setManageGroupModel(model);
    ctrl.setTableState(tableStatus);
    ctrl.setUi(spy(new UiDelegate() {
        @Override
        public void handleException(SaaSApplicationException ex) {

        }

        @Override
        public String getText(String key, Object... params) {
            return "modalName";
        }

        @Override
        public ExternalContext getExternalContext() {
            return exContext;
        }
    }));

}
 
Example 29
Project: myfaces-trinidad   File: XhtmlLafUtilsTest.java   View source code 5 votes vote down vote up
protected void setUp() throws Exception
{
  RequestContext rc = RequestContext.getCurrentInstance();
  if (rc != null)
  {
    rc.release();
  }
  
  _bootstrap = new RenderKitBootstrap();
  _bootstrap.init();
  
  RenderKitBootstrap.clearFactories();
  RenderKitBootstrap.setFactories(_bootstrap.getFacesConfigInfo());

  _facesContext = new MFacesContext(MApplication.sharedInstance(), true);
  _requestContext = new MRequestContext();
  _requestContext.setSkinFamily("minimal");
  _requestContext.setAgent(RenderKitBootstrap.getGeckoAgent());
  _requestContext.setRightToLeft(false);
  _requestContext.setAccessibilityMode(null);
  _facesContext.getExternalContext().getApplicationMap().put(TrinidadSkinProvider.TRINDIAD_SKIN_PROVIDER_KEY, new TrinidadSkinProvider());
  _facesContext.getExternalContext().getApplicationMap().put(ExternalSkinProvider.EXTERNAL_SKIN_PROVIDER_KEY, new ExternalSkinProvider());
  _facesContext.getExternalContext().getApplicationMap().put(SkinProvider.SKIN_PROVIDER_INSTANCE_KEY, new SkinProviderRegistry());

  UIViewRoot root = RenderKitBootstrap.createUIViewRoot(_facesContext);
  root.setRenderKitId("org.apache.myfaces.trinidad.core");
  root.setLocale(Locale.getDefault());
  _facesContext.setViewRoot(root);
  
  try
  {
    new CoreRenderingContext();
  }
  catch (IllegalStateException ex)
  {
    return;
  }
}
 
Example 30
Project: myfaces-trinidad   File: UIXSwitcherTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doTestProcessValidations(
  FacesContext context,
  UIViewRoot   root,
  UIComponent  component)
{
  
  Mock mockUIComponent = createMockUIComponent();//mock(UIComponent.class);
  UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
  
  // JavaServer Faces 1.0 Specification, section 2.2.2
  // During the apply-request-values phase,
  // only the processDecodes lifecycle method may be called.
  mockUIComponent.expects(once()).method("processValidators");

  // These children will never get called
  Mock mockBarChild = createMockUIComponent();
  UIComponent barChild = (UIComponent) mockBarChild.proxy();
  
  Mock mockOrdinaryChild = createMockUIComponent();
  UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy(); 

  // construct the UIComponent tree and
  // execute the apply-request-values lifecycle phase
  root.getChildren().add(component);
  component.getFacets().put("foo", fooChild);
  component.getFacets().put("bar", barChild);
  component.getChildren().add(ordinaryChild);
  root.processValidators(context);

  mockUIComponent.verify();
  mockBarChild.verify();
  mockOrdinaryChild.verify();
}
 
Example 31
Project: oscm   File: ServiceListingBeanTest.java   View source code 5 votes vote down vote up
@Before
public void setup() throws Exception {
    UIViewRoot viewRoot = mock(UIViewRoot.class);
    given(viewRoot.getLocale()).willReturn(Locale.ENGLISH);
    new FacesContextStub(Locale.ENGLISH).setViewRoot(viewRoot);

    initBeans();
}
 
Example 32
Project: oscm   File: SkinBeanTest.java   View source code 5 votes vote down vote up
@Before
public void before() {
    // mock the BrandService' get getMarketplaceStage() method
    brandServiceMock = mock(BrandService.class);
    when(brandServiceMock.getMarketplaceStage(anyString(), anyString()))
            .thenReturn(stageContent);

    // mock the HttpSession's getAttribute() method
    httpSessionMock = mock(HttpSession.class);
    when(httpSessionMock.getAttribute(anyString())).thenReturn(null);

    // mock the HttpServletRequest's getSession() method
    HttpServletRequest httpServletRequestMock = mock(HttpServletRequest.class);
    when(httpServletRequestMock.getSession()).thenReturn(httpSessionMock);

    // mock the ExternalContext's getRequest() method
    ExternalContext externalContextMock = mock(ExternalContext.class);
    when(externalContextMock.getRequest()).thenReturn(
            httpServletRequestMock);

    // mock the UIViewRoot's getLocale() method
    viewRootMock = mock(UIViewRoot.class);
    when(viewRootMock.getLocale()).thenReturn(Locale.FRANCE);

    // mock the FacesContext's getExternalContext() and getViewRoot()
    // methods
    final FacesContext facesContextMock = mock(FacesContext.class);
    when(facesContextMock.getExternalContext()).thenReturn(
            externalContextMock);
    when(facesContextMock.getViewRoot()).thenReturn(viewRootMock);

    // spy the SkinBean to only partial mock - overriding the methods below
    skinBean = spy(new SkinBean());
    doReturn(brandServiceMock).when(skinBean).getBrandManagementService();
    doReturn(facesContextMock).when(skinBean).getFacesContext();
    doReturn(httpServletRequestMock).when(skinBean).getRequest();
}
 
Example 33
Project: NICON   File: RelatorioBean.java   View source code 5 votes vote down vote up
public void teste() {
    FacesContext context = FacesContext.getCurrentInstance();
    UIViewRoot viewRoot = context.getViewRoot();
    DataTable dataTable = (DataTable) viewRoot.findComponent("Rel:tabelaRelatorio");
    dataTable.setValue(null);
    dataTable.setColumns(null);
    Validacao.AtualizarCompoente("Rel", "tabelaRelatorio");
    String tipoRelatorio = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("relatorio");
    relatorio.setTipoRelatorio(tipoRelatorio);
}
 
Example 34
Project: myfaces-trinidad   File: ComponentReferenceTest.java   View source code 5 votes vote down vote up
public void testCustomFacetWithFind()
{
  UIViewRoot root = new UIViewRoot();
  root.setId("root");
  UIForm form = new UIForm(); form.setId("form");
  UINamingContainer nc1 = new UINamingContainer(); nc1.setId("nc1");
  UINamingContainer nc2 = new UINamingContainer(); nc2.setId("nc2");
  UINamingContainer nc3 = new UINamingContainer(); nc3.setId("nc3");
  UIPanel panel = new UIPanel(); panel.setId("panel");
  UIInput input = new UIInput(); input.setId("input1");

  // build the Tree...
  panel.getFacets().put("fancyFacet", input);
  panel.getChildren().add(input);
  nc3.getChildren().add(panel);
  nc2.getChildren().add(new UIOutput());
  nc2.getChildren().add(new UIOutput());
  nc2.getChildren().add(nc3);
  nc1.getChildren().add(nc2);
  form.getChildren().add(new UIOutput());
  form.getChildren().add(new UIOutput());
  form.getChildren().add(new UIOutput());
  form.getChildren().add(nc1);
  root.getChildren().add(new UIOutput());
  root.getChildren().add(form);
  
  facesContext.setViewRoot(root);

  // Get the ComponentReference util
  ComponentReference<UIInput> uiRef = ComponentReference.newUIComponentReference(input);

  // find the component...
  UIInput referencedComp = uiRef.getComponent();
  assertEquals(input, referencedComp);

  // find it again!
  assertEquals(input, uiRef.getComponent());

}
 
Example 35
Project: myfaces-trinidad   File: UIXSwitcherTest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doTestUpdateModelValues(
  FacesContext context,
  UIViewRoot   root,
  UIComponent  component)
{
  Mock mockUIComponent = createMockUIComponent();
  UIComponent fooChild = (UIComponent) mockUIComponent.proxy();
  // JavaServer Faces 1.0 Specification, section 2.2.2
  // During the apply-request-values phase,
  // only the processDecodes lifecycle method may be called.
  mockUIComponent.expects(once()).method("processUpdates");

  // These children will never get called
  Mock mockBarChild = createMockUIComponent();
  UIComponent barChild = (UIComponent) mockBarChild.proxy();
  
  Mock mockOrdinaryChild = createMockUIComponent();
  UIComponent ordinaryChild = (UIComponent) mockOrdinaryChild.proxy();

  // construct the UIComponent tree and
  // execute the apply-request-values lifecycle phase
  root.getChildren().add(component);
  component.getFacets().put("foo", fooChild);
  component.getFacets().put("bar", barChild);
  component.getChildren().add(ordinaryChild);
  root.processUpdates(context);

  mockUIComponent.verify();
  mockBarChild.verify();
  mockOrdinaryChild.verify();
}
 
Example 36
Project: myfaces-trinidad   File: ComponentReference.java   View source code 5 votes vote down vote up
protected static UIViewRoot getUIViewRoot(UIComponent component)
{
  // stash the component and parent , for the loop
  UIComponent currComponent = component;
  UIComponent currParent = currComponent.getParent();

  while(currParent != null)
  {
    currComponent = currParent;
    currParent = currParent.getParent();
  }
  
  return (currComponent instanceof UIViewRoot) ? (UIViewRoot)currComponent : null;
}
 
Example 37
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void testRITable() throws IOException
{
  HtmlDataTable table = new HtmlDataTable();
  ArrayList<Integer> l = new ArrayList<Integer>();
  for (int i = 0 ; i < 10; i++)
    l.add(new Integer(i));
  
  table.setValue(l);
  table.setStyleClass("TableContent");
  table.setHeaderClass("af_column_header-text SomeBorderStyle");
  table.setColumnClasses("af_column_cell-text OraTableBorder1111");

  for (int i = 0 ; i < 3; i++)
  {
    UIColumn col = new UIColumn();
    /*
    HtmlOutputText header = new HtmlOutputText();
    header.setValue("Header " + i);
    col.setHeader(header);
    //HtmlOutputText text = new HtmlOutputText();
    HtmlInputText text = new HtmlInputText();
    text.setValue("Column " + i);
    col.getChildren().add(text);
    */

    col.setHeader(new NullComp());
    col.getChildren().add(new NullComp());
    table.getChildren().add(col);
  }

  UIViewRoot root = createTestTree(table, "testRITable()", 500);
  renderRoot(root);
}
 
Example 38
Project: myfaces-trinidad   File: CoreRenderKit.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public boolean shortCircuitRenderView(
  FacesContext context) throws IOException
{
  ExternalContext ec = context.getExternalContext();
  if (isPartialRequest(ec))
  {
    Map<String, Object> requestMap = ec.getRequestMap();

    UIViewRoot originalRoot = (UIViewRoot) requestMap.get(
                       TrinidadPhaseListener.INITIAL_VIEW_ROOT_KEY);
    // If we're doing a partial update, and the page has changed, switch to a
    // full page context.
    if (context.getViewRoot() != originalRoot)
    {
      ViewHandler vh = context.getApplication().getViewHandler();

      String viewId = context.getViewRoot().getViewId();
      String redirect = vh.getActionURL(context, viewId);
      String encodedRedirect = ec.encodeActionURL(redirect);
      ec.redirect(encodedRedirect);
      if (_LOG.isFine())
      {
        _LOG.fine("Page navigation to {0} happened during a PPR request " +
                  "on {1};  Apache Trinidad is forcing a redirect.",
                  new String[]{viewId, originalRoot.getViewId()});
      }

      return true;
    }
  }

  // =-=AEW We could look for PPR requests that have no
  // requested partial targets, in particular requests
  // that simply need to launch a dialog.
  return false;
}
 
Example 39
Project: myfaces-trinidad   File: DialogRequest.java   View source code 5 votes vote down vote up
@SuppressWarnings("unchecked")
public DialogRequest(
  UIViewRoot         targetRoot,
  String             clientId,
  String             formId,
  Map<String,Object> dialogProperties,
  boolean            usePopup
  )
{
  _clientId = clientId;
  _formId   = formId;
  _usePopup = usePopup;

  if (dialogProperties == null)
    dialogProperties = Collections.emptyMap();

  Object width = dialogProperties.get("width");
  Object height = dialogProperties.get("height");

  FacesContext context = FacesContext.getCurrentInstance();

  String url;
  
  if (usePopup)
  {
    url = context.getApplication().getViewHandler().getActionURL(context, targetRoot.getViewId());
  }
  else
  {
    url = FredJSP.getRedirectURL(context,
                                targetRoot,
                                CoreRenderer.toString(width),
                                CoreRenderer.toString(height));
  }
  
  PageFlowScopeProvider provider = RequestContext.getCurrentInstance().getPageFlowScopeProvider();
  _url = context.getExternalContext().encodeActionURL(provider.encodeDialogPageFlowScopeURL(context, url));
  
  _dialogProperties  = dialogProperties;
}
 
Example 40
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   View source code 5 votes vote down vote up
public void notestSelectRangeChoicePerf() throws IOException
{
  CoreSelectRangeChoiceBar bar = new CoreSelectRangeChoiceBar();
  bar.setValue(new MVariableResolver.BigList());
  bar.setRows(30);

  UIViewRoot root = createTestTree(bar, "testSelectRangeChoiceBar");
  renderRoot(root);
}