Note that there are some explanatory texts on larger screens.

plurals
  1. POFacelets custom component doesn't set attribute after submit
    primarykey
    data
    text
    <p>I am having a problem with custom components in facelets. The first time that the page is rendered, the attributes are set properly on the component class. When a form is submitted however, the attributes are not set.</p> <p>Here is the class that I am using to test this.</p> <pre><code>public class TestEcho extends UIData { /** Logger. */ private static Log log = LogFactory.getLog(TestEcho.class); private String msg; public TestEcho() { log.debug("Constructor."); } public void encodeEnd(FacesContext context) throws IOException { ResponseWriter writer = context.getResponseWriter(); writer.startElement("div", this); writer.writeText("The value of msg is '" + msg + "'.", null); writer.endElement("div"); } public void setMsg(String msg) { log.debug("Setting msg to '" + msg + "'."); this.msg = msg; } } </code></pre> <p>The component is used in the .xhtml page like this.</p> <pre><code>&lt;h:form&gt; &lt;v:testEcho msg="hello" /&gt; &lt;h:commandButton action="#{PictureManager.trigger}" value="Click" /&gt; &lt;/h:form&gt; </code></pre> <p>When the page renders for the first time, the component renders the following html code.</p> <pre><code>&lt;div&gt;The value of msg is 'hello'.&lt;/div&gt; </code></pre> <p>When the button is clicked, it renders this.</p> <pre><code>&lt;div&gt;The value of msg is 'null'.&lt;/div&gt; </code></pre> <p>From the log, you can see that the component is constructed again, but the attribute is not set.</p> <pre><code>13:23:42,955 DEBUG [TestEcho] Constructor. 13:23:42,955 DEBUG [TestEcho] Setting msg to 'hello'. ----- Button was pressed here ----- 13:25:48,988 DEBUG [TestEcho] Constructor. 13:25:49,144 DEBUG [PictureManager] Button pressed. </code></pre> <p>From what I understand, facelets does all the wiring of attributes to components so I don't need a tag class, but I don't understand why the attribute would be set correctly the first time, but not the second time.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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