Search in sources :

Example 1 with UIOutput

use of jakarta.faces.component.UIOutput in project myfaces by apache.

the class HtmlLinkRendererBase method decode.

@Override
public void decode(FacesContext facesContext, UIComponent component) {
    // check for NP
    super.decode(facesContext, component);
    if (component instanceof UICommand) {
        String clientId = component.getClientId(facesContext);
        UIForm form = ComponentUtils.findClosest(UIForm.class, component);
        boolean disabled = HtmlRendererUtils.isDisabled(component);
        // MYFACES-3960 Decode, decode client behavior and queue action event at the end
        boolean activateActionEvent = false;
        if (form != null && !disabled) {
            String reqValue = (String) facesContext.getExternalContext().getRequestParameterMap().get(HtmlRendererUtils.getHiddenCommandLinkFieldName(form, facesContext));
            activateActionEvent = reqValue != null && reqValue.equals(clientId) || HtmlRendererUtils.isPartialOrBehaviorSubmit(facesContext, clientId);
        }
        if (component instanceof ClientBehaviorHolder && !disabled) {
            ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
        }
        if (activateActionEvent) {
            component.queueEvent(new ActionEvent(component));
        }
    } else if (component instanceof UIOutput) {
        // do nothing
        if (component instanceof ClientBehaviorHolder && !HtmlRendererUtils.isDisabled(component)) {
            ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
        }
    } else {
        throw new IllegalArgumentException("Unsupported component class " + component.getClass().getName());
    }
}
Also used : UIOutput(jakarta.faces.component.UIOutput) ActionEvent(jakarta.faces.event.ActionEvent) UICommand(jakarta.faces.component.UICommand) UIForm(jakarta.faces.component.UIForm) ClientBehaviorHolder(jakarta.faces.component.behavior.ClientBehaviorHolder)

Example 2 with UIOutput

use of jakarta.faces.component.UIOutput in project myfaces by apache.

the class MockApplication20 method _handleAttachedResourceDependency.

private void _handleAttachedResourceDependency(FacesContext context, ResourceDependency annotation) {
    // If this annotation is not present on the class in question, no action must be taken.
    if (annotation != null) {
        Application application = context.getApplication();
        // Create a UIOutput instance by passing jakarta.faces.Output. to
        // Application.createComponent(java.lang.String).
        UIOutput output = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
        // Get the annotation instance from the class and obtain the values of the name, library, and
        // target attributes.
        String name = annotation.name();
        if (name != null && name.length() > 0) {
            name = _ELText.parse(getExpressionFactory(), context.getELContext(), name).toString(context.getELContext());
        }
        // Obtain the renderer-type for the resource name by passing name to
        // ResourceHandler.getRendererTypeForResourceName(java.lang.String).
        String rendererType = application.getResourceHandler().getRendererTypeForResourceName(name);
        // Call setRendererType on the UIOutput instance, passing the renderer-type.
        output.setRendererType(rendererType);
        // Obtain the Map of attributes from the UIOutput component by calling UIComponent.getAttributes().
        Map<String, Object> attributes = output.getAttributes();
        // Store the name into the attributes Map under the key "name".
        attributes.put("name", name);
        // If library is the empty string, let library be null.
        String library = annotation.library();
        if (library != null && library.length() > 0) {
            library = _ELText.parse(getExpressionFactory(), context.getELContext(), library).toString(context.getELContext());
            // If library is non-null, store it under the key "library".
            attributes.put("library", library);
        }
        // If target is the empty string, let target be null.
        String target = annotation.target();
        if (target != null && target.length() > 0) {
            target = _ELText.parse(getExpressionFactory(), context.getELContext(), target).toString(context.getELContext());
            // If target is non-null, store it under the key "target".
            attributes.put("target", target);
            context.getViewRoot().addComponentResource(context, output, target);
        } else {
            // Otherwise, if target is null, call
            // UIViewRoot.addComponentResource(jakarta.faces.context.FacesContext,
            // jakarta.faces.component.UIComponent),
            // passing the UIOutput instance as the second argument.
            context.getViewRoot().addComponentResource(context, output);
        }
    }
}
Also used : UIOutput(jakarta.faces.component.UIOutput) Application(jakarta.faces.application.Application)

Example 3 with UIOutput

