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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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);
}
 
Example 41
Project: myfaces-trinidad   File: UIXTableTest.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void doTestUpdateModelValues(
  FacesContext context,
  UIViewRoot   root,
  UIComponent  component)
{
  root.getChildren().add(component);
  root.processUpdates(context);
}
 
Example 42
Project: myfaces-trinidad   File: PreferencesProxy.java   Source Code and License 5 votes vote down vote up
private String _getViewId(FacesContext context)
{
  UIViewRoot viewRoot = context.getViewRoot();
  if (viewRoot != null)
    return viewRoot.getViewId();
  
  return null;
}
 
Example 43
Project: myfaces-trinidad   File: InternalViewHandlingStrategy.java   Source Code and License 5 votes vote down vote up
@Override
public UIViewRoot createView(FacesContext context, String viewId)
{
  UIViewRoot root = _finder.getInternalView(context, viewId).createView(context, viewId);
  if (root != null)
    return root;
  
  return _defaultCreateView(context, viewId);
}
 
Example 44
Project: myfaces-trinidad   File: UIComponentTestCase.java   Source Code and License 5 votes vote down vote up
/**
 * Tests the update-model-values lifecycle phase.
 */
protected void doTestUpdateModelValues(
  UIViewRoot  root,
  UIComponent component)
{

  Mock mockRenderkit = getMockRenderKitWrapper().getMock();

  Mock mockRenderer = mock(Renderer.class);
  Renderer renderer = (Renderer) mockRenderer.proxy();
  mockRenderkit.stubs().method("getRenderer").will(returnValue(renderer));

  Mock mockBinding = mock(ValueBinding.class);
  ValueBinding binding = (ValueBinding) mockBinding.proxy();

  setCurrentContext(facesContext);

  // if the component is an EditableValueHolder, then the value binding
  // must be updated with the new value before this phase completes.
  if (component instanceof EditableValueHolder)
  {
    EditableValueHolder editable = (EditableValueHolder)component;
    component.setValueBinding("value", binding);
    editable.setValue("newValue");
    mockBinding.expects(atLeastOnce()).method("setValue").with(eq(facesContext), eq("newValue"));

    assertEquals(true, editable.isLocalValueSet());
  }

  doTestUpdateModelValues(facesContext, root, component);

  setCurrentContext(null);

  mockRenderer.verify();
  mockBinding.verify();
}
 
Example 45
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   Source Code and License 5 votes vote down vote up
public void testInputHidden() throws IOException
{
  CoreInputHidden cih = new CoreInputHidden();
  cih.setValue("value");

  UIViewRoot root = createTestTree(cih, "testInputHidden");
  renderRoot(root);
}
 
Example 46
Project: myfaces-trinidad   File: StateManagerImpl.java   Source Code and License 5 votes vote down vote up
/**
 * Save a view root.  Doesn't return a SerializedView because
 * SerializedView is a non-static inner class, and this needs
 * to be a static method.
 */
static public Object saveViewRoot(
  FacesContext context,
  UIViewRoot   root)
{
  _removeTransientComponents(root);

  Object structure = new Structure(root);
  Object state = root.processSaveState(context);

  return new PageState(context,
                       _getViewRootStateRefFactory(context, RequestContext.getCurrentInstance()),
                       new Object[]{structure, state},
                       root);
}
 
Example 47
Project: myfaces-trinidad   File: TestInternalView.java   Source Code and License 5 votes vote down vote up
/**
 * Renders the view.
 */
@Override
public void renderView(
  FacesContext context, 
  UIViewRoot   viewToRender) throws IOException, FacesException
{
  ViewDeclarationLanguageFactoryImplTest.__internalViewCalled = "render";
}
 
