jsf - commandButton/commandLink/ajax action/listener method not invoked or input value not set/updated -


sometimes, when using <h:commandlink>, <h:commandbutton> or <f:ajax>, action, actionlistener or listener method associated tag not being invoked. or, bean properties not updated submitted uiinput values.

what possible causes , solutions this?

introduction

whenever uicommand component (<h:commandxxx>, <p:commandxxx>, etc) fails invoke associated action method, or uiinput component (<h:inputxxx>, <p:inputxxxx>, etc) fails process submitted values and/or update model values, , aren't seeing googlable exceptions and/or warnings in server log, not when configure ajax exception handler per exception handling in jsf ajax requests, nor when set below context parameter in web.xml,

<context-param>     <param-name>javax.faces.project_stage</param-name>     <param-value>development</param-value> </context-param> 

and not seeing googlable errors and/or warnings in browser's javascript console (press f12 in chrome/firefox23+/ie9+ open web developer toolset , open console tab), work through below list of possible causes.

possible causes

  1. uicommand , uiinput components must placed inside uiform component, e.g. <h:form> (and not plain html <form>), otherwise nothing can sent server. uicommand components must not have type="button" attribute, otherwise dead button useful javascript onclick. see how send form input values , invoke method in jsf bean , <h:commandbutton> not initiate postback.

  2. you cannot nest multiple uiform components in each other. illegal in html. browser behavior unspecified. watch out include files! can use uiform components in parallel, won't process each other during submit. should watch out "god form" antipattern; make sure don't unintentionally process/validate other (invisible) inputs in same form (e.g. having hidden dialog required inputs in same form). see how use <h:form> in jsf page? single form? multiple forms? nested forms?.

  3. no uiinput value validation/conversion error should have occurred. can use <h:messages> show messages not shown input-specific <h:message> components. don't forget include id of <h:messages> in <f:ajax render>, if any, updated on ajax requests. see h:messages not display messages when p:commandbutton pressed.

  4. if uicommand or uiinput components placed inside iterating component <h:datatable>, <ui:repeat>, etc, need ensure same value of iterating component been preserved during apply request values phase of form submit request. jsf reiterate on find clicked link/button , submitted input values. putting bean in view scope and/or making sure load data model in @postconstruct of bean (and not in getter method!) should fix it. see how , when should load model database h:datatable.

  5. the rendered attribute of component , of parents , test attribute of parent <c:if>/<c:when> should not evaluate false during apply request values phase of form submit request. jsf recheck part of safeguard against tampered/hacked requests. storing variables responsible condition in @viewscoped bean or making sure you're preinitializing condition in @postconstruct of @requestscoped bean should fix it. same applies disabled attribute of component, should not evaluate true during apply request values phase. see jsf commandbutton action not invoked , form submit in conditionally rendered component not processed.

  6. the onclick attribute of uicommand component , onsubmit attribute of uiform component should not return false or cause javascript error. there should in case of <h:commandlink> or <f:ajax> no js errors visible in browser's js console. googling exact error message give answer. see adding jquery primefaces results in uncaught typeerror on place.

  7. if you're using ajax via jsf 2.x <f:ajax> or e.g. primefaces <p:commandxxx>, make sure have <h:head> in master template instead of <head>. otherwise jsf won't able auto-include necessary javascript files contains ajax functions. result in javascript error "mojarra not defined" or "primefaces not defined" in browser's js console. see h:commandlink actionlistener not invoked when used f:ajax , ui:repeat.

  8. if you're using ajax, make sure uiinput , uicommand components of interest covered <f:ajax execute> or e.g. <p:commandxxx process>, otherwise won't executed/processed. see submitted form values not updated in model when adding <f:ajax> <h:commandbutton> , understanding primefaces process/update , jsf f:ajax execute/render attributes.

  9. if parent of <h:form> uicommand button beforehand been rendered/updated ajax request coming form in same page, first action fail. second , subsequent actions work. caused bug in view state handling reported jsf spec issue 790 , scheduled fixed in jsf 2.3. older jsf versions, need explicitly specify id of <h:form> in render of <f:ajax>. see h:commandbutton/h:commandlink not work on first click, works on second click.

  10. if <h:form> has enctype="multipart/form-data" set in order support file uploading, need make sure you're using @ least jsf 2.2, or servlet filter responsible parsing multipart/form-data requests configured, otherwise facesservlet end getting no request parameters @ , not able apply request values. how configure such filter depends on file upload component being used. tomahawk <t:inputfileupload>, check this answer , primefaces <p:fileupload>, check this answer. or, if you're not uploading file @ all, remove attribute altogether.

  11. make sure actionevent argument of actionlistener javax.faces.event.actionevent , not java.awt.event.actionevent, ides suggest 1st autocomplete option. having no argument wrong if use actionlistener="#{bean.method}". if don't want argument in method, use actionlistener="#{bean.method()}". or perhaps want use action instead of actionlistener. see differences between action , actionlistener.

  12. make sure no phaselistener or eventlistener in request-response chain has changed jsf lifecycle skip invoke action phase example calling facescontext#renderresponse() or facescontext#responsecomplete().

  13. make sure no filter or servlet in same request-response chain has blocked request fo facesservlet somehow.

  14. bug in framework. example, richfaces has "conversion error" when using rich:calendar ui element defaultlabel attribute (or, in cases, rich:placeholder sub-element). bug prevents bean method being invoked when no value set calendar date. tracing framework bugs can accomplished starting simple working example , building page until bug discovered.

debugging hints

in case still stucks, it's time debug. in client side, press f12 in webbrowser open web developer toolset. click console tab see javascript conosle. should free of javascript errors. below screenshot example chrome demonstrates case of submitting <f:ajax> enabled button while not having <h:head> declared (as described in point 7 above).

js console

click network tab see http traffic monitor. submit form , investigate if request headers , form data , response body per expectations. below screenshot example chrome demonstrates successful ajax submit of simple form single <h:inputtext> , single <h:commandbutton> <f:ajax execute="@form" render="@form">.

network monitor

(warning: when post screenshots http request headers above production environment, make sure scramble/obfuscate session cookies in screenshot avoid session hijacking attacks!)

in server side, make sure server started in debug mode. put debug breakpoint in method of jsf component of interest expect called during processing form submit. e.g. in case of uicommand component, uicommand#queueevent() , in case of uiinput component, uiinput#validate(). step through code execution , inspect if flow , variables per expectations. below screenshot example eclipse's debugger.

debug server


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -