我在用Primefaces触发ajax请求时有问题
<f:metadata>
<f:viewParam name="token" value="#{clientBean.token}"/>
<f:event type="preRenderView" listener="#{clientBean.getParameter}" />
</f:metadata>
<h:form>
<h:graphicImage id="id1" url="/images/circle-ok.png" onclick="dTag.show();"/>
<p:commandButton id="id4" value="T" actionListener="#{clientBean.tag}" />
<!-- This does not work -->
<h:graphicImage id="id2" url="/images/circle-ok.png">
<p:ajax id="id3" event="onclick" onstart="dTag.show();"
actionListener="#{clientBean.tag}" />
</h:graphicImage>
</h:form>第一个h:graphicImage正确地打开对话框,p:commandButton正确地触发actionListener,但是p:ajax没有效果(在googles应用引擎上测试)。
Update 1将event从单击更改为单击是绝对正确的(谢谢BalusC):现在显示了p:dialog。但是仍然没有调用tag()方法。我用xhtml-Code更新了f:metadata,因为还有一个额外的日志记录。我认为它与p:ajax和bean调用有关,我尝试了actionListener、动作和侦听器(来自Primefaces的文档),结果是相同的:
应用程序引擎记录了对<changes><update id="otCounter"><![CDATA[<span id="otCounter">0</span>]]></update>..
public void tag(ActionEvent ae)的调用(也尝试过getParameter(ComponentSystemEvent event) )。p:commandButton正确地更新计数器。
为了简单起见,我已经删除了和f:event,现在正在使用listener和public void tag(),但是方法没有被调用:-(
更新3 BalusC的答案是正确的,我在这里使用它时还有其他问题:JSF and p:ajax inside p:dataTable inside ui:repeat
发布于 2011-09-05 12:54:10
事件名是错误的,它必须是没有"click"前缀的on。
<h:graphicImage id="id2" url="/images/circle-ok.png">
<p:ajax id="id3" event="click" onstart="dTag.show();"
listener="#{clientBean.tag}" />
</h:graphicImage>事件的on前缀只应用为事件处理程序提供钩子的HTML属性的名称。它们不代表完整的事件名称。
注意,<p:ajax>不支持actionListener属性。它必须是listener,并且应该引用以AjaxBehaviourEvent为参数的方法(没有参数也很好)。这与<f:ajax>上的情况完全相同。
https://stackoverflow.com/questions/7307407
复制相似问题