Preciso selecionar um estabelecimento para poder mudar os menus do meu sistema, mas estou levando um laço na hora de pegar o valor do estabelecimento escolhido…
estou usando o primefaces 2.1 e JSF 2.0
segue abaixo os codigos
index.xhtml
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:include src="../includes/head.html"/>
<h:body>
<f:view contentType="text/html">
<!-- <ui:include src="../includes/cabecalho.html"/> -->
<div id="conteudo">
<h:form id="form">
<p:panel style=" width: 329px; margin: 0px auto; margin-top: 15%;">
<h:panelGrid columns="2">
<h:outputText value="Selecione :"/>
<h:selectOneMenu>
<f:selectItems value="#{estabelecimentoMB.estabelecimentos}" var="estabelecimento" itemLabel="#{estabelecimento.nome_razao}" itemValue="#{estabelecimento.codigo_estab}" />
</h:selectOneMenu>
</h:panelGrid>
<p:commandButton value="Selecionar" actionListener="#{estabelecimentoMB.escreveEstabelecimento}" immediate="true">
<f:setPropertyActionListener value="#{estabelecimento}" target="#{estabelecimentoMB.estabelecimentoSelecionado}" />
</p:commandButton>
</p:panel>
</h:form>
</div>
</f:view>
</h:body>
</html>
estabelecimento.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package mb;
import beans.Estabelecimento;
import dao.EstabelecimentoJpaController;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
/**
*
* @author F2PRO
*/
@ManagedBean
@RequestScoped
public class EstabelecimentoMB implements Serializable {
/** Creates a new instance of EstabelecimentoMB */
private List<Estabelecimento> estabelecimentos = new ArrayList<Estabelecimento>();
EstabelecimentoJpaController jpa = new EstabelecimentoJpaController();
SelectItem estabelecimentoSelecionado = new SelectItem();
public SelectItem getEstabelecimentoSelecionado() {
return estabelecimentoSelecionado;
}
public void setEstabelecimentoSelecionado(SelectItem estabelecimento) {
//this.estabelecimentoSelecionado = estabelecimento;
System.out.println("valor :" + estabelecimento.getLabel());
}
public List<Estabelecimento> getEstabelecimentos() {
return estabelecimentos;
}
public void setEstabelecimentos(List<Estabelecimento> estabelecimentos) {
this.estabelecimentos = estabelecimentos;
}
public EstabelecimentoJpaController getJpa() {
return jpa;
}
public void setJpa(EstabelecimentoJpaController jpa) {
this.jpa = jpa;
}
public EstabelecimentoMB() {
this.estabelecimentos = jpa.findEstabelecimentoEntities();
}
public void escreveEstabelecimento(ActionEvent actionEvent){
//System.out.println("selecionado: " + this.estabSelecionado.getCodigo_estab());
//System.out.println();
}
}
como faço para pegar o valor do meu select?
[]'s