简体   繁体   English

JSF到JQuery组件集成

[英]JSF to JQuery Component Integration

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会获取HTML并重新呈现。

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. 从理论上讲,应该有可能采用JSF生成的HTML并将其包装到JQuery中,如果这样的话,我想知道它是如何完成的。 Specifically using RichFaces as the JSF implementation if possible. 如果可能,请特别使用RichFaces作为JSF实现。

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

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

The above snippet of JSF is transformed into it's equivalent HTML which is this 上面的JSF片段被转换为等效的HTML,这是

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

Shouldn't it be possible to do something like this 应该不会做这样的事情

<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. 因此,如果有人有任何提示,请多谢。

Mixing JSF and jquery is doable but there are some gotchas. 混合使用JSF和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". JSF将接管您的ID,因此,如果table的ID为“ form”,则html中的实际元素ID默认为“ 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: 我认为jquery可能在选择器中出现冒号问题,因此您可以在表中标记一个类并通过以下方式进行选择:

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

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

and set selector as: 并将选择器设置为:

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

The Id's of the JSF components are generated by combining the Id's of the containers on the hierarchy with a : separator. 通过将层次结构上的容器的ID与:分隔符组合在一起,可以生成JSF组件的ID。 Not all the containers count, I don't remember exactly the rules. 并非所有容器都在计数,我不记得确切的规则。

Normally some JSF libraries have some client side API to get the component ID's I don't know for richfaces. 通常,某些JSF库具有一些客户端API来获取Richfaces所不知道的组件ID。

Anyway, if you'd like to use jQuery based JSF, take a look at primefaces. 无论如何,如果您想使用基于jQuery的JSF,请看一下primefaces。

Hope this helps. 希望这可以帮助。

This issue might be a '$' name spacing conflict arisen by the Jquery and rich faces component which is made of Prototype.js.Try using jQuery.noconflict() method. 这个问题可能是由Prototype.js构成的Jquery和rich face组件引起的'$'名称间距冲突。请尝试使用jQuery.noconflict()方法。 I had a similar problem of making the jquery work with richfaces jquery.noconflict() did the trick.. 我有使jquery与richfaces一起工作的类似问题jquery.noconflict()可以解决问题。

<script type="text/javascript">
  $.noConflict();
  jQuery(document).ready(function($) {
 // Code that uses jQuery's $ can follow here.
 });
// Code that uses other library's $ can follow here.
</script>

Good Luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM