0

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!

Community
  • 1
  • 1
user871784
  • 1,247
  • 4
  • 13
  • 32

2 Answers2

0

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.

MRX
  • 1,611
  • 8
  • 33
  • 55
  • sorry, but why would i use f:param tag and then get it by using FacesContext? It's much easier (and cleaner) imho to use JSF 2.0 features and pass the parameter using EL. Also i don't see how this is an answer to my question as it doesn't change anything...however thanks for your answer anyways – user871784 Jul 03 '12 at 11:16
  • Ok. i understand. Please change method argument long to Long. – MRX Jul 03 '12 at 11:36
  • it is working with me like and in bean public void myMethod(Long id) { System.out.println("id is :" +id); } – MRX Jul 03 '12 at 11:38
  • long datatype in java is lowercase afaik, so that should be fine. Also, the problem is not the method in the backing bean, it works just fine. the problem appears to arise on the page itself as the method is not even being called due to a javascript error (as posted above) – user871784 Jul 03 '12 at 11:48
  • This is same as your question. if it is working with me means something in your page like(other javascript) that do not let that commandLink to call. – MRX Jul 03 '12 at 11:53
0

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

user871784
  • 1,247
  • 4
  • 13
  • 32