1
votes

I am trying to put a commandLink in a column of a datatable, however clicking the link, the method is not called in backbean, screen refresh and nothing happens.

I know that there are several topic on the internet about my problem. I already tried all the solutions and donk worked. I've tried changing the scope of the bean, tried to switch to h:commandLink I cleaned my html and removed the template and nothing resolved. what am I doing wrong? follow my code:

i am use glasshfish 3 and primeface 3.5

xhtml:

<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
    <h:form id="formTournament">
        <p:messages id="messages" /> 

               <p:dataTable id="tableTournaments"
                   value="#{tournamentBean.lazyModel}" var="tournament">
                   <p:column>
                    <p:commandLink id="signupt" action="#{tournamentBean.signUpTournament}"
                        update=":formTournament">
                        <f:setPropertyActionListener value="#{tournament}"   
                                    target="#{tournamentBean.selectedTournament}" />
                    </p:commandLink>
                   </p:column>

               </p:dataTable>
      </h:form>

</h:body>
</html>

Bean

@ManagedBean
@ViewScoped
public class TournamentBean{

private Tournament selectedTournament;

public TournamentBean() {
   this.selectedTournament = new Tournament();
}



public void signUpTournament() {
    this.tournamentController.signUpTournament(this.selectedTournament);
}

//getters and setters

}

Thanks for help!

2
You should isolate the code that causes the problem instead of pasting the whole class. - Creative Magic
I thought showing the whole class would be better. i cleaned the post. thanks - LeoCBS
No... You should post the code in SSCCE flavor. Show the smallest possible but complete code snippet with which we (and you!) can reproduce the very problem when copy'n'paste'n'runned without non-obvious modifications in a completely blank playground environment. See also stackoverflow.com/tags/jsf/info For example.. Are that <div class="container"> and <h:graphicImage> absolutely necessary in order to reproduce your problem? And the lazy="true"? And paginator="true"? Etc..etc.. Just remove every single tag/attribute/line which doesn't play any significant role in the problem. - BalusC
I'm new here and apologize for the mess. I organized the post as you suggested. Thank you. Any tips to how fix my problem? - LeoCBS
This code is not copy'n'paste'n'runnable. SimpleAbstractBean and TournamentBean are missing. Can't you just merge them into one bean for SSCCE purposes? Also, a more technical description of "can not call the method" would be very helpful. Isn't the problem just that selectedTournament is null at the moment action is invoked? The code posted so far namely suggests that, but you seem to imply that the method is never hit. - BalusC

2 Answers

1
votes

thanks everyone for help,

i found the solution, my bean annotation was wrong. I was importing wrong class javax.faces.view.ViewScoped.

the correct class is javax.faces.bean.ViewScoped.

it was why no one action in datatable works. my doubt is, why the others buttons works out the datatables in my app?

anyway all works now.

0
votes

For each attribute of the manager bean, you must have respective get's and set's. Also you also should try use action method and don't actionListing method. ActionListener is used for execute actions before real action. (For more informations about it's you must read a JSF Life Cycle).

Seems also missing some other methods in your manager bean, for example, the get method of the lazyModel attribute.