Search in sources :

Example 1 with BufferedResponseWrapper

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper in project faces by jakartaee.

the class TestServlet method uiComponentGetSetValueExpressionTest.

// ------------------------------------------- Test Methods ----
@Override
public void uiComponentGetSetValueExpressionTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
    super.uiComponentGetSetValueExpressionTest(request, wrapper);
    String result = wrapper.getBufferedWriter().toString();
    PrintWriter out = response.getWriter();
    if (result.indexOf(JSFTestUtil.PASS) == -1) {
        out.println(result);
        return;
    }
    // default processing of get,setValueExpression is ok, now validate
    // processing specific to UIGraphic
    request.setAttribute("tckUrl", "http://java.sun.com");
    ExpressionFactory factory = JSFTestUtil.getExpressionFactory(servletContext);
    ValueExpression expression = factory.createValueExpression(getFacesContext().getELContext(), "#{requestScope.tckUrl}", java.lang.String.class);
    ValueExpression literalExpr = factory.createValueExpression(getFacesContext().getELContext(), "http://java.net", java.lang.String.class);
    UIGraphic graphic = (UIGraphic) createComponent();
    graphic.setValueExpression("url", expression);
    if (!"http://java.sun.com".equals(graphic.getValue())) {
        out.println(JSFTestUtil.FAIL + " setValueExpression() with a key of 'url'" + " didn't set the ValueExpression provided as the value" + " of the component.");
        out.println("Expected: http://java.net");
        out.println("Received: " + graphic.getValue());
        return;
    }
    // ensure there is no special processing if the ValueExpression
    // happens to be literal
    graphic.setValueExpression("url", literalExpr);
    if (!"http://java.net".equals(graphic.getValue())) {
        out.println(JSFTestUtil.FAIL + " setValueExpression() with a key of 'url'" + " didn't set the literal ValueExpression provided as the " + "value of the component.");
        out.println("Expected: " + expression);
        out.println("Received: " + graphic.getValue());
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) UIGraphic(jakarta.faces.component.UIGraphic) BufferedResponseWrapper(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper) PrintWriter(java.io.PrintWriter)

Example 2 with BufferedResponseWrapper

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper in project faces by jakartaee.

the class TestServlet method uiComponentGetSetValueExpressionTest.

// ------------------------------------------- Test Methods ----
@Override
public void uiComponentGetSetValueExpressionTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
    super.uiComponentGetSetValueExpressionTest(request, wrapper);
    String result = wrapper.getBufferedWriter().toString();
    PrintWriter out = response.getWriter();
    if (result.indexOf(JSFTestUtil.PASS) == -1) {
        out.println(result);
        return;
    }
    // default processing of get,setValueExpression is ok, now validate
    // processing specific to UIGraphic
    request.setAttribute("value", "selectedValue");
    ExpressionFactory factory = JSFTestUtil.getExpressionFactory(servletContext);
    ValueExpression expression = factory.createValueExpression(getFacesContext().getELContext(), "#{requestScope.value}", java.lang.String.class);
    UISelectBoolean selBoolean = (UISelectBoolean) createComponent();
    selBoolean.setValueExpression("selected", expression);
    if (!"selectedValue".equals(selBoolean.getValue())) {
        out.println(JSFTestUtil.FAIL + " setValueExpression() with a key of 'selected'" + " didn't set the ValueExpression provided as the value" + " of the component.");
        out.println("Expected: " + expression);
        out.println("Received: " + selBoolean.getValue());
        return;
    }
    out.println(JSFTestUtil.PASS);
}
Also used : ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) UISelectBoolean(jakarta.faces.component.UISelectBoolean) BufferedResponseWrapper(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper) PrintWriter(java.io.PrintWriter)

Example 3 with BufferedResponseWrapper

use of com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper in project faces by jakartaee.

the class TestServlet method uiComponentGetSetValueExpressionTest.

// ------------------------------------------- Test Methods ----
@Override
public void uiComponentGetSetValueExpressionTest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    BufferedResponseWrapper wrapper = new BufferedResponseWrapper(response);
    super.uiComponentGetSetValueExpressionTest(request, wrapper);
    String result = wrapper.getBufferedWriter().toString();
    PrintWriter out = response.getWriter();
    if (result.indexOf(JSFTestUtil.PASS) == -1) {
        out.println(result);
        return;
    }
    List<String> values = new ArrayList<String>();
    values.add("value1");
    values.add("value2");
    // default processing of get,setValueExpression is ok, now validate
    // processing specific to UIGraphic
    request.setAttribute("values", values);
    ExpressionFactory factory = JSFTestUtil.getExpressionFactory(servletContext);
    ValueExpression expression = factory.createValueExpression(getFacesContext().getELContext(), "#{requestScope.values}", java.util.List.class);
    UISelectMany many = (UISelectMany) createComponent();
    many.setValueExpression("selectedValues", expression);
    if (many.getValue() != values) {
        out.println(JSFTestUtil.FAIL + " getValue() returned unexpected value" + " after having called setValueExpression().");
        out.println("Expected: " + values);
        out.println("Received: " + many.getValue());
    }
    out.println(JSFTestUtil.PASS);
}
Also used : UISelectMany(jakarta.faces.component.UISelectMany) ExpressionFactory(jakarta.el.ExpressionFactory) ValueExpression(jakarta.el.ValueExpression) ArrayList(java.util.ArrayList) BufferedResponseWrapper(com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper) PrintWriter(java.io.PrintWriter)

Aggregations

BufferedResponseWrapper (com.sun.ts.tests.jsf.api.jakarta_faces.component.common.BufferedResponseWrapper)3 ExpressionFactory (jakarta.el.ExpressionFactory)3 ValueExpression (jakarta.el.ValueExpression)3 PrintWriter (java.io.PrintWriter)3 UIGraphic (jakarta.faces.component.UIGraphic)1 UISelectBoolean (jakarta.faces.component.UISelectBoolean)1 UISelectMany (jakarta.faces.component.UISelectMany)1 ArrayList (java.util.ArrayList)1