<p:commandLink não chama método

4 respostas
LeoCBS

Boa noite pessoal,

Tenho um

Segue xhtml e classe:

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>
        <div class="container">
          <h:form id="formTournament">
            <p:messages id="messages" /> 

                   <p:dataTable id="tableTournaments" paginator="true" lazy="true" rows="5"
                       value="#{tournamentBean.lazyModel}" var="tournament" paginatorPosition="bottom">
                       <p:column>
                           <!-- Editar -->
                        <p:commandLink id="signupt" actionListener="#{userBean.signUpTournament}"
                            update=":formTournament">
                            <h:graphicImage value="/web/images/icons/signup_tournament.png"/>
                            <f:setPropertyActionListener value="#{tournament}"   
                                        target="#{userBean.selectedTournament}" />
                        </p:commandLink>
                       </p:column>

                   </p:dataTable>
          </h:form>
          </div>
    </h:body>
</html>

Bean:

import java.io.IOException;

import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.view.ViewScoped;
import javax.persistence.PersistenceException;
import javax.servlet.http.HttpServletRequest;

import br.com.wt.business.SimpleAbstractBean;
import br.com.wt.business.exception.WTCustomException;
import br.com.wt.business.platform.PlatformManagerBeanLocal;
import br.com.wt.business.tournament.TournamentManagerBeanLocal;
import br.com.wt.dao.Tournament;
import br.com.wt.dao.User;
import br.com.wt.utils.MessageUtils;

@ManagedBean
@ViewScoped
public class UserBean extends SimpleAbstractBean {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @EJB
    private PlatformManagerBeanLocal platformController;

    @EJB
    private UserManagerBeanLocal userController;

    @EJB
    private TournamentManagerBeanLocal tournamentController;

    private User user;

    private int idPlatform;

    private Tournament selectedTournament;

    public UserBean() {
        this.user = new User();
        this.selectedTournament = new Tournament();
    }

    public void createUser(ActionEvent event) {
        try {
            this.userController.validateLogin(this.user.getDsLogin());
            this.userController.createUser(this.user, idPlatform);

            super.exibiMensagem(MessageUtils.getMessage(FacesContext
                    .getCurrentInstance().getViewRoot().getLocale(),
                    "user.create.success"));
        } catch (WTCustomException e) {
            super.exibiMensagemErro(e.getMessage(), e.getMessage(), e);
        } catch (Exception e) {
            if (e.getCause() instanceof PersistenceException) {
                super.exibiMensagemErro(MessageUtils.getMessage(FacesContext
                        .getCurrentInstance().getViewRoot().getLocale(),
                        "email.duplicated"), MessageUtils.getMessage(
                        FacesContext.getCurrentInstance().getViewRoot()
                                .getLocale(), "email.duplicated"), e);
            } else {
                super.exibiMensagemErro(MessageUtils.getMessage(FacesContext
                        .getCurrentInstance().getViewRoot().getLocale(),
                        "msg.erro.default"), MessageUtils.getMessage(
                        FacesContext.getCurrentInstance().getViewRoot()
                                .getLocale(), "msg.erro.default"), e);
            }
        }
    }

    public void redirectNewTournament(ActionEvent actionEvent) {
        FacesContext context = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) context
                .getExternalContext().getRequest();
        try {
            context.getExternalContext().redirect(
                    request.getContextPath() + "/tournament/newtournament.wt");
        } catch (IOException e) {
            super.exibiMensagemErro(
                    MessageUtils.getMessage(FacesContext.getCurrentInstance()
                            .getViewRoot().getLocale(), "msg.erro.default"), e);
        }
    }

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

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public int getIdPlatform() {
        return idPlatform;
    }

    public void setIdPlatform(int idPlatform) {
        this.idPlatform = idPlatform;
    }

    public Tournament getSelectedTournament() {
        return selectedTournament;
    }

    public void setSelectedTournament(Tournament selectedTournament) {
        this.selectedTournament = selectedTournament;
    }

}

Obrigado pela ajuda!

4 Respostas

drsmachado

Você conhece o ciclo de vida de uma requisição JSF? Sabe que ocorrem validações antes de um método do bean ser invocado e, caso haja algum erro, a requisição é abortada?
Se sabe, então tente verificar possíveis erros em fases anteriores à execução do método. Se não sabe, é hora de estudar, aprender e então verificar os possíveis erros.

drsmachado

Duplicado.

Polverini

uma dica tire o id do commandlink, outra coisa de uma olhada na resposta do ajax do servidor com o firebug.

G

Vendo por alto Leo, o método signUpTournament(ActionEvent actionEvent) nao pode receber um ActionEvent, remove o parametro e deixe assim: signUpTournament() e vê agora se ele é acionado.

Criado 29 de agosto de 2013
Ultima resposta 30 de ago. de 2013
Respostas 4
Participantes 4