Search in sources :

Example 1 with HtmlOutputText

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

the class HtmlTableRendererTest method testNoRowCountRender.

/**
 * Check table renderer behavior when DataModel returns -1 from getRowCount(). It should
 * render the same as if that value is provided. Note t:dataTable newspaper mode requires
 * row count to calculate newspaperRows and newspaperColumns.
 */
public void testNoRowCountRender() {
    List<Person> list = new ArrayList<Person>();
    list.add(new Person("John", "Smith"));
    list.add(new Person("Pepito", "Perez"));
    list.add(new Person("Kurt", "Kobain"));
    dataTable.setId("data");
    dataTable.setRowClasses("class1, class2");
    dataTable.setVar("person");
    UIColumn column1 = new UIColumn();
    HtmlOutputText text = new HtmlOutputText();
    text.setValueExpression("value", facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{person.firstName}", String.class));
    column1.getChildren().add(text);
    dataTable.getChildren().add(column1);
    UIColumn column2 = new UIColumn();
    HtmlOutputText text2 = new HtmlOutputText();
    text2.setValueExpression("value", facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{person.lastName}", String.class));
    column2.getChildren().add(text2);
    dataTable.getChildren().add(column2);
    dataTable.setValue(new UnknownRowCountDemoDataModel<Person>(list));
    String output1 = null;
    try {
        dataTable.encodeAll(facesContext);
        output1 = ((StringWriter) writer.getWriter()).getBuffer().toString();
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    dataTable.setValue(new ListDataModel<Person>(list));
    ((StringWriter) writer.getWriter()).getBuffer().setLength(0);
    String output2 = null;
    try {
        dataTable.encodeAll(facesContext);
        output2 = ((StringWriter) writer.getWriter()).getBuffer().toString();
    } catch (Exception e) {
        Assert.fail(e.getMessage());
    }
    Assert.assertTrue(output2.contains("John"));
    Assert.assertTrue(output2.contains("Smith"));
    Assert.assertTrue(output2.contains("class1"));
    Assert.assertTrue(output2.contains("class2"));
    Assert.assertTrue(output1.contains("John"));
    Assert.assertTrue(output1.contains("Smith"));
    Assert.assertTrue(output1.contains("class1"));
    Assert.assertTrue(output1.contains("class2"));
    Assert.assertEquals(output2, output1);
}
Also used : UIColumn(jakarta.faces.component.UIColumn) StringWriter(java.io.StringWriter) ArrayList(java.util.ArrayList) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 2 with HtmlOutputText

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

the class HtmlTableRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    dataTable = new HtmlDataTable();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(dataTable.getFamily(), dataTable.getRendererType(), new HtmlTableRenderer());
    HtmlOutputText text = new HtmlOutputText();
    facesContext.getRenderKit().addRenderer(text.getFamily(), text.getRendererType(), new HtmlTextRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) StringWriter(java.io.StringWriter) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 3 with HtmlOutputText

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

the class HtmlTextRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    servletContext.addInitParameter(MyfacesConfig.RENDER_CLIENTBEHAVIOR_SCRIPTS_AS_STRING, "true");
    outputText = new HtmlOutputText();
    inputText = new HtmlInputText();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    // TODO remove these two lines once myfaces-test goes alpha, see MYFACES-1155
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(outputText.getFamily(), outputText.getRendererType(), new HtmlTextRenderer());
    facesContext.getRenderKit().addRenderer(inputText.getFamily(), inputText.getRendererType(), new HtmlTextRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : StringWriter(java.io.StringWriter) HtmlInputText(jakarta.faces.component.html.HtmlInputText) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Example 4 with HtmlOutputText

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

the class HtmlEscapeRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    outputText = new HtmlOutputText();
    outputLabel = new HtmlOutputLabel();
    selectOneRadio = new HtmlSelectOneRadio();
    selectOneListbox = new HtmlSelectOneListbox();
    selectOneMenu = new HtmlSelectOneMenu();
    selectManyCheckbox = new HtmlSelectManyCheckbox();
    selectManyListbox = new HtmlSelectManyListbox();
    selectManyMenu = new HtmlSelectManyMenu();
    // TODO remove these two lines once myfaces-test goes alpha, see MYFACES-1155
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(outputText.getFamily(), outputText.getRendererType(), new HtmlTextRenderer());
    facesContext.getRenderKit().addRenderer(outputLabel.getFamily(), outputLabel.getRendererType(), new HtmlLabelRenderer());
    facesContext.getRenderKit().addRenderer(selectOneRadio.getFamily(), selectOneRadio.getRendererType(), new HtmlRadioRenderer());
    facesContext.getRenderKit().addRenderer(selectOneListbox.getFamily(), selectOneListbox.getRendererType(), new HtmlListboxRenderer());
    facesContext.getRenderKit().addRenderer(selectOneMenu.getFamily(), selectOneMenu.getRendererType(), new HtmlMenuRenderer());
    facesContext.getRenderKit().addRenderer(selectManyCheckbox.getFamily(), selectManyCheckbox.getRendererType(), new HtmlCheckboxRenderer());
    facesContext.getRenderKit().addRenderer(selectManyListbox.getFamily(), selectManyListbox.getRendererType(), new HtmlListboxRenderer());
    facesContext.getRenderKit().addRenderer(selectManyMenu.getFamily(), selectManyMenu.getRendererType(), new HtmlMenuRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : HtmlSelectOneListbox(jakarta.faces.component.html.HtmlSelectOneListbox) HtmlSelectOneMenu(jakarta.faces.component.html.HtmlSelectOneMenu) HtmlOutputLabel(jakarta.faces.component.html.HtmlOutputLabel) HtmlSelectOneRadio(jakarta.faces.component.html.HtmlSelectOneRadio) HtmlSelectManyMenu(jakarta.faces.component.html.HtmlSelectManyMenu) HtmlSelectManyListbox(jakarta.faces.component.html.HtmlSelectManyListbox) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) HtmlSelectManyCheckbox(jakarta.faces.component.html.HtmlSelectManyCheckbox)

Example 5 with HtmlOutputText

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

the class HtmlGroupRendererTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    servletContext.addInitParameter(MyfacesConfig.RENDER_CLIENTBEHAVIOR_SCRIPTS_AS_STRING, "true");
    panelGroup = new HtmlPanelGroup();
    HtmlOutputText panelChildOutputText = new HtmlOutputText();
    panelChildOutputText.setValue(PANEL_CHILD_TEXT);
    panelGroup.getChildren().add(panelChildOutputText);
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    facesContext.getViewRoot().setRenderKitId(MockRenderKitFactory.HTML_BASIC_RENDER_KIT);
    facesContext.getRenderKit().addRenderer(panelGroup.getFamily(), panelGroup.getRendererType(), new HtmlGroupRenderer());
    facesContext.getRenderKit().addRenderer(panelChildOutputText.getFamily(), panelChildOutputText.getRendererType(), new HtmlTextRenderer());
    facesContext.getRenderKit().addClientBehaviorRenderer(AjaxBehavior.BEHAVIOR_ID, new HtmlAjaxBehaviorRenderer());
    facesContext.getAttributes().put("org.apache.myfaces.RENDERED_FACES_JS", Boolean.TRUE);
}
Also used : StringWriter(java.io.StringWriter) HtmlPanelGroup(jakarta.faces.component.html.HtmlPanelGroup) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText)

Aggregations

HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)31 UIViewRoot (jakarta.faces.component.UIViewRoot)11 Test (org.junit.Test)11 StringWriter (java.io.StringWriter)9 UIComponent (jakarta.faces.component.UIComponent)8 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)8 UIColumn (jakarta.faces.component.UIColumn)7 UIOutput (jakarta.faces.component.UIOutput)7 HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)7 HtmlColumn (jakarta.faces.component.html.HtmlColumn)6 HtmlInputText (jakarta.faces.component.html.HtmlInputText)6 ArrayList (java.util.ArrayList)5 UIData (jakarta.faces.component.UIData)4 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)4 ListDataModel (jakarta.faces.model.ListDataModel)4 ViewDeclarationLanguage (jakarta.faces.view.ViewDeclarationLanguage)4 Application (jakarta.faces.application.Application)3 FacesContext (jakarta.faces.context.FacesContext)3 HtmlRenderedAttr (org.apache.myfaces.test.utils.HtmlRenderedAttr)3 MethodExpression (jakarta.el.MethodExpression)2