p:ajax在h:graphicImage里面 [英] p:ajax inside h:graphicImage

查看:142
本文介绍了p:ajax在h:graphicImage里面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题发布一个ajax请求与Primefaces

 < f:元数据> 
< f:viewParam name =tokenvalue =#{clientBean.token}/>
< f:event type =preRenderViewlistener =#{clientBean.getParameter}/>
< / f:元数据>
< h:form>
< p:commandButton id =id4value =TactionListener =#{clientBean.tag}/>

<! - 这不起作用 - >
< p:ajax id =id3event =onclickonstart =dTag.show();
actionListener =#{clientBean.tag}/>
< / h:graphicImage>
< / h:表格>

第一个 h:graphicImage 打开对话框正确地说, p:commandButton 会正确触发actionListener,但 p:ajax 没有效果(在Google应用上测试引擎)。

更新1
事件点击点击是绝对正确的(感谢BalusC):现在显示 p:dialog 。但仍然不会调用 tag()方法。我使用 f:metadata 更新了 xhtml - 代码,因为还有一个额外的日志记录。
我认为它与 p:ajax 和bean的调用有关,我试过了 actionListener action listener (来自Primefaces的文档),结果如下:


  • 应用程序引擎日志调用 getParameter(ComponentSystemEvent event)并且Firebug显示这个部分更新:< changes>< update id =otCounter><<< ;![CDATA [< span id =otCounter> 0< / span>]]>< / update> ..

  • 调用 public void tag(ActionEvent ae)不会被记录(也试过 public void tag()



p:commandButton 正确更新计数器。



更新2
我已经删除了 f:viewParam f:现在使用侦听器 public void tag(),但是方法不被调用: - (



更新3 BalusC的答案是正确的,在这里使用它时我还有其他问题: JSF和p: ajax里面的p:dataTable里面的ui:repeat 解析方案

事件名称是错误的,它必须是点击,而前缀不包含 $ b

 < h:graphicImage id =id2url =/ images / circle-ok.png> 
< p:ajax id =id3event =clickonstart =dTag.show();
listener =#{clientBean.tag}/>
< / h:graphicImage>

事件前缀仅适用于为事件处理程序提供钩子的HTML元素属性的名称。请注意< p:ajax> 不支持 actionListener 属性。它必须是 listener ,并且应该引用一个方法,该方法需要 AjaxBehaviourEvent 作为参数(没有参数也非常好)。这与< f:ajax> 完全相同。


I have problem firing an ajax request with Primefaces

<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>

The first h:graphicImage opens the dialog correctly, the p:commandButton triggers the actionListener correctly, but the p:ajax has no effects (tested on googles app engine).

Update 1 Changing the event from onclick to click was absolutely right (thanks BalusC): Now the p:dialog is shown. But still the tag() method is not invoked. I've updated the xhtml-Code with f:metadata because there is one additional logging. I think it's related to p:ajax and the invocation of the bean, I've tried actionListener, action and listener (from the documentation of Primefaces) with the same result:

  • The app engines logs the invocation of getParameter(ComponentSystemEvent event) and Firebug shows this partial-update: <changes><update id="otCounter"><![CDATA[<span id="otCounter">0</span>]]></update>..
  • The invocation of public void tag(ActionEvent ae) is not logged (also tried public void tag())

The p:commandButton updates the counter correctly.

Update 2 I've removed the f:viewParam and f:event for simplicity and now are using listener and public void tag(), but the method is not called :-(

Update 3 The answer of BalusC is correct, I have other problems when using it here: JSF and p:ajax inside p:dataTable inside ui:repeat

解决方案

The event name is wrong, it must be "click" without the on prefix.

<h:graphicImage id="id2" url="/images/circle-ok.png">
    <p:ajax id="id3" event="click" onstart="dTag.show();"
        listener="#{clientBean.tag}" />
</h:graphicImage>

The on prefix of events applies only the names of the HTML element attributes which provide a hook for the event handler. They do not represent full event names.

Note the <p:ajax> doesn't support the actionListener attribute. It has to be listener and should refer to a method which takes AjaxBehaviourEvent as argument (no arguments is also perfectly fine). This is exactly the same as on <f:ajax>.

这篇关于p:ajax在h:graphicImage里面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