博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
commandLink/commandButton/ajax backing bean action/listener method not invoked (转)
阅读量:5851 次
发布时间:2019-06-19

本文共 4904 字,大约阅读时间需要 16 分钟。

Whenever an UICommand component fails to invoke the associated action method or an UIInputelement fails to update the model value, and you aren't seeing any obvious exceptions/warnings in the server log, then verify the following:

  1. UICommand and UIInput components must be placed inside an UIForm component, e.g. <h:form>, and UICommand components must not have type="button" attribute (get rid of it, that's only for push buttons, not for submit buttons).

  2. You cannot nest multiple UIForm components in each other. This is namely illegal in HTML. Watch out with include files! You can use UIForm components in parallel, but they won't process each other during submit.

  3. No UIInput value validation/conversion error should have occurred. You can use <h:messages> to show any messages which are not shown by any input-specific <h:message>components. Don't forget to include the id of <h:messages> in the <f:ajax render>, if any, so that it will be updated as well on ajax requests.

  4. If UICommand or UIInput components are placed inside an iterating component like <h:dataTable><ui:repeat>, etc, then you need to ensure that exactly the same value of the iterating component is been preserved during the apply request values phase of the form submit request. JSF will namely 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 @PostConstruct of the bean (!) should fix it.

  5. The rendered attribute of the component and all of the parent components should not evaluate tofalse during the apply request values phase of the form submit request. JSF will namely recheck it as part of safeguard against tampered/hacked requests. Making the bean @ViewScoped or making sure that you're properly preinitializing the condition in @PostConstructof a @RequestScoped bean should fix it. The same applies to the disabled attribute of the component, which should not evaluate to true during apply request values phase.

  6. The onclick attribute of the UICommand component and the onsubmit attribute of the UIFormcomponent should not return false or cause a JavaScript error. There should in case of <h:commandLink> or <f:ajax> also be no JS errors in the document. In recent browsers you can press F12 to get the web developer toolset with the JS console. All JS errors will be logged there. Usually googling the exact error message will already give you the answer.

  7. If you're using JSF 2.x <f:ajax> on the command component, make sure that you have a <h:head> in the master template instead of the <head>. Otherwise JSF won't be able to auto-include the necessary jsf.js JavaScript file which contains the Ajax functions. This would result in a JavaScript error like "mojarra is not defined" in the JS console.

  8. If a parent of the <h:form> with the UICommand 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  and currently scheduled to be fixed in JSF 2.3. For older JSF versions, you need to explicitly specify the ID of the <h:form> in the render of the <f:ajax>, or to use the script in .

  9. If the <h:form> has enctype="multipart/form-data" 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 FacesServlet 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 <t:inputFileUpload>, check  and for PrimeFaces <p:fileUpload>, check . Or, if you're actually not uploading a file at all, then remove the attribute altogether.

  10. Be sure that the ActionEvent argument of actionListener is anjavax.faces.event.ActionEvent and thus not java.awt.event.ActionEvent, which is what most IDEs suggest as 1st autocomplete option.

  11. Be sure that no PhaseListener or any EventListener in the request-response chain has changed the JSF lifecycle to skip the invoke action phase by for example calling FacesContext#renderResponse() or FacesContext#responseComplete().

  12. Be sure that no Filter or Servlet in the same request-response chain has blocked the request fo the FacesServlet somehow.

My bet that your particular problem is caused by point 2: nested forms. You probably already have a <h:form> in the parent page which wraps the include file. The include file itself should not have a <h:form>. You can also fix it the other way round, ensure that the parent page does not have a <h:form> around the place of the include file.

转载于:https://www.cnblogs.com/bigbang92/p/jsf_commandLink_commandButton_not_invoke.html

你可能感兴趣的文章
Dubbo架构设计简单了解
查看>>
网络编程:基于C语言的简易代理服务器实现(proxylab)
查看>>
badboy录制网站出现css样式混乱,网页的图标点击没反应
查看>>
步步为营 .NET 设计模式学习笔记系列总结
查看>>
WIN2008服务器不能复制粘贴怎么办
查看>>
jQuery插件开发
查看>>
链路层
查看>>
Canvas_2
查看>>
unity工具IGamesTools之批量生成帧动画
查看>>
Thread和Runnable
查看>>
多系统盘挂载
查看>>
virtualbox+vagrant学习-2(command cli)-25-Machine Readable Output
查看>>
2018.8.2-8.6学习内容
查看>>
element-ui tree树形组件自定义实现可展开选择表格
查看>>
递归算法
查看>>
Python(三)-文件处理
查看>>
linux 挂载硬盘
查看>>
[linux] 替换字符串
查看>>
IE6和Opera position:absolute; 子元素浮动 width:100%;显示不正确问题。。。
查看>>
[高数][高昆轮][高等数学上][第一章-函数与极限]03.函数的极限
查看>>