commandLink/commandButton/ajax backing bean action/listener method not invoked (转)
Whenever an UICommand
component fails to invoke the associated action method or an UIInput
element fails to update the model value, and you aren't seeing any obvious exceptions/warnings in the server log, then verify the following:
UICommand
andUIInput
components must be placed inside anUIForm
component, e.g.<h:form>
, andUICommand
components must not havetype="button"
attribute (get rid of it, that's only for push buttons, not for submit buttons).You cannot nest multiple
UIForm
components in each other. This is namely illegal in HTML. Watch out with include files! You can useUIForm
components in parallel, but they won't process each other during submit.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 theid
of<h:messages>
in the<f:ajax render>
, if any, so that it will be updated as well on ajax requests.If
UICommand
orUIInput
components are placed inside an iterating component like<h:dataTable>
,<ui:repeat>
, etc, then you need to ensure that exactly the samevalue
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 (and thus not in a getter method!) should fix it.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@PostConstruct
of a@RequestScoped
bean should fix it. The same applies to thedisabled
attribute of the component, which should not evaluate totrue
during apply request values phase.The
onclick
attribute of theUICommand
component and theonsubmit
attribute of theUIForm
component should not returnfalse
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.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 necessaryjsf.js
JavaScript file which contains the Ajax functions. This would result in a JavaScript error like "mojarra is not defined" in the JS console.If a parent of the
<h:form>
with theUICommand
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 JSF spec issue 790 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 therender
of the<f:ajax>
, or to use the script in this answer.If the
<h:form>
hasenctype="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 theFacesServlet
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 this answer and for PrimeFaces<p:fileUpload>
, check this answer. Or, if you're actually not uploading a file at all, then remove the attribute altogether.Be sure that the
ActionEvent
argument ofactionListener
is anjavax.faces.event.ActionEvent
and thus notjava.awt.event.ActionEvent
, which is what most IDEs suggest as 1st autocomplete option.Be sure that no
PhaseListener
or anyEventListener
in the request-response chain has changed the JSF lifecycle to skip the invoke action phase by for example callingFacesContext#renderResponse()
orFacesContext#responseComplete()
.Be sure that no
Filter
orServlet
in the same request-response chain has blocked the request fo theFacesServlet
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.
commandLink/commandButton/ajax backing bean action/listener method not invoked (转)的更多相关文章
- 4 ways to pass parameter from JSF page to backing bean
As i know,there are 4 ways to pass a parameter value from JSF page to backing bean : Method expressi ...
- JQuery ajax请求struts action实现异步刷新的小实例
这个样例是用JQuery ajax和struts来做的一个小样例,在这个样例中采用两种方式将java Util中的list转换成支json的格式,第一种是用json-lib.jar这个jar包来转换, ...
- form里面的action和method(post和get的方法)使用
一.form里面的action和method的post使用方法 <%@ Page Language="C#" AutoEventWireup="true" ...
- 关于Struts2中 Action 配置method的解读
为Action配置method属性: 将Action类中的每一个处理方法都定义成一个逻辑Action方法. <!DOCTYPE struts PUBLIC "-//Apache Sof ...
- EF5+MVC4系列(11)在主视图中用Html.RenderPartial调用分部视图(ViewDate传值);在主视图中按钮用ajax调用子action并在子action中使用return PartialView返回分布视图(return view ,return PartialView区别)
一:主视图中使用Html.RenderPartial来调用子视图(注意,这里是直接调用子视图,而没有去调用子Action ) 在没有使用母版页的主视图中(也就是设置了layout为null的视图中), ...
- ajax调用,action返回的中文为乱码的解决方案
原文:ajax调用,action返回的中文为乱码的解决方案 版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.c ...
- jQuery ajax请求struts action实现异步刷新
第一步:导入相关jar包,本样例需导入struts相关jar包,json-lib.jar,gson-2.1.jar可以任意选择,但是这里需要都导入,因为为了做测试,两种jar包的转换方式都用到了. 第 ...
- ADF backing Bean中常用的代码
// 刷新iterator bindings.refreshControl(); iterBind.executeQuery(); iterBind.refresh(DCIteratorBinding ...
- Struts.xml中Action的method与路径的三种匹配方法
原文 http://blog.csdn.net/woshixuye/article/details/7734482 首先我们有一个Action——UserAction public class Us ...
随机推荐
- php数组函数-array_reduce()
array_reduce()函数发送数组中的值到用户自定义函数,并返回一个字符串. 注:如果数组是空的或则初始化值未传递,该函数返回NULL array_reduce(array,myfunction ...
- 20145240 《Java程序设计》第五周学习总结
20145240 <Java程序设计>第五周学习总结 教材学习内容总结 语法与继承结构 8.1.1使用try.catch java中所有的错误都会被打包为对象,并提供了特有的语句进行处理. ...
- codeforces 353D 递推 找规律
题意:一组男生女生在排队,每秒钟所有排在女生左边的男生与她相邻的女生交换位置,求女生全部换到男生前面的时间. 思路: 解法一:队伍最前面的那些女生不需要交换,后面的女生有两种状态:畅通无阻,前一个女生 ...
- linux与windows 通过SecureCRT进行文件传输方式
linux与windows 通过SecureCRT进行文件传输方式 方式一:lrzsz是一款在Linux里可代替ftp上传和下载的程序.(小文件推荐,以4G为界限) # rz -bash: rz: c ...
- streambase一些疑难杂症
1.webserverReqest控件接收不到换行符\r\n 方案一:这个在streambase7.6.7没有办法处理,只有在streambase7.7.4中才有办法处理,在这个版本中出现了Reque ...
- spark学习2-1(hive1.2安装)
由于前面安装版本过老,导致学习过程中出现了很多问题,今天安装了一个新一点的版本.安装结束启动时遇到一点问题,记录在这里. 第一步:hive-1.2安装 通过WinSCP将apache-hive-1.2 ...
- HRBUST 1717 字典树模板
之前写字典树虽然很熟也能变化 但是一直是到了场上再乱写 写的很长 于是准备写个短点的板子 于是选了个水题 然而写出了1W个bug insert和query反而写的没什么问题.. L c[100050] ...
- js数字过大js自动变0
解决方案: <a onclick="checkDate(${item.billday},'${item.bankcard}',${item.limitmoney/100}) 加上引号变 ...
- python之Django rest_framework总结
一.rest api a.api就是接口 如: - http://www.oldboyedu.com/get_user/ - http://www. ...
- IOS开发--解析复杂json数据
json的自我介绍:JSON(JavaScript Object Notation)是一种轻量级的数据交换格式.JSON采用完全独立于语言的文本格式,这些特性使JSON成为理想的数据交换语言.易于人阅 ...