Example 48
Project: myfaces-trinidad   File: ComponentReference.java   Source Code and License 5 votes vote down vote up
/**
* This method will use a calculated "component path" to walk down to the <code>UIComponent</code>
* that is referenced by this class. If the component can not be found, the <code>getComponent()</code>
* will return <code>null</code>. 
* 
* @return the referenced <code>UIComponent</code> or <code>null</code> if it can not be found.
* @throws IllegalStateException if the component used to create the
* ComponentReference is not in the component tree or does <b>not</b> have an <code>Id</code>
* @see ComponentReference#newUIComponentReference(UIComponent)
*/
@SuppressWarnings("unchecked")
public final T getComponent()
{
  // get the scopedId, calculating it if necessary
  String scopedId = getScopedId();
      
  UIComponent foundComponent = null;

  // In order to find the component with its
  // calculated path, we need to start at the ViewRoot;
  UIViewRoot root = FacesContext.getCurrentInstance().getViewRoot();

  List<Object> componentPath = _componentPath;
  
  if (componentPath != null) 
  {
    // Walk down the component tree, to the component we are looking for.
    // We start at the ViewRoot and use the previous calculated "component path"
    foundComponent = _walkPathToComponent(root, componentPath);
  }

  // Check if we really found it with the previously created "component path"
  if (foundComponent == null || (!getComponentId().equals(foundComponent.getId())))
  {
    // OK, we were not lucky with the calculated "component path", let's
    // see if we can find it by using the "scoped ID" and the regular 
    // findComponent();
    foundComponent = root.findComponent(scopedId);

    // was the regular findComponent() successful ?
    if (foundComponent != null)
    {        
      // OK, now let's rebuild the path
      _componentPath = calculateComponentPath(foundComponent);
    }
  }

  return (T)foundComponent;
}
 
Example 49
Project: myfaces-trinidad   File: ViewHandlerImpl.java   Source Code and License 5 votes vote down vote up
@Override
public UIViewRoot createView(FacesContext context, String viewId)
{
  _checkSkinPregeneration(context, viewId);

  _initIfNeeded(context);

  if (_isTimestampCheckEnabled(context, viewId))
  {
    try
    {
      // Check the timestamp on the physical path
      String path = _getPath(viewId);
      synchronized (_timestamps)
      {
        Long ts = _timestamps.get(path);
        if (ts != _NOT_FOUND)
        {
          URL url = context.getExternalContext().getResource(path);
          Long modified = _getLastModified(url);
          _timestamps.put(path, modified);
        }
      }
    }
    catch (IOException e)
    {
      _LOG.severe(e);
    }
  }

  return super.createView(context, viewId);
}
 
Example 50
Project: myfaces-trinidad   File: UIComponentTestCase.java   Source Code and License 5 votes vote down vote up
/**
 * Tests the apply-request-values lifecycle phase.
 */
protected void doTestProcessValidations(
  UIComponent component,
  Object      submittedValue,
  Object      convertedValue)
{
  UIViewRoot root = new UIViewRoot();
  doTestProcessValidations(root, component, submittedValue, convertedValue);
}
 
Example 51
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   Source Code and License 5 votes vote down vote up
public void testRISimplePerf() throws IOException
{
  HtmlOutputText out = _createHtmlOutputText();
  out.setValue("Plain value");
  UIViewRoot root = createTestTree(out, "testRISimplePerf()");
  renderRoot(root);

  root = createTestTree(out, "testRISimplePerf() 2");
  renderRoot(root);
}
 
Example 52
Project: myfaces-trinidad   File: CoreRenderKitPerf.java   Source Code and License 5 votes vote down vote up
public void notestSelectInputDate() throws IOException
{
  CoreInputDate date = new CoreInputDate();
  date.setLabel("Label");

  UIViewRoot root = createTestTree(date, "testSelectInputDate");
  renderRoot(root);
}
 
Example 53
Project: myfaces-trinidad   File: UIComponentTestCase.java   Source Code and License 5 votes vote down vote up
/**
 * Tests the apply-request-values lifecycle phase.
 */
protected void doTestApplyRequestValues(
  UIViewRoot  root,
  UIComponent component)
{

  Mock mockRenderKitFactory = mock(RenderKitFactory.class);

  Mock mockRenderkit = getMockRenderKitWrapper().getMock();
  RenderKit renderkit = getMockRenderKitWrapper().getRenderKit();

  Mock mockRenderer = mock(Renderer.class);
  Renderer renderer = (Renderer) mockRenderer.proxy();

  mockRenderKitFactory.stubs().method("getRenderKit").will(returnValue(renderkit));
  mockRenderkit.stubs().method("getRenderer").will(returnValue(renderer));

  if (isRendererUsed() && component.isRendered())
  {
    mockRenderer.expects(once()).method("decode");
  }
  else
  {
    mockRenderer.expects(never()).method("decode");
  }

  try
  {
    setCurrentContext(facesContext);
    doTestApplyRequestValues(facesContext, root, component);
  }
  finally
  {
    setCurrentContext(null);
  }

  mockRenderKitFactory.verify();
  mockRenderkit.verify();
  mockRenderer.verify();
}
 
