Search in sources :

Example 1 with HtmlForm

use of jakarta.faces.component.html.HtmlForm in project myfaces by apache.

the class HtmlFormRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    // application.setViewHandler(new MockTestViewHandler());
    form = new HtmlForm();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(form.getFamily(), form.getRendererType(), new HtmlFormRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : HtmlForm(jakarta.faces.component.html.HtmlForm) StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter)

Example 2 with HtmlForm

use of jakarta.faces.component.html.HtmlForm in project myfaces by apache.

the class HtmlCommandLinkClientBehaviorRendererTest method createComponentToTest.

@Override
protected UIComponent createComponentToTest() {
    UIComponent component = new HtmlCommandLink();
    UIComponent form = new HtmlForm();
    form.getChildren().add(component);
    facesContext.getViewRoot().getChildren().add(form);
    return component;
}
Also used : HtmlForm(jakarta.faces.component.html.HtmlForm) HtmlCommandLink(jakarta.faces.component.html.HtmlCommandLink) UIComponent(jakarta.faces.component.UIComponent)

Example 3 with HtmlForm

use of jakarta.faces.component.html.HtmlForm in project myfaces by apache.

the class PartialStateManagementStrategyTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY, VisitContextFactoryImpl.class.getName());
    RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory("jakarta.faces.render.RenderKitFactory");
    renderKit = new MockRenderKit() {

        ResponseStateManager stateManager = new ResponseStateManager() {

            public Object getState(FacesContext context, String viewId) {
                return stateToRestore;
            }
        };

        @Override
        public ResponseStateManager getResponseStateManager() {
            return stateManager;
        }
    };
    renderKitFactory.addRenderKit("HTML_BASIC2", renderKit);
    // FactoryFinder.setFactory(FactoryFinder.VISIT_CONTEXT_FACTORY,
    // VisitContextFactoryImpl.class.getName());
    renderKit.addRenderer(new HtmlCommandButton().getFamily(), new HtmlCommandButton().getRendererType(), new HtmlButtonRenderer());
    renderKit.addRenderer(new HtmlForm().getFamily(), new HtmlForm().getRendererType(), new HtmlFormRenderer());
    renderKit.addRenderer(new HtmlOutputText().getFamily(), new HtmlOutputText().getRendererType(), new HtmlTextRenderer());
    renderKit.addRenderer(new HtmlInputText().getFamily(), new HtmlInputText().getRendererType(), new HtmlTextRenderer());
}
Also used : FacesContext(jakarta.faces.context.FacesContext) HtmlInputText(jakarta.faces.component.html.HtmlInputText) VisitContextFactoryImpl(org.apache.myfaces.component.visit.VisitContextFactoryImpl) HtmlCommandButton(jakarta.faces.component.html.HtmlCommandButton) HtmlFormRenderer(org.apache.myfaces.renderkit.html.HtmlFormRenderer) HtmlTextRenderer(org.apache.myfaces.renderkit.html.HtmlTextRenderer) HtmlForm(jakarta.faces.component.html.HtmlForm) ResponseStateManager(jakarta.faces.render.ResponseStateManager) HtmlButtonRenderer(org.apache.myfaces.renderkit.html.HtmlButtonRenderer) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) MockRenderKit(org.apache.myfaces.test.mock.MockRenderKit) RenderKitFactory(jakarta.faces.render.RenderKitFactory)

Example 4 with HtmlForm

use of jakarta.faces.component.html.HtmlForm in project myfaces by apache.

the class HtmlInputFileRendererBase method encodeEnd.

@Override
public void encodeEnd(FacesContext facesContext, UIComponent component) throws IOException {
    renderInput(facesContext, component);
    if (!facesContext.isProjectStage(ProjectStage.Production) && facesContext.isPostback() && (facesContext.getPartialViewContext().isPartialRequest() || facesContext.getPartialViewContext().isAjaxRequest())) {
        UIForm form = ComponentUtils.findClosest(UIForm.class, component);
        if (form != null && form instanceof HtmlForm) {
            String content = ((HtmlForm) form).getEnctype();
            if (content == null || !content.contains("multipart/form-data")) {
                FacesMessage message = new FacesMessage("file upload requires a form with" + " enctype equal to multipart/form-data");
                facesContext.addMessage(component.getClientId(), message);
            }
        }
    }
}
Also used : HtmlForm(jakarta.faces.component.html.HtmlForm) UIForm(jakarta.faces.component.UIForm) FacesMessage(jakarta.faces.application.FacesMessage)

Example 5 with HtmlForm

use of jakarta.faces.component.html.HtmlForm in project myfaces by apache.

the class HtmlMessageRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    message = new HtmlMessage();
    form = new HtmlForm();
    inputText = new HtmlInputText();
    facesContext.setResponseWriter(writer);
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(message.getFamily(), message.getRendererType(), new HtmlMessageRenderer());
    facesContext.getRenderKit().addRenderer(inputText.getFamily(), inputText.getRendererType(), new HtmlTextRenderer());
    facesContext.getRenderKit().addRenderer(form.getFamily(), form.getRendererType(), new HtmlFormRenderer());
    // inputText.setParent(form);
    inputText.setId("myInputId");
    // message.setParent(form);
    form.getChildren().add(inputText);
    form.getChildren().add(message);
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : HtmlMessage(jakarta.faces.component.html.HtmlMessage) StringWriter(java.io.StringWriter) HtmlForm(jakarta.faces.component.html.HtmlForm) HtmlInputText(jakarta.faces.component.html.HtmlInputText) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter)

Aggregations

HtmlForm (jakarta.faces.component.html.HtmlForm)10 StringWriter (java.io.StringWriter)4 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)4 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)3 UIComponent (jakarta.faces.component.UIComponent)2 HtmlInputText (jakarta.faces.component.html.HtmlInputText)2 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)2 FacesMessage (jakarta.faces.application.FacesMessage)1 UIForm (jakarta.faces.component.UIForm)1 UIOutput (jakarta.faces.component.UIOutput)1 HtmlBody (jakarta.faces.component.html.HtmlBody)1 HtmlCommandLink (jakarta.faces.component.html.HtmlCommandLink)1 HtmlMessage (jakarta.faces.component.html.HtmlMessage)1 HtmlOutcomeTargetButton (jakarta.faces.component.html.HtmlOutcomeTargetButton)1 FacesContext (jakarta.faces.context.FacesContext)1 RenderKitFactory (jakarta.faces.render.RenderKitFactory)1 ResponseStateManager (jakarta.faces.render.ResponseStateManager)1 NavigationHandlerImpl (org.apache.myfaces.application.NavigationHandlerImpl)1 VisitContextFactoryImpl (org.apache.myfaces.component.visit.VisitContextFactoryImpl)1 HtmlButtonRenderer (org.apache.myfaces.renderkit.html.HtmlButtonRenderer)1