JSF:: h:commandLink onsubmit(return validateRow(this)) probl
JSF:: h:commandLink onsubmit(return validateRow(this)) problem
我在datatable中的一个列中有一个h:commandLink。
JSF<h:commandLink id="save" actionListener="#{ApplicationManagerBean.update}"
rendered="#{routeappcode.edit}"
value="save" onclick="return validateRow(this)"/>
生成的HTML是
<a id="routeappcodesummary:summarytable:2:save"
onclick="var cf = function(){return validateRow(this)};
var oamSF = function(){return oamSubmitForm('routeappcodesummary','routeappcodesummary:summarytable:2:save');};return (cf()==false)? false : oamSF();"
href="#">save</a>
1.2银鲈_15
<a href="#" onclick="var a=function(){return validateRow(this);};var b=function()
{if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('j_id_jsp_1765393453_2'),
{'j_id_jsp_1765393453_2:j_id_jsp_1765393453_3:0:j_id_jsp_1765393453_7':'j_id_jsp_1765393453
_2:j_id_jsp_1765393453_3:0:j_id_jsp_1765393453_7'},'');}return false};return (a()==false) ?
false : b();">test</a>
这里为onclick生成的javascript封装了JSF标签中提供的脚本。
function validateRow(link){
//link is not a link object but some window object.
var parent = link.parentNode;
}
在javascript函数中,我们得到的不是一个链接对象,而是一个窗口对象。原因是JSF标签中提供的脚本被封装了,由于的值这个参考变化。
我怎样才能解决这个问题,这样我就可以在我的脚本中获得链接对象?
使用onmouseup无法在ie6中工作
使用JSF 1.2
你确实不能给你的JavaScript函数this
的引用,因为onclick
代码将被封装在JavaScript函数中。
你可以尝试使用一些JavaScript代码在你的validateRow()
函数中找到这个链接元素,正如Stig Henriksen提出的那样。
<h:commandLink id="save" actionListener="#{ApplicationManagerBean.update}"
rendered="#{routeappcode.edit}" value="save"
onclick="return validateRow();" styleClass="saveLink"/>
然后,在你的JavaScript代码(我使用jQuery在这里,但你可以使用纯JS代替):
function validateRow() {
// We retrieve a jQuery object:
var jQueryObject = $("a.saveLink");
// If you prefer to get a "pure" JavaScript object
var pureJavaScriptObject = $("a.saveLink").get(0);
// continue your work here...
}
我不知道为什么JSF会这样做,但是这里有一个使用jQuery获取链接的变通方法:
<h:commandLink id="save" actionListener="#{ApplicationManagerBean.update}"
rendered="#{routeappcode.edit}"value="save"
onclick="return validateRow($('a[id*=save]')[0])"/>
相关文章:
- $(this).prop('property') vs. this.property
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 在另一个函数中使用变量this
- this.router在AngularJS 2中未定义
- reactjs this.refs vs document.getElementById
- JavaScript 中的嵌套函数和 “this” 关键字
- React+Meteor:this.ops返回未定义
- javascript中对象构造函数中的var属性与this.properties
- 函数中this和var之间的区别
- jQuery(this).Pparent().Pparente().Prent().find()在iPad上不起作用
- Understanding Javascript scope with "var that = this&qu
- 定义this.properties或objectName.properties的javascript JSON对象
- Object.prototype using 'this'
- 在JavaScript类型的函数中避免self-this
- 如何使用(this)访问Angular 2 http rxjs catch函数中的对象属性
- Javascript 对象和 this 关键字
- jQuery使用ajax自动完成问题-TypeError:this.source不是函数
- reactjs无法将this.pops传递到react图表列表中
- 为什么在这种情况下,“This”确实充当javascript函数中的私有成员
- JSF:: h:commandLink onsubmit(return validateRow(this)) probl