2012-07-03 31 views
0

我試圖讓一個簡單的commandLink工作。以下是頁面的代碼片段:JSF 2.0 commandLink - 操作未被調用,JavaScript錯誤

<div class="item-single"> 
    <h:graphicImage value="image/screenshots/#{collectionListBean.collectionListTeaser[0].screenshot}" alt="Screenshot #{collectionListBean.collectionListTeaser[0].title}"/> 
    <div class="item-title"> 
     <h:form id="teaser0"> 
      <h:commandLink value="#{collectionListBean.collectionListTeaser[0].title}" action="#{collectionBean.showCollection(collectionListBean.collectionListTeaser[0].id)}" />  
     </h:form> 
    </div> 
    <div class="item-description"> 
     <p> 
      <h:outputText value="#{collectionListBean.collectionListTeaser[0].persons.get(0).person.getFullName()}" /> 
     </p> 
    </div> 
</div> 

標題顯示正確,所以支持bean和列表可用且可訪問。 CollectionBean也可以訪問。該列表有一個固定的大小,並在javascript畫廊內使用,這就是爲什麼我沒有使用ui:repeat或h/p:dataTable元素的原因。

我還檢查BalusC'S List of common problems

的動作沒有被調用的後盾豆,我得到下面的JavaScript錯誤的瀏覽器控制檯上:

Uncaught TypeError: Cannot read property 'teaser0:_idcl' of undefined 

這裏是後盾的相關代碼豆(collectionBean):

@Named("collectionBean") 
@Scope("access") 
@ViewController(viewIds = {ViewIds.EDIT_COLLECTION, ViewIds.SHOW_COLLECTION,  ViewIds.EDIT_COLLECTION, ViewIds.METADATA_COLLECTION_ADMIN,  ViewIds.EDIT_COLLECTION_EXISTING, ViewIds.COLLECTION_LIST, ViewIds.HOME}) 
public class CollectionBean extends CollectionBeanBase { 

. 
. 
. 
public String showCollection(long id) { 
    //Check if user is admin, if yes, allow to edit metadata 
    Authentication auth=SecurityContextHolder.getContext().getAuthentication(); 
    this.collection = collectionService.findById(id); 
    if (!(auth instanceof AnonymousAuthenticationToken)){ 
     role=auth.getAuthorities().iterator().next().getAuthority(); 
     if(role.equalsIgnoreCase("ROLE_ADMIN")) { 
      this.collection.setEdit_flag(true); 
      return ViewIds.EDIT_COLLECTION; 
     }   
    } 

    return ViewIds.SHOW_COLLECTION; 
} 

有沒有人有一個想法是什麼問題可能是什麼?任何提示都非常感謝!提前謝謝你們!

回答

0

我重新排列了元素來包裝所有受jQuery畫廊影響的div,現在它的功能就像一個魅力一樣。

0

這是commandLink那麼你爲什麼要在方法中傳遞值。

意味着你可以使用

<f:param name="id" value="#{collectionListBean.collectionListTeaser[0].id}"/> 

你可以很容易地在行動中該值。

public String showCollection() { 

FacesContext fc = FacesContext.getCurrentInstance(); 

     Object id = fc.getExternalContext().getRequestParameterMap().get("id"); 

    System.out.println(id); 

    return ViewIds.SHOW_COLLECTION; 
    } 

我認爲這是做最好的方式。

+0

對不起,但爲什麼我會使用f:param標記,然後通過使用FacesContext來獲取它?使用JSF 2.0功能並使用EL傳遞參數更容易(也更清潔)。另外我不明白這是如何回答我的問題,因爲它不會改變任何東西......不過謝謝你的回答 – user871784

+0

好的。我明白。請將方法參數更改爲Long。 – KSHiTiJ

+0

它與我一樣像 and in public void myMethod (Long id) { System.out.println(「id is:」+ id); } – KSHiTiJ