p:commandButton在使用p:selectOneMenu时不调用ActionListener

时间:2014-07-11 13:38:26

标签: jsf-2 primefaces

当我使用p:commandbutton和p:selectOneMenu时,我的actionListener被调用,ManagedBean运行良好。

当我把p:selectOneMenu我的actionListernet没有调用ManagedBean中的函数时。

可能是什么?这是我的代码!

<h:form id="formCadastrar">
            <p:dialog header="Cadastrar" widgetVar="dialogCadastrar" modal="true" >
                    <p:panelGrid id="panelCadastrar" columns="6">
                            <h:outputText value="Nome:" />
                            <p:inputText id="nome" value="#{exameBean.exame.nome}"  required="true">
                              <f:validateLength minimum="8" />
                              <p:ajax update="msgNome" event="keyup" />
                            </p:inputText>
                            <p:message for="nome" id="msgNome" display="icon" />

                            <h:outputText value="Valor" />
                            <p:inputText value="#{exameBean.exame.valor}" />

                             <h:outputLabel value="Pessoa" />
                             <p:selectOneMenu id="console" value="#{exameBean.exame.pessoa}" >

                             <f:selectItems value="#{pessoaBean.pessoas}" var="p" itemLabel="#{p.nome}" itemValue="#{p.id}" />

                            </p:selectOneMenu> 

                    </p:panelGrid>

                  <p:commandButton value="Cadastrar"
                            actionListener="#{exameBean.cadastrar}"
                            update=":formPrincipal:tabelaExames"
                            oncomplete="PF('dialogCadastrar').hide()"  />



            </p:dialog>
    </h:form>

我的ExameBean

@ManagedBean(name="exameBean")
@RequestScoped
public class ExameBean implements Serializable {


private static final long serialVersionUID = 1L;

private Exame exame = new Exame();
private List<Pessoa> pessoa;

public List<Pessoa> getPessoa() {
    System.out.println("get");
    return pessoa;
}

public void setPessoa(List<Pessoa> pessoa) {
    System.out.println("set");
    this.pessoa = pessoa;
}

//construtor
public ExameBean(){

}

//Métodos dos botões 
public void cadastrar(ActionEvent actionEvent){
    System.out.println("cadastrar");
            new ExameDao().inserir(exame);
}

public void alterar(ActionEvent actionEvent){
    new ExameDao().alterar(exame);

}
public void excluir(ActionEvent actionEvent){
    new ExameDao().excluir(exame);

}

public List<Exame> getListar(){
    List<Exame> exames = new ArrayList<Exame>(); 
    exames = new ExameDao().listar();
    return exames;

}

//getters and setters
public Exame getExame() {
    return exame;
}

public void setExame(Exame exame) {
    this.exame = exame;
}

}

转换器:

@ManagedBean(name="pessoaConverter")
public class PessoaConverter implements Converter {

@EJB
private PessoaDao pessoaDao;

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
    return pessoaDao.buscaPorId((Long.valueOf(value)));
}

@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
    return ((Pessoa) value).getId().toString();
}
}

0 个答案:

没有答案