Example 54
Project: myfaces-trinidad   File: DialogServiceImpl.java   Source Code and License 5 votes vote down vote up
@Override
public void queueLaunchEvent(UIViewRoot viewRoot)
{
  UIComponent source = getCurrentLaunchSource();
  if (source == null)
  {
    launchDialog(viewRoot, null, null, false, null);
  }
  else
  {
    (new InternalLaunch(source, viewRoot)).queue();
  }
}
 
Example 55
Project: myfaces-trinidad   File: ComponentReferenceTest.java   Source Code and License 5 votes vote down vote up
public void testUIDataFooterFacet()
{
  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");
  UIData table = new UIData(); table.setId("table1");
  UIInput input = new UIInput(); input.setId("input1");

  // build the Tree...
  table.setFooter(input);
  nc3.getChildren().add(table);
  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);
}
 
Example 56
Project: myfaces-trinidad   File: UIXComponentELTag.java   Source Code and License 5 votes vote down vote up
private String _getScopedId(UIComponent component, UIViewRoot viewRoot)
{
  if (component == null)
  {
    // use tag id if component was not created
    return this.getId();
  }
  else
  {
    return ComponentUtils.getScopedIdForComponent(component, viewRoot);
  }
}
 
Example 57
Project: myfaces-trinidad   File: TokenCacheDebugUtils.java   Source Code and License 5 votes vote down vote up
/**
 * In order to provide human readable information there is a map which 
 * has token to viewId information.
 * 
 * Add the token passed in and associate it in the map with the current view id. 
 * 
 * This method should only be called when debugTokenCache() is true
 */
public static void addTokenToViewIdMap(String token)
{
  if (!_DEBUG_TOKEN_CACHE)
    throw new UnsupportedOperationException(_UNSUPPORTED_OPERATION_MESSAGE);
  
  FacesContext context = FacesContext.getCurrentInstance();
  Map<String,String> tokenToViewIdMap = _getTokenToViewIdMap(context);      
  UIViewRoot root = context.getViewRoot();
  String viewId = root.getViewId();    
  tokenToViewIdMap.put(token, viewId);

  StringBuffer logBuffer = _getLogBuffer(context);
  logBuffer.append("\nADDING ").append(_getTokenToViewIdString(tokenToViewIdMap, token));
}
 
Example 58
Project: myfaces-trinidad   File: MRequestContext.java   Source Code and License 5 votes vote down vote up
@Override
public void launchDialog(
    UIViewRoot dialogRoot,
    Map<String, Object> dialogParameters,
    UIComponent source,
    boolean useWindow,
    Map<String, Object> windowProperties)
{
  throw new UnsupportedOperationException("Should not be called during rendering");
}
 
Example 59
Project: myfaces-trinidad   File: MRequestContext.java   Source Code and License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public Map<String, Object> getViewMap(boolean create)
{
  // Note: replace this method body with a call to UIViewRoot.getViewMap(boolean) when
  // Trinidad is upgraded to use JSF 2.0

  FacesContext facesContext = FacesContext.getCurrentInstance();
  UIViewRoot viewRoot = facesContext.getViewRoot();
  Map<String, Object> viewMap = null;

  if (viewRoot != null)
  {
    Map<String, Object> attrs = viewRoot.getAttributes();

    viewMap = (Map<String, Object>)attrs.get(_VIEW_MAP_KEY);
    if (viewMap == null && create)
    {
      // Note, it is not valid to refer to the request context from outside of the request's
      // thread. As such, synchronization and thread safety is not an issue here.
      // This coincides with the JSF 2.0 code not using syncronization and using the non-thread
      // safe HashMap.
      viewMap = new HashMap<String, Object>();
      attrs.put(_VIEW_MAP_KEY, viewMap);
    }
  }

  return viewMap;
}
 
Example 60
Project: myfaces-trinidad   File: LaunchEvent.java   Source Code and License 5 votes vote down vote up
/**
 * Create a LaunchEvent.
 * @param source the component responsible for launching the dialog
 * @param viewRoot the UIViewRoot to be displayed at the start of
 *   the dialog
 */
public LaunchEvent(UIComponent source,
                   UIViewRoot viewRoot)
{
  super(source);
  _viewRoot = viewRoot;
  _dialogParameters = new HashMap<String, Object>();
  _windowProperties  = new HashMap<String, Object>();

  // LaunchEvents should always be queued for the current phase
  setPhaseId(PhaseId.ANY_PHASE);
}