JSF 2.0 commandLink - 未调用操作,javascript erro



我正在尝试让一个普通的命令链接工作。以下是该页面的代码片段:

<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的常见问题列表

该操作未在支持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;
}

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

这是命令链接,那你为什么要在方法中传递值。

您可以使用的手段

<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;
    }

我认为这是最好的方法。

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

最新更新