Note that there are some explanatory texts on larger screens.

plurals
  1. POJSF, writeAttribute("value", str, null) fails with strings obtained through ValueExpression.getValue()
    text
    copied!<p>I'm having a somewhat weird problem with custom JSF component.</p> <p>Here's my renderer code:</p> <pre><code>public class Test extends Renderer { public void encodeBegin(final FacesContext context, final UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("textarea", component); String clientId = component.getClientId(context); if (clientId != null) writer.writeAttribute("name", clientId, null); ValueExpression exp = component.getValueExpression("value"); if (exp != null &amp;&amp; exp.getValue(context.getELContext()) != null) { String val = (String) exp.getValue(context.getELContext()); System.out.println("Value: " + val); writer.writeAttribute("value", val, null); } writer.endElement("textarea"); writer.flush(); } } </code></pre> <p>The code generates:</p> <pre><code>&lt;textarea name="j_id2:j_id12:j_id19" value=""&gt;&lt;/textarea&gt; </code></pre> <p>Property binding contains "test" and as it should be, "Value: test" is successfully printed to console.</p> <p>Now, if I change the code to: </p> <pre><code>public void encodeBegin(final FacesContext context, final UIComponent component) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("textarea", component); String clientId = component.getClientId(context); if (clientId != null) writer.writeAttribute("name", clientId, null); ValueExpression exp = component.getValueExpression("value"); if (exp != null &amp;&amp; exp.getValue(context.getELContext()) != null) { String val = (String) exp.getValue(context.getELContext()); String str = "new string"; System.out.println("Value1: " + val + ", Value2: " + str); writer.writeAttribute("value", str, null); } writer.endElement("textarea"); writer.flush(); } </code></pre> <p>generated html is:</p> <pre><code>&lt;textarea name="j_id2:j_id12:j_id19" value="new string"&gt;&lt;/textarea&gt; </code></pre> <p>and console output is "Value1: test, Value2: new string"</p> <p>What's going on here? This doesn't make sense. Why would writeAttribute differentiate between the two strings?</p> <p>Additional info:</p> <ul> <li>The component extends UIComponentBase</li> <li>I am using it with facelets </li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload