Search in sources :

Example 6 with UIForm

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

the class HtmlFormRendererBase method decode.

@Override
public void decode(FacesContext facesContext, UIComponent component) {
    RendererUtils.checkParamValidity(facesContext, component, UIForm.class);
    UIForm htmlForm = (UIForm) component;
    Map paramMap = facesContext.getExternalContext().getRequestParameterMap();
    // Perf: initialize StringBuilder to maximal lenght used in this renderer, render_response
    // method will re-use it without capacity expanding
    StringBuilder sb = SharedStringBuilder.get(facesContext, SHARED_STRING_BUILDER, 100);
    String submittedValue = (String) paramMap.get(sb.append(component.getClientId(facesContext)).append(HIDDEN_SUBMIT_INPUT_SUFFIX));
    if (submittedValue != null && submittedValue.equals(HIDDEN_SUBMIT_INPUT_VALUE)) {
        htmlForm.setSubmitted(true);
    } else {
        htmlForm.setSubmitted(false);
    }
    ClientBehaviorRendererUtils.decodeClientBehaviors(facesContext, component);
}
Also used : SharedStringBuilder(org.apache.myfaces.core.api.shared.lang.SharedStringBuilder) UIForm(jakarta.faces.component.UIForm) Map(java.util.Map)

Example 7 with UIForm

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

the class ViewPoolMyFacesRequestTestCase method testStaticPage1_1.

@Test
public void testStaticPage1_1() throws Exception {
    Locale locale = null;
    startViewRequest("/staticPage.xhtml");
    processLifecycleExecute();
    locale = facesContext.getViewRoot().getLocale();
    executeBeforeRender(facesContext);
    executeBuildViewCycle(facesContext);
    // Add a component in order to trigger a dynamic update
    UIOutput testComponent = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    testComponent.setId("testId");
    testComponent.setValue("Some Text");
    UIForm form = (UIForm) facesContext.getViewRoot().findComponent("mainForm");
    form.getChildren().add(testComponent);
    executeViewHandlerRender(facesContext);
    executeAfterRender(facesContext);
    UIViewRoot root = new UIViewRoot();
    root.setLocale(locale);
    root.setRenderKitId("HTML_BASIC");
    root.setViewId("/staticPage.xhtml");
    ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext);
    ViewPool viewPool = processor.getViewPool(facesContext, root);
    ViewEntry entry = viewPool.popStaticOrPartialStructureView(facesContext, root);
    Assert.assertNotNull(entry);
    Assert.assertEquals(RestoreViewFromPoolResult.COMPLETE, entry.getResult());
    // Check the component was removed
    UIForm form2 = (UIForm) entry.getViewRoot().findComponent("mainForm");
    Assert.assertNotNull(form2);
    UIOutput testComponent2 = (UIOutput) form2.findComponent("testId");
    Assert.assertNull(testComponent2);
    endRequest();
}
Also used : Locale(java.util.Locale) UIOutput(jakarta.faces.component.UIOutput) UIForm(jakarta.faces.component.UIForm) ViewPoolProcessor(org.apache.myfaces.view.facelets.ViewPoolProcessor) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 8 with UIForm

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

the class ViewPoolMyFacesRequestTestCase method testDynamicPage1_1.

@Test
public void testDynamicPage1_1() throws Exception {
    Locale locale = null;
    startViewRequest("/dynPage1.xhtml");
    processLifecycleExecute();
    locale = facesContext.getViewRoot().getLocale();
    executeBeforeRender(facesContext);
    executeBuildViewCycle(facesContext);
    // Add a component in order to trigger a dynamic update
    UIOutput testComponent = (UIOutput) application.createComponent(UIOutput.COMPONENT_TYPE);
    testComponent.setId("testId");
    testComponent.setValue("Some Text");
    UIForm form = (UIForm) facesContext.getViewRoot().findComponent("mainForm");
    form.getChildren().add(testComponent);
    FaceletState faceletState = (FaceletState) facesContext.getViewRoot().getAttributes().get(ComponentSupport.FACELET_STATE_INSTANCE);
    executeViewHandlerRender(facesContext);
    executeAfterRender(facesContext);
    UIViewRoot root = new UIViewRoot();
    root.setLocale(locale);
    root.setRenderKitId("HTML_BASIC");
    root.setViewId("/dynPage1.xhtml");
    ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext);
    ViewPool viewPool = processor.getViewPool(facesContext, root);
    ViewEntry entry = viewPool.popDynamicStructureView(facesContext, root, faceletState);
    Assert.assertNotNull(entry);
    Assert.assertEquals(RestoreViewFromPoolResult.COMPLETE, entry.getResult());
    // Check the component was removed
    UIForm form2 = (UIForm) entry.getViewRoot().findComponent("mainForm");
    Assert.assertNotNull(form2);
    UIOutput testComponent2 = (UIOutput) form2.findComponent("testId");
    Assert.assertNull(testComponent2);
    endRequest();
}
Also used : Locale(java.util.Locale) UIOutput(jakarta.faces.component.UIOutput) UIForm(jakarta.faces.component.UIForm) FaceletState(org.apache.myfaces.view.facelets.tag.faces.FaceletState) ViewPoolProcessor(org.apache.myfaces.view.facelets.ViewPoolProcessor) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 9 with UIForm

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

