让我们考虑这个简单的代码:
<h:form id="myForm">
<h:inputText id="myInput">
<a4j:support event="onchange" actionListener="#{myBean.doSomething}"/>
</h:inputText>
</h:form>
这将生成以下 HTML 代码:
<input id="myForm:myInput" type="text" name="myForm:myInput" onchange="A4J.AJAX.Submit(...)" />
现在,我只是在我的情况下添加一些onchange
东西<h:inputText>
:
<h:form id="myForm">
<h:inputText id="myInput" onchange="alert('foobar');">
<a4j:support event="onchange" actionListener="#{myBean.doSomething}"/>
</h:inputText>
</h:form>
这将生成以下 HTML 代码:
<input id="myForm:myInput" type="text" name="myForm:myInput" onchange="alert('foobar');" />
如您所见,不再添加Ajax 代码。就我而言,这是一种非常奇怪的行为。如果事件已在输入字段中定义,为什么<a4j:support>
不附加 Ajax 调用?
所以我的问题是如何进行已经定义的<a4j:support>
工作?当然,解决方案必须同时运行中定义的 Javascript 代码和Ajax 调用。event
input
onchange
换句话说,我想要以下 HTML:
<input id="myForm:myInput" type="text" name="myForm:myInput" onchange="alert('foobar'); A4J.AJAX.Submit(...)" />
我正在使用 Richfaces 3.3.2 和 JSF 1.2
编辑
当然,我可以在 的属性中移动onchange
Javascript 代码,执行以下操作:onsubmit
<a4j:support>
<h:inputText id="myInput">
<a4j:support onsubmit="alert('foobar');" event="onchange" actionListener="#{myBean.doSomething}"/>
</h:inputText>
但这是唯一的方法吗??