문제

i'm trying to get a plain commandLink to work. Here is a code snippet of the page:

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

The title is displayed correctly, so the backing bean and the list is available and accessible. CollectionBean is also available and accessible. The list has a fixed size and is used inside a javascript gallery which is the reason why i didn't use ui:repeat or h/p:dataTable elements.

I have also checked BalusC'S List of common problems

The action is not being invoked in the backing bean, I get following javascript error on the browser console:

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

Here is the relevant code of the backing 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;
}

Does anyone have an idea what the problem might be? Any hint is highly appreciated! thank you guys in advance!

도움이 되었습니까?

해결책 2

I rearranged the element to wrap all of the div's affected by the jQuery gallery and now it works like a charm.

다른 팁

This is commandLink then why are you passing value in method.

Means you can use

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

you can easily get that value in action.

like

 public String showCollection() {

FacesContext fc = FacesContext.getCurrentInstance();

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

    System.out.println(id);

    return ViewIds.SHOW_COLLECTION;
    }

i think this is best way to do it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top