2012-04-25 39 views
1

我在使用JSF數據表的JQuery時遇到問題。JQuery不適用於JSF動態UI組件

我有這樣的代碼:

<script type="text/javascript" charset="utf-8"> 
      $(document).ready(function() { 
       $('<b>#example</b>').dataTable({ 
        "aoColumns": [ 
         { "asSorting": [ "asc" ] }, 
         { "asSorting": [ "asc" ] }, 
         { "asSorting": [ "desc", "asc", "asc" ] }, 
         { "asSorting": [ "desc" ] }, 
         { "asSorting": [ "asc" ] }, 
         { "asSorting": [ "asc" ] } 
        ] 
       }); 
      }); 
     </script> 

XHTML

<h:dataTable id="example" name="example" value="#{notificationBean.notificationList}" var="item" 
       cellpadding="0" cellspacing="0" border="0" 
       styleClass="display" 
       rowClasses="gradeC" 
       style="background-image: url('../images/ClientCare_Menu_Gradient.jpg'); background-repeat: repeat-x;"> 

當它呈現:

<table id="searchform:example" class="display" cellspacing="0" cellpadding="0" border="0" style="background-image: url('../images/ClientCare_Menu_Gradient.jpg'); background-repeat: repeat-x;"> 

現在我的問題是,其有權申請DataTable中的CSS沒有得到應用。

我嘗試了不同的記號它仍然沒有工作 jQuery中我嘗試:

$ { '#searchform:例如'} $ { '#searchform.example'} 在這種情況下,對哈弗行動包含表本身將無法顯示數據表。

$ {「searchform#例如」} $ {「#例如」} 在這種情況下,懸停動作工程和數據表上渲染,但CSS是不適用

在這個任何人都可以幫助?

預先感謝 迪帕克

+0

那是什麼''在jQuery選擇做什麼呢? – BalusC 2012-04-25 16:54:33

+0

看看這個相關[回答](http://stackoverflow.com/questions/973496/cannot-pickup-id-with-jquery-for-the-jsf-textarea) – landal79 2012-04-25 16:57:51

+0

只是一個格式化.. 。我只是試圖讓它大膽 – user1356720 2012-04-25 19:24:18

回答

1

你不必由JSF <h:dataTable>組件的組件ID來選擇所生成的HTML <table>元素的客戶端ID。 HTML ID在您的特定情況下爲searchform:example。由於:是CSS選擇器非法字符,你需要逃避它:

$("#searchform\\:example") 

或改用屬性選擇:

$("[id='searchform:example']") 

更容易將給予<h:dataTable>而不是一個風格類。

<h:dataTable styleClass="example"> 

在您的特定情況下,你已經有了一個

<h:dataTable styleClass="display"> 

所以,你也可以只用

$(".display") 
+0

哇哇第一個選項確實像魅力一樣工作... 非常感謝Balu ... :) :) – user1356720 2012-04-25 19:18:00

相關問題