Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirect to same webflow view state causes exception with nested composites
    primarykey
    data
    text
    <p>Consider a simple page with an input text and some validation to it. The page is included in a Spring webflow as a view state. On validation fail the same view state needs to be redisplayed, including validation messages. This works fine. Using a composite component that encapsulates input and message also works fine.</p> <p>However, using the same composite component inside another composite leads to the following error:</p> <p><code>FacesException: Cannot add the same component twice</code></p> <p>This Exception stems from a method called <a href="https://java.net/jira/secure/attachment/50134/changebundle.txt" rel="nofollow">handleAddRemoveWithAutoPrune</a>, which adds components to a dynamic action list and throws the error if a component is supposed to be added a second time.</p> <p>Here is an example to reproduce the behaviour:</p> <h3>JSF Page</h3> <pre><code>&lt;h:form id="form"&gt; &lt;h:inputText id="text" value="#{bean.someValue}" &gt; &lt;f:validateLength maximum="3" /&gt; &lt;/h:inputText&gt; &lt;h:message for="text" /&gt; &lt;!-- This will work --&gt; &lt;test:ccInner anything="Blubb" /&gt; &lt;!-- This will not work --&gt; &lt;test:ccOuter id="outer" title="Outer Component"&gt; &lt;test:ccInner id="inner" anything="Inner Component" /&gt; &lt;/test:ccOuter&gt; &lt;h:commandButton id="button" type="submit" value="Submit" action="#{bean.doStuff}" /&gt; &lt;/h:form&gt; </code></pre> <h3>Components</h3> <p><em>Inner</em></p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:h="http://java.sun.com/jsf/html"&gt; &lt;cc:interface&gt; &lt;cc:attribute name="anything" /&gt; &lt;/cc:interface&gt; &lt;cc:implementation&gt; #{cc.attrs.anything} &lt;/cc:implementation&gt; &lt;/html&gt; </code></pre> <p><em>Outer</em></p> <pre><code>&lt;html xmlns="http://www.w3.org/1999/xhtml" xmlns:cc="http://java.sun.com/jsf/composite" xmlns:h="http://java.sun.com/jsf/html"&gt; &lt;cc:interface&gt; &lt;cc:attribute name="title" /&gt; &lt;/cc:interface&gt; &lt;cc:implementation&gt; #{cc.attrs.title} &lt;cc:insertChildren /&gt; &lt;/cc:implementation&gt; &lt;/html&gt; </code></pre> <p>(Omitting the bean and flow definition. Plain standard stuff)</p> <p>I looked into this for a while. Others who have similar problems usually encounter it when using composites inside iterating components (e.g. dataTable), hence components will be added dynamically on view creation and view restoring. The problem then occurs on a postback to the same view, see for example <a href="https://java.net/jira/browse/JAVASERVERFACES-2894" rel="nofollow">this ticket here</a>. There, the error was caused by a flaw in the original poster's encode methode, however, my components are plain and simple, no custom Java behind, so this doesn't help me... </p> <p>Nonetheless I found two work-arounds: As described <a href="http://static.springsource.org/spring-webflow/docs/2.3.x/reference/html/ch13s10.html" rel="nofollow">in the Spring Webflows documentation</a> a webflow automatically performs a redirect when a transition to the same view state occurs. </p> <p>1) When turning off this behaviour by adding </p> <pre><code>&lt;webflow:flow-executor id="flowExecutor"&gt; &lt;webflow:flow-execution-attributes&gt; &lt;webflow:redirect-in-same-state value="false"/&gt; &lt;/webflow:flow-execution-attributes&gt; &lt;/webflow:flow-executor&gt; </code></pre> <p>to the <code>webflow.xml</code> the problem disappears. However, as the text advises, the original redirect is desired behaviour to prevent double form submission and notifications in some browsers such as chrome when hitting F5 or using back/forward.</p> <p>2) As the text describes, Ajax requests will not cause a redirect, so adding <code>&lt;f:ajax execute="@form" render="@form" /&gt;</code> to the submit button will also solve the problem. But do I really want to use Ajax for a submission of the full form? It seems kind of nonsensical to me. </p> <p>While this works for the moment, 1) has serious drawbacks and 2) makes things a bit more complicated and may also not always be desirable. Thus, I would rather solve the original issue (or first understand it, for that matter). Also, if this is a problem in the underlying implementation it might be good to file a bug report (if there isn't one already).</p> <p>Edit: Running on JBoss with Mojarra 2.1.21, JSF 2.1, Spring Webflow 2.3.2</p>
    singulars
    1. This table or related slice is empty.
    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