JSF到JQuery组件集成 [英] JSF to JQuery Component Integration

查看:239
本文介绍了JSF到JQuery组件集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于任何JSF页面在服务器端转换为等效的HTML并发送到客户端进行渲染,客户端的JQuery将获取HTML并重新呈现它。

Since any JSF page gets transformed at the server side into its equivalent HTML and sent to the client for rendering, and JQuery at the client side takes the HTML and re renders it.

从理论上讲,应该可以获取由JSF生成的HTML并将其包装到JQuery中,如果是这样,我想知道它是如何完成的。如果可能,特别使用RichFaces作为JSF实现。

In theory it should be possible to take the HTML that is a generated by JSF and wrap it into JQuery, if so I would like to know how it's done. Specifically using RichFaces as the JSF implementation if possible.

<rich:dataTable id="table">          
  <rich:column>

  </rich:column>
</rich:dataTable>

上面的JSF片段被转换为等效的HTML,这就是这个

The above snippet of JSF is transformed into it's equivalent HTML which is this

<table id="table">
  <tr>
    <td></td>
  </tr>
</table>

不应该做这样的事情

<script type="text/javascript">
   $(document).ready(function () {
     $('#table').dataTable();
}
</script>

我已经尝试过了,但似乎没有用。

I've already tried that but it doesn't seem to work.

所以,如果有人有任何提示,我会非常感激。

So please if anyone has any hints, I'd be more than grateful.

推荐答案

混合JSF和jquery是可行,但有一些问题。

Mixing JSF and jquery is doable but there are some gotchas.

JSF接管你的id,所以如果table是一个id为form的表单,html中的实际元素id将是默认情况下form:table。我认为jquery可能在选择器中出现冒号问题,所以你可以用一个类来标记你的表并选择它:

JSF is taking over your ids, so if table is in a form with id "form", the actual element id in html would be by default "form:table". I think jquery could have a problem with colon in a selector, so you may mark your table with a class and select by that:

<rich:dataTable styleClass="my-table">          
  <rich:column>

  </rich:column>
</rich:dataTable>

并将选择器设置为:

<script type="text/javascript">
   $(document).ready(function () {
     $('.my-table').dataTable();
}
</script>

这篇关于JSF到JQuery组件集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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