简体   繁体   中英

<p:commandLink don't work in <p:dataTable

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!

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM