2012-08-07 69 views
0

有新聞titles.and用戶點擊這些titles.browser轉到這個標題的消息的鞋的頁面。我想要從數據庫中獲取數據,其中id等於元素id是clicked.element從數據庫中獲取id我不提前知道身份證。如何在JSF中獲取HTML元素的id?

<ui:repeat value="#{controller.sql.yenilikler}" var="list"> 
    <a href="xeberShekil.xhtml" id="#{list.id}}"> 
    #{list.basliq} 
    </a> 
<br/> 
</ui:repeat> 

所以我應該

1.get其被點擊

2.發送該ID到一個變量中的java類

3.send查詢的元件,其是的id從數據庫獲得數據,其中id =元素的ID

int id; 
ResultSet rs= statement.executeQuery("select * from tableName where id="+id); 

如果其他算法建議請採用F share.Tnx很多

回答

0

值傳遞給託管bean:PARAM,F:setPropertyActionListner或直接使用命令按鈕的行動= 「#{bean.someAction(值)}」

JSF-2 Action Parameter的價值傳遞代碼片段。

編輯代碼

數據表

 <h:dataTable value="#{someManagedBean.categories}" var="cat"> 
       <h:column> 
         <h:commandButton action="#{someManagedBean.edit(cat.id)}" 
       </h:column> 

     </h:dataTable> 

Managed Bean的

 public void edit(id) { 
       doYourDBThing(id); 

     } 

您也可以使用f:PARAM和f:setPropertyActionListner。看到上面的鏈接。

+0

johny你能寫一個小例子來使用... – 2012-08-07 13:20:43