the class ViewPoolMyFacesRequestTestCase method testStaticPage1_4.

@Test
public void testStaticPage1_4() throws Exception {
    Locale locale = null;
    startViewRequest("/staticPage.xhtml");
    processLifecycleExecute();
    locale = facesContext.getViewRoot().getLocale();
    executeBeforeRender(facesContext);
    executeBuildViewCycle(facesContext);
    // Now let's try to remove some component programatically
    // that invalidates the view to be reused without a refresh,
    // so in the pool it should be marked as REFRESH_REQUIRED
    UIForm form = (UIForm) facesContext.getViewRoot().findComponent("mainForm");
    UIComponent panel = form.getChildren().remove(0);
    // Add it again
    form.getChildren().add(panel);
    executeViewHandlerRender(facesContext);
    executeAfterRender(facesContext);
    UIViewRoot root = new UIViewRoot();
    root.setLocale(locale);
    root.setRenderKitId("HTML_BASIC");
    root.setViewId("/staticPage.xhtml");
    ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext);
    ViewPool viewPool = processor.getViewPool(facesContext, root);
    ViewEntry entry = viewPool.popStaticOrPartialStructureView(facesContext, root);
    Assert.assertNotNull(entry);
    Assert.assertEquals(RestoreViewFromPoolResult.REFRESH_REQUIRED, entry.getResult());
    endRequest();
}
Also used : Locale(java.util.Locale) UIComponent(jakarta.faces.component.UIComponent) UIForm(jakarta.faces.component.UIForm) ViewPoolProcessor(org.apache.myfaces.view.facelets.ViewPoolProcessor) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Example 10 with UIForm

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

the class ViewPoolMyFacesRequestTestCase method testStaticPage1_3.

@Test
public void testStaticPage1_3() throws Exception {
    Locale locale = null;
    startViewRequest("/staticPage.xhtml");
    processLifecycleExecute();
    locale = facesContext.getViewRoot().getLocale();
    executeBeforeRender(facesContext);
    executeBuildViewCycle(facesContext);
    // Now let's try to remove some component programatically
    // that invalidates the view to be reused without a refresh,
    // so in the pool it should be marked as REFRESH_REQUIRED
    UIForm form = (UIForm) facesContext.getViewRoot().findComponent("mainForm");
    form.getChildren().remove(0);
    executeViewHandlerRender(facesContext);
    executeAfterRender(facesContext);
    UIViewRoot root = new UIViewRoot();
    root.setLocale(locale);
    root.setRenderKitId("HTML_BASIC");
    root.setViewId("/staticPage.xhtml");
    ViewPoolProcessor processor = ViewPoolProcessor.getInstance(facesContext);
    ViewPool viewPool = processor.getViewPool(facesContext, root);
    ViewEntry entry = viewPool.popStaticOrPartialStructureView(facesContext, root);
    Assert.assertNotNull(entry);
    Assert.assertEquals(RestoreViewFromPoolResult.REFRESH_REQUIRED, entry.getResult());
    endRequest();
}
Also used : Locale(java.util.Locale) UIForm(jakarta.faces.component.UIForm) ViewPoolProcessor(org.apache.myfaces.view.facelets.ViewPoolProcessor) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Aggregations

UIForm (jakarta.faces.component.UIForm)56 UIComponent (jakarta.faces.component.UIComponent)19 UIViewRoot (jakarta.faces.component.UIViewRoot)15 PrintWriter (java.io.PrintWriter)14 UIOutput (jakarta.faces.component.UIOutput)10 UIInput (jakarta.faces.component.UIInput)8 ClientBehaviorHolder (jakarta.faces.component.behavior.ClientBehaviorHolder)7 FacesContext (jakarta.faces.context.FacesContext)7 ResponseWriter (jakarta.faces.context.ResponseWriter)7 Test (org.junit.Test)7 List (java.util.List)5 UICommand (jakarta.faces.component.UICommand)4 HtmlCommandLink (jakarta.faces.component.html.HtmlCommandLink)4 VisitHint (jakarta.faces.component.visit.VisitHint)4 Locale (java.util.Locale)4 Map (java.util.Map)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 ViewPoolProcessor (org.apache.myfaces.view.facelets.ViewPoolProcessor)4 FacesException (jakarta.faces.FacesException)3 FacesMessage (jakarta.faces.application.FacesMessage)3