Search in sources :

Example 1 with HtmlInputText

use of jakarta.faces.component.html.HtmlInputText 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 2 with HtmlInputText

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

the class OwnRenderkitTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    addRenderKit();
    inputText = new HtmlInputText();
    writer = new MockResponseWriter(new StringWriter(), null, null);
    facesContext.setResponseWriter(writer);
    MockFacesContext12.getCurrentInstance();
    facesContext.getViewRoot().setRenderKitId("OWN_BASIC");
    facesContext.getRenderKit().addRenderer(inputText.getFamily(), inputText.getRendererType(), new HtmlTextRenderer());
}
Also used : StringWriter(java.io.StringWriter) HtmlInputText(jakarta.faces.component.html.HtmlInputText) MockResponseWriter(org.apache.myfaces.test.mock.MockResponseWriter) HtmlTextRenderer(org.apache.myfaces.renderkit.html.HtmlTextRenderer)

Example 3 with HtmlInputText

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

the class MessageUtilsTest method testGetLabelReturnsClientIdWhenLabelIsNotSpecified.

public void testGetLabelReturnsClientIdWhenLabelIsNotSpecified() {
    HtmlInputText inputText = new HtmlInputText();
    inputText.setId("testId");
    Object label = MessageUtils.getLabel(facesContext, inputText);
    Assert.assertEquals("testId", label);
}
Also used : HtmlInputText(jakarta.faces.component.html.HtmlInputText)

Example 4 with HtmlInputText

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

the class MessageUtilsTest method testGetLabelFromValueExpression.

public void testGetLabelFromValueExpression() {
    facesContext.getExternalContext().getRequestMap().put("lbl", "testLabel");
    HtmlInputText inputText = new HtmlInputText();
    ValueExpression expression = new MockValueExpression("#{requestScope.lbl}", String.class);
    inputText.setValueExpression("label", expression);
    Object label = MessageUtils.getLabel(facesContext, inputText);
    Assert.assertEquals("testLabel", label);
}
Also used : MockValueExpression(org.apache.myfaces.test.el.MockValueExpression) ValueExpression(jakarta.el.ValueExpression) HtmlInputText(jakarta.faces.component.html.HtmlInputText) MockValueExpression(org.apache.myfaces.test.el.MockValueExpression)

Example 5 with HtmlInputText

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

the class UIDataRowStateTest method testChangeIdsAfterSetRowIndex2.

@Test
public void testChangeIdsAfterSetRowIndex2() {
    List<Item> list = new ArrayList<Item>();
    int rowCount = 10;
    for (int i = 0; i < rowCount; i++) {
        list.add(new Item(i, "name" + i, "lastName" + i));
    }
    facesContext.getExternalContext().getRequestMap().put("items", list);
    UIViewRoot root = facesContext.getViewRoot();
    UIData data = new HtmlDataTable();
    data.setId("table");
    root.getChildren().add(data);
    data.setValue(new ListDataModel(list));
    data.setVar("item");
    data.setRows(rowCount);
    UIColumn col = new HtmlColumn();
    data.getChildren().add(col);
    UIOutput text = new HtmlOutputText();
    text.setId("text");
    text.setValue(facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{item.name}", String.class));
    col.getChildren().add(text);
    UIInput inputText = new HtmlInputText();
    inputText.setId("text");
    inputText.setValue(facesContext.getApplication().getExpressionFactory().createValueExpression(facesContext.getELContext(), "#{item.lastName}", String.class));
    col.getChildren().add(inputText);
    for (int i = 0; i < rowCount; i++) {
        data.setRowIndex(i);
        Assert.assertEquals(data.getId() + ":" + i + ":" + text.getId(), text.getClientId());
        Assert.assertEquals(data.getId() + ":" + i + ":" + inputText.getId(), inputText.getClientId());
    }
    data.setRowIndex(-1);
    Assert.assertEquals(data.getId() + ":" + text.getId(), text.getClientId());
    Assert.assertEquals(data.getId() + ":" + inputText.getId(), inputText.getClientId());
}
Also used : HtmlDataTable(jakarta.faces.component.html.HtmlDataTable) UIColumn(jakarta.faces.component.UIColumn) ArrayList(java.util.ArrayList) HtmlInputText(jakarta.faces.component.html.HtmlInputText) UIInput(jakarta.faces.component.UIInput) ListDataModel(jakarta.faces.model.ListDataModel) UIData(jakarta.faces.component.UIData) HtmlColumn(jakarta.faces.component.html.HtmlColumn) UIOutput(jakarta.faces.component.UIOutput) HtmlOutputText(jakarta.faces.component.html.HtmlOutputText) UIViewRoot(jakarta.faces.component.UIViewRoot) Test(org.junit.Test)

Aggregations

HtmlInputText (jakarta.faces.component.html.HtmlInputText)21 UIComponent (jakarta.faces.component.UIComponent)6 HtmlOutputText (jakarta.faces.component.html.HtmlOutputText)6 UIOutput (jakarta.faces.component.UIOutput)5 UIViewRoot (jakarta.faces.component.UIViewRoot)5 HtmlCommandButton (jakarta.faces.component.html.HtmlCommandButton)4 StringWriter (java.io.StringWriter)4 MockResponseWriter (org.apache.myfaces.test.mock.MockResponseWriter)4 UIInput (jakarta.faces.component.UIInput)3 HtmlDataTable (jakarta.faces.component.html.HtmlDataTable)3 HtmlInputFile (jakarta.faces.component.html.HtmlInputFile)3 UIColumn (jakarta.faces.component.UIColumn)2 UIData (jakarta.faces.component.UIData)2 UIForm (jakarta.faces.component.UIForm)2 ClientBehavior (jakarta.faces.component.behavior.ClientBehavior)2 ClientBehaviorBase (jakarta.faces.component.behavior.ClientBehaviorBase)2 ClientBehaviorContext (jakarta.faces.component.behavior.ClientBehaviorContext)2 ClientBehaviorHint (jakarta.faces.component.behavior.ClientBehaviorHint)2 HtmlBody (jakarta.faces.component.html.HtmlBody)2 HtmlColumn (jakarta.faces.component.html.HtmlColumn)2