JSF 2.0 commandLink - 没有调用动作,javascript错误

时间:2012-07-03 10:10:55

标签: jsf-2 tomcat7 commandlink

我正在努力让一个简单的commandLink工作。以下是该页面的代码段:

<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

在支持bean中没有调用该操作,我在浏览器控制台上出现以下javascript错误:

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

以下是支持bean(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;
}

有谁知道问题可能是什么?任何提示都非常感谢!提前谢谢你们!

2 个答案:

答案 0 :(得分: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;
    }

我认为这是最佳方式。

答案 1 :(得分:0)

我重新排列了元素以包装受jQuery库影响的所有div,现在它就像魅力一样。

相关问题