use of jakarta.faces.component.UIOutput in project myfaces by apache.

the class SearchExpressionImplTest method testResolveClientIds1.

@Test
public void testResolveClientIds1() throws Exception {
    startViewRequest("/search1.xhtml");
    processLifecycleExecute();
    executeBeforeRender();
    executeBuildViewCycle();
    SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
    UIOutput out = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:showName");
    Set<SearchExpressionHint> expressionHints = new HashSet<SearchExpressionHint>();
    expressionHints.add(SearchExpressionHint.IGNORE_NO_RESULT);
    SearchExpressionContext searchContextWithIgnoreNoResult = SearchExpressionContext.createSearchExpressionContext(facesContext, out, expressionHints, null);
    List<String> clientId = handler.resolveClientIds(searchContextWithIgnoreNoResult, "@none");
    Assert.assertTrue(clientId.isEmpty());
    SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(facesContext, out);
    try {
        clientId = handler.resolveClientIds(searchContext, "@none");
        Assert.fail();
    } catch (ComponentNotFoundException e) {
    // No op
    }
}
Also used : ComponentNotFoundException(jakarta.faces.component.search.ComponentNotFoundException) UIOutput(jakarta.faces.component.UIOutput) SearchExpressionHint(jakarta.faces.component.search.SearchExpressionHint) SearchExpressionHandler(jakarta.faces.component.search.SearchExpressionHandler) SearchExpressionContext(jakarta.faces.component.search.SearchExpressionContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with UIOutput

use of jakarta.faces.component.UIOutput in project myfaces by apache.

the class SearchExpressionImplTest method testSearchExpression1.

@Test
public void testSearchExpression1() throws Exception {
    startViewRequest("/search1.xhtml");
    processLifecycleExecute();
    executeBeforeRender();
    executeBuildViewCycle();
    UIOutput out = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:showName");
    SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(facesContext, out);
    Collection<String> list = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "mainForm:showName");
    boolean found = false;
    for (String clientId : list) {
        System.out.println(clientId);
        found = true;
    }
    Assert.assertTrue(found);
    String componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@this").get(0);
    Assert.assertEquals(componentId, "mainForm:showName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@this:@parent:showName").get(0);
    Assert.assertEquals(componentId, "mainForm:showName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "mainForm:table:0:baseText").get(0);
    Assert.assertEquals(componentId, "mainForm:table:0:baseText");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@parent:showName:@parent:showName").get(0);
    Assert.assertEquals(componentId, "mainForm:showName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@form:showName").get(0);
    Assert.assertEquals(componentId, "mainForm:showName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, " @namingcontainer:showName ").get(0);
    Assert.assertEquals(componentId, "mainForm:showName");
    UIOutput name = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:name");
    searchContext = SearchExpressionContext.createSearchExpressionContext(facesContext, name);
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@previous").get(0);
    Assert.assertEquals(componentId, "mainForm:labelName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@next").get(0);
    Assert.assertEquals(componentId, "mainForm:msgName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "@parent:@id(msgName)").get(0);
    Assert.assertEquals(componentId, "mainForm:msgName");
    componentId = facesContext.getApplication().getSearchExpressionHandler().resolveClientIds(searchContext, "topLevelOutputText").get(0);
    Assert.assertEquals(componentId, "topLevelOutputText");
    facesContext.getViewRoot().invokeOnComponent(facesContext, "mainForm:table:3:nested:1:nestedButton", new ContextCallback() {

        @Override
        public void invokeContextCallback(FacesContext context, UIComponent target) {
            SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
            SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(context, target);
            String componentId = handler.resolveClientIds(searchContext, "mainForm:showName").get(0);
            Assert.assertEquals(componentId, "mainForm:showName");
            componentId = handler.resolveClientIds(searchContext, "nested:nestedText").get(0);
            Assert.assertEquals(componentId, "mainForm:table:3:nested:1:nestedText");
            componentId = handler.resolveClientIds(searchContext, "table:baseText").get(0);
            Assert.assertEquals(componentId, "mainForm:table:3:baseText");
            componentId = handler.resolveClientIds(searchContext, "table:0:baseText").get(0);
            Assert.assertEquals(componentId, "mainForm:table:0:baseText");
            componentId = handler.resolveClientIds(searchContext, "nested:0:nestedText").get(0);
            Assert.assertEquals(componentId, "mainForm:table:3:nested:0:nestedText");
            componentId = handler.resolveClientIds(searchContext, "table:nested").get(0);
            Assert.assertEquals(componentId, "mainForm:table:3:nested");
            componentId = handler.resolveClientIds(searchContext, "table:1:nested:0:nestedText").get(0);
            Assert.assertEquals(componentId, "mainForm:table:1:nested:0:nestedText");
        // System.out.println(componentId);
        }
    });
    facesContext.getViewRoot().invokeOnComponent(facesContext, "mainForm:table:3:baseText", new ContextCallback() {

        @Override
        public void invokeContextCallback(FacesContext context, UIComponent target) {
            SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
            SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(context, target);
            Assert.assertEquals(handler.resolveClientId(searchContext, "@next"), "mainForm:table:3:nestedText");
        }
    });
    processRemainingPhases();
}
Also used : FacesContext(jakarta.faces.context.FacesContext) UIOutput(jakarta.faces.component.UIOutput) SearchExpressionHandler(jakarta.faces.component.search.SearchExpressionHandler) SearchExpressionContext(jakarta.faces.component.search.SearchExpressionContext) ContextCallback(jakarta.faces.component.ContextCallback) UIComponent(jakarta.faces.component.UIComponent) Test(org.junit.Test)

Example 5 with UIOutput

use of jakarta.faces.component.UIOutput in project myfaces by apache.

the class SearchExpressionImplTest method testResolveClientId1.

@Test
public void testResolveClientId1() throws Exception {
    startViewRequest("/search1.xhtml");
    processLifecycleExecute();
    executeBeforeRender();
    executeBuildViewCycle();
    SearchExpressionHandler handler = facesContext.getApplication().getSearchExpressionHandler();
    UIOutput out = (UIOutput) facesContext.getViewRoot().findComponent("mainForm:showName");
    Set<SearchExpressionHint> expressionHints = new HashSet<SearchExpressionHint>();
    expressionHints.add(SearchExpressionHint.IGNORE_NO_RESULT);
    SearchExpressionContext searchContextWithIgnoreNoResult = SearchExpressionContext.createSearchExpressionContext(facesContext, out, expressionHints, null);
    String clientId = handler.resolveClientId(searchContextWithIgnoreNoResult, "@none");
    Assert.assertNull(clientId);
    SearchExpressionContext searchContext = SearchExpressionContext.createSearchExpressionContext(facesContext, out);
    try {
        clientId = handler.resolveClientId(searchContext, "@none");
        Assert.fail();
    } catch (ComponentNotFoundException e) {
    // No op
    }
}
Also used : ComponentNotFoundException(jakarta.faces.component.search.ComponentNotFoundException) UIOutput(jakarta.faces.component.UIOutput) SearchExpressionHint(jakarta.faces.component.search.SearchExpressionHint) SearchExpressionHandler(jakarta.faces.component.search.SearchExpressionHandler) SearchExpressionContext(jakarta.faces.component.search.SearchExpressionContext) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

UIOutput (jakarta.faces.component.UIOutput)150 UIComponent (jakarta.faces.component.UIComponent)74 Test (org.junit.Test)59 UIViewRoot (jakarta.faces.component.UIViewRoot)38 PrintWriter (java.io.PrintWriter)25 FacesContext (jakarta.faces.context.FacesContext)22 jakarta.faces.component._EventListenerWrapper (jakarta.faces.component._EventListenerWrapper)19 UIInput (jakarta.faces.component.UIInput)15 Converter (jakarta.faces.convert.Converter)14 HashSet (java.util.HashSet)14 UIColumn (jakarta.faces.component.UIColumn)13 LongConverter (jakarta.faces.convert.LongConverter)13 HashMap (java.util.HashMap)13 HtmlPanelGroup (jakarta.faces.component.html.HtmlPanelGroup)12 ViewDeclarationLanguage (jakarta.faces.view.ViewDeclarationLanguage)12 UIData (jakarta.faces.component.UIData)11 ComponentSystemEventListener (jakarta.faces.event.ComponentSystemEventListener)11 TestBean (com.sun.ts.tests.jsf.common.beans.TestBean)10 ELContext (jakarta.el.ELContext)10 UICommand (jakarta.faces.component.UICommand)10