Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>Introduction</h2> <p>Whenever an <code>UICommand</code> component (<code>&lt;h:commandXxx&gt;</code>, <code>&lt;p:commandXxx&gt;</code>, etc) fails to invoke the associated action method, or an <code>UIInput</code> component (<code>&lt;h:inputXxx&gt;</code>, <code>&lt;p:inputXxxx&gt;</code>, etc) fails to process the submitted values and/or update the model values, and you aren't seeing any googlable exceptions and/or warnings in the server log, also not when you configure an ajax exception handler as per <a href="https://stackoverflow.com/questions/27526753/exception-handling-in-jsf-ajax-requests">Exception handling in JSF ajax requests</a>, nor when you set below context parameter in <code>web.xml</code>,</p> <pre><code>&lt;context-param&gt; &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt; &lt;param-value&gt;Development&lt;/param-value&gt; &lt;/context-param&gt; </code></pre> <p>and you are also not seeing any googlable errors and/or warnings in browser's JavaScript console (press F12 in Chrome/Firefox23+/IE9+ to open the web developer toolset and then open the <em>Console</em> tab), then work through below list of possible causes.</p> <h2>Possible causes</h2> <ol> <li><p><code>UICommand</code> and <code>UIInput</code> components must be placed inside an <code>UIForm</code> component, e.g. <code>&lt;h:form&gt;</code> (and thus not plain HTML <code>&lt;form&gt;</code>), otherwise nothing can be sent to the server. <code>UICommand</code> components must also not have <code>type="button"</code> attribute, otherwise it will be a dead button which is only useful for JavaScript <code>onclick</code>. See also <a href="https://stackoverflow.com/questions/3681123/how-to-get-hinputtext-values-from-gui-xhtml-into-java-class-jsf-bean">How to send form input values and invoke a method in JSF bean</a> and <a href="https://stackoverflow.com/questions/12958208/hcommandbutton-does-not-initiate-a-postback">&lt;h:commandButton&gt; does not initiate a postback</a>.</p></li> <li><p>You cannot nest multiple <code>UIForm</code> components in each other. This is illegal in HTML. The browser behavior is unspecified. Watch out with include files! You can use <code>UIForm</code> components in parallel, but they won't process each other during submit. You should also watch out with "God Form" antipattern; make sure that you don't unintentionally process/validate all other (invisible) inputs in the very same form (e.g. having a hidden dialog with required inputs in the very same form). See also <a href="https://stackoverflow.com/questions/7371903/using-multiple-hform-in-a-jsf-page">How to use &lt;h:form&gt; in JSF page? Single form? Multiple forms? Nested forms?</a>. </p></li> <li><p>No <code>UIInput</code> value validation/conversion error should have occurred. You can use <code>&lt;h:messages&gt;</code> to show any messages which are not shown by any input-specific <code>&lt;h:message&gt;</code> components. Don't forget to include the <code>id</code> of <code>&lt;h:messages&gt;</code> in the <code>&lt;f:ajax render&gt;</code>, if any, so that it will be updated as well on ajax requests. See also <a href="https://stackoverflow.com/questions/16175178/hmessages-does-not-display-messages-when-pcommandbutton-is-pressed">h:messages does not display messages when p:commandButton is pressed</a>.</p></li> <li><p>If <code>UICommand</code> or <code>UIInput</code> components are placed inside an iterating component like <code>&lt;h:dataTable&gt;</code>, <code>&lt;ui:repeat&gt;</code>, etc, then you need to ensure that exactly the same <code>value</code> of the iterating component is been preserved during the apply request values phase of the form submit request. JSF will reiterate over it to find the clicked link/button and submitted input values. Putting the bean in the view scope and/or making sure that you load the data model in <code>@PostConstruct</code> of the bean (and thus not in a getter method!) should fix it. See also <a href="https://stackoverflow.com/questions/5765853/when-should-i-load-the-collection-from-database-for-hdatatable">How and when should I load the model from database for h:dataTable</a>.</p></li> <li><p>If <code>UICommand</code> or <code>UIInput</code> components are included by a dynamic source such as <code>&lt;ui:include src="#{bean.include}"&gt;</code>, then you need to ensure that exactly the same <code>#{bean.include}</code> value is preserved during the view build time of the form submit request. JSF will reexecute it during building the component tree. Putting the bean in the view scope and/or making sure that you load the data model in <code>@PostConstruct</code> of the bean (and thus not in a getter method!) should fix it. See also <a href="https://stackoverflow.com/questions/7108668/how-to-ajax-refresh-dynamic-include-content-by-navigation-menu-jsf-spa">How to ajax-refresh dynamic include content by navigation menu? (JSF SPA)</a>.</p></li> <li><p>The <code>rendered</code> attribute of the component and all of its parents and the <code>test</code> attribute of any parent <code>&lt;c:if&gt;</code>/<code>&lt;c:when&gt;</code> should not evaluate to <code>false</code> during the apply request values phase of the form submit request. JSF will recheck it as part of safeguard against tampered/hacked requests. Storing the variables responsible for the condition in a <code>@ViewScoped</code> bean or making sure that you're properly preinitializing the condition in <code>@PostConstruct</code> of a <code>@RequestScoped</code> bean should fix it. The same applies to the <code>disabled</code> attribute of the component, which should not evaluate to <code>true</code> during apply request values phase. See also <a href="https://stackoverflow.com/questions/13326404/jsf-commandbutton-action-not-invoked">JSF CommandButton action not invoked</a> and <a href="https://stackoverflow.com/questions/18782503/form-submit-in-conditionally-rendered-component-is-not-processed">Form submit in conditionally rendered component is not processed</a>.</p></li> <li><p>The <code>onclick</code> attribute of the <code>UICommand</code> component and the <code>onsubmit</code> attribute of the <code>UIForm</code> component should not return <code>false</code> or cause a JavaScript error. There should in case of <code>&lt;h:commandLink&gt;</code> or <code>&lt;f:ajax&gt;</code> also be no JS errors visible in the browser's JS console. Usually googling the exact error message will already give you the answer. See also <a href="https://stackoverflow.com/questions/16166039/adding-jquery-to-primefaces-results-in-uncaught-typeerror-over-all-place">Adding jQuery to PrimeFaces results in Uncaught TypeError over all place</a>.</p></li> <li><p>If you're using Ajax via JSF 2.x <code>&lt;f:ajax&gt;</code> or e.g. PrimeFaces <code>&lt;p:commandXxx&gt;</code>, make sure that you have a <code>&lt;h:head&gt;</code> in the master template instead of the <code>&lt;head&gt;</code>. Otherwise JSF won't be able to auto-include the necessary JavaScript files which contains the Ajax functions. This would result in a JavaScript error like "mojarra is not defined" or "PrimeFaces is not defined" in browser's JS console. See also <a href="https://stackoverflow.com/questions/9933777/hcommandlink-actionlistener-is-not-invoked-when-used-with-fajax-and-uirepeat">h:commandLink actionlistener is not invoked when used with f:ajax and ui:repeat</a>.</p></li> <li><p>If you're using Ajax, then make sure that the <code>UIInput</code> and <code>UICommand</code> components of interest are covered by the <code>&lt;f:ajax execute&gt;</code> or e.g. <code>&lt;p:commandXxx process&gt;</code>, otherwise they won't be executed/processed. See also <a href="https://stackoverflow.com/questions/17960929/submitted-form-values-not-updated-in-model-when-adding-fajax-to-hcommandbut">Submitted form values not updated in model when adding &lt;f:ajax&gt; to &lt;h:commandButton&gt;</a> and <a href="https://stackoverflow.com/questions/25339056/understanding-process-and-update-attributes-of-primefaces">Understanding PrimeFaces process/update and JSF f:ajax execute/render attributes</a>.</p></li> <li><p>If a parent of the <code>&lt;h:form&gt;</code> with the <code>UICommand</code> button is beforehand been rendered/updated by an ajax request coming from another form in the same page, then the first action will always fail. The second and subsequent actions will work. This is caused by a bug in view state handling which is reported as <a href="http://java.net/jira/browse/JAVASERVERFACES_SPEC_PUBLIC-790" rel="noreferrer">JSF spec issue 790</a> and currently scheduled to be fixed in JSF 2.3. For older JSF versions, you need to explicitly specify the ID of the <code>&lt;h:form&gt;</code> in the <code>render</code> of the <code>&lt;f:ajax&gt;</code>. See also <a href="https://stackoverflow.com/questions/11408130/hcommandbutton-hcommandlink-does-not-work-on-first-click-works-only-on-second">h:commandButton/h:commandLink does not work on first click, works only on second click</a>.</p></li> <li><p>If the <code>&lt;h:form&gt;</code> has <code>enctype="multipart/form-data"</code> set in order to support file uploading, then you need to make sure that you're using at least JSF 2.2, or that the servlet filter who is responsible for parsing multipart/form-data requests is properly configured, otherwise the <code>FacesServlet</code> will end up getting no request parameters at all and thus not be able to apply the request values. How to configure such a filter depends on the file upload component being used. For Tomahawk <code>&lt;t:inputFileUpload&gt;</code>, check <a href="https://stackoverflow.com/questions/5418292/jsf-2-0-file-upload/5424229#5424229">this answer</a> and for PrimeFaces <code>&lt;p:fileUpload&gt;</code>, check <a href="https://stackoverflow.com/questions/8875818/how-to-use-primefaces-pfileupload-listener-method-is-never-invoked/8880083#8880083">this answer</a>. Or, if you're actually not uploading a file at all, then remove the attribute altogether.</p></li> <li><p>Make sure that the <code>ActionEvent</code> argument of <code>actionListener</code> is an <code>javax.faces.event.ActionEvent</code> and thus not <code>java.awt.event.ActionEvent</code>, which is what most IDEs suggest as 1st autocomplete option. Having no argument is wrong as well if you use <code>actionListener="#{bean.method}"</code>. If you don't want an argument in your method, use <code>actionListener="#{bean.method()}"</code>. Or perhaps you actually want to use <code>action</code> instead of <code>actionListener</code>. See also <a href="https://stackoverflow.com/questions/3909267/differences-between-action-and-actionlistener">Differences between action and actionListener</a>.</p></li> <li><p>Make sure that no <code>PhaseListener</code> or any <code>EventListener</code> in the request-response chain has changed the JSF lifecycle to skip the invoke action phase by for example calling <code>FacesContext#renderResponse()</code> or <code>FacesContext#responseComplete()</code>.</p></li> <li><p>Make sure that no <code>Filter</code> or <code>Servlet</code> in the same request-response chain has blocked the request fo the <code>FacesServlet</code> somehow.</p></li> <li><p>Bug in the framework. For example, RichFaces has a "<a href="https://issues.jboss.org/browse/RF-12594" rel="noreferrer">conversion error</a>" when using a <code>rich:calendar</code> UI element with a <code>defaultLabel</code> attribute (or, in some cases, a <code>rich:placeholder</code> sub-element). This bug prevents the bean method from being invoked when no value is set for the calendar date. Tracing framework bugs can be accomplished by starting with a simple working example and building the page back up until the bug is discovered.</p></li> <li><p>If you are using a PrimeFaces <code>p:dialog</code> or a <code>p:overlayPanel</code>, make sure you do not run into <a href="https://stackoverflow.com/questions/18958729/pcommandbutton-action-doesnt-work-inside-pdialog">p:commandbutton action doesn&#39;t work inside p:dialog</a></p></li> </ol> <h2>Debugging hints</h2> <p>In case you still stucks, it's time to debug. In the client side, press F12 in webbrowser to open the web developer toolset. Click the <em>Console</em> tab so see the JavaScript conosle. It should be free of any JavaScript errors. Below screenshot is an example from Chrome which demonstrates the case of submitting an <code>&lt;f:ajax&gt;</code> enabled button while not having <code>&lt;h:head&gt;</code> declared (as described in point 7 above).</p> <p><a href="https://i.stack.imgur.com/2qsLp.png" rel="noreferrer"><img src="https://i.stack.imgur.com/2qsLp.png" alt="js console"></a></p> <p>Click the <em>Network</em> tab to see the HTTP traffic monitor. Submit the form and investigate if the request headers and form data and the response body are as per expectations. Below screenshot is an example from Chrome which demonstrates a successful ajax submit of a simple form with a single <code>&lt;h:inputText&gt;</code> and a single <code>&lt;h:commandButton&gt;</code> with <code>&lt;f:ajax execute="@form" render="@form"&gt;</code>.</p> <p><a href="https://i.stack.imgur.com/mg5Al.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mg5Al.png" alt="network monitor"></a></p> <p><em>(warning: when you post screenshots from HTTP request headers like above from a production environment, then make sure you scramble/obfuscate any session cookies in the screenshot to avoid session hijacking attacks!)</em></p> <p>In the server side, make sure that server is started in debug mode. Put a debug breakpoint in a method of the JSF component of interest which you expect to be called during processing the form submit. E.g. in case of <code>UICommand</code> component, that would be <a href="http://grepcode.com/file/repo1.maven.org/maven2/javax.faces/javax.faces-api/2.2/javax/faces/component/UICommand.java#UICommand.queueEvent%28javax.faces.event.FacesEvent%29" rel="noreferrer"><code>UICommand#queueEvent()</code></a> and in case of <code>UIInput</code> component, that would be <a href="http://grepcode.com/file/repo1.maven.org/maven2/javax.faces/javax.faces-api/2.2/javax/faces/component/UIInput.java#UIInput.validate%28javax.faces.context.FacesContext%29" rel="noreferrer"><code>UIInput#validate()</code></a>. Just step through the code execution and inspect if the flow and variables are as per expectations. Below screenshot is an example from Eclipse's debugger.</p> <p><a href="https://i.stack.imgur.com/mnn5R.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mnn5R.png" alt="debug server"></a></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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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