I have a problem with Primefaces 3.4.1. I need to get the selected value from a p:selectOneMenu. I have drained Google, but nothing help me. Here is my XHTML, Controller and Bean.
XHTML:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Bem Vindo</title>
</h:head>
<h:body>
<h:outputStylesheet library="primefaces-dot-luv" name="theme.css" />
<p:layout fullPage="true">
<p:layoutUnit position="west" size="200" header="Menu principal" resizable="true" closable="false" collapsible="true" >
<h:form id="menuForm">
<h:panelGrid>
<h:panelGroup>
<p:commandButton value="Cadastrar Cliente" actionListener="#{indexController.pagCliente}" style="font-size: 15px"/>
<p:commandButton value="Cadastrar Produto" actionListener="#{indexController.pagProduto}" style="font-size: 15px"/>
</h:panelGroup>
</h:panelGrid>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="north" size="110" header="Selecionar Cliente" resizable="true" closable="false" collapsible="true" >
<p:selectOneMenu value="#{clienteController.idClient}" effect="fade" id="combo">
<f:selectItem itemLabel="Cliente" itemValue="" />
<f:selectItems value="#{clienteController.clientes}"
var="cli"
itemLabel="#{cli.nome}"
itemValue="#{cli.id}" />
<p:ajax listener="#{indexController.hideValida()}" update=":outPanel" />
</p:selectOneMenu>
</p:layoutUnit>
<p:layoutUnit position="center" header="Carrito" id="layoutCenter">
<p:outputPanel id="outPanel" autoUpdate="true">
<h:form id="form" rendered="#{indexController.hide}">
<p:dataTable id="tabelaVenda" var="vendas" value="#{clienteController.listarVendas}" style="font-size: 13px"
sortBy="#{clienteController.listaSale}" sortOrder="descending">
<p:column>
<f:facet name="header">
<h:outputText value="Produto"/>
</f:facet>
<h:outputText value="#{vendas.nomeProduto}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="R$ Unitario"/>
</f:facet>
<h:outputText value="#{vendas.valorUnitario}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Quantidade"/>
</f:facet>
<h:outputText value="#{vendas.quantidadeVenda}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Preço Total (R$)"/>
</f:facet>
<h:outputText value="#{vendas.valorTotal}"/>
</p:column>
<p:summaryRow>
<p:column colspan="3" style="text-align:right">
Total:
</p:column>
<p:column>
#{clienteController.total} R$
</p:column>
<p:column rendered="false"/>
</p:summaryRow>
<p:column>
<f:facet name="header">
<h:outputText value="Excluir"/>
</f:facet>
<h:commandLink action="#{clienteController.excluirProdutoVenda}" value="Cancelar Produto"/>
</p:column>
</p:dataTable>
<p:commandLink value="Agregar Produto" actionListener="#{clienteController.prepararAdicionar}"
style="font-size: 13px" update=":dialogForm:infosProduct" oncomplete="dialogSelectProd.show()"/>
<p:commandButton value="Finalizar Venda" actionListener="#{clienteController.adicionarVenda}"
style="font-size: 70%; float: right; vertical-align: bottom;" oncomplete="dialogPDFfactura.show()"/>
</h:form>
</p:outputPanel>
</p:layoutUnit>
</p:layout>
<p:dialog header="Selecionar Produto" widgetVar="dialogSelectProd" resizable="false" modal="true" showEffect="slide" width="500" >
<h:form id="dialogForm" style="font-size: 13px">
<h:panelGrid id="infosProduct" columns="2" style="margin-bottom:10px">
<p:dataTable id="tabela" var="produto" value="#{clienteController.listarProdutos}" style="font-size: 13px" rowKey="#{produto.nomeProduto}"
selection="#{clienteController.produto}" selectionMode="single">
<p:column>
<f:facet name="header">
<h:outputText value="Produto"/>
</f:facet>
<h:outputText value="#{produto.nomeProduto}" />
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Quantidade Disponível"/>
</f:facet>
<h:outputText value="#{produto.quantidade}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value="Valor Unitario"/>
</f:facet>
<h:outputText value="#{produto.valor}"/>
</p:column>
</p:dataTable>
<h:outputLabel for="quantidadeVenda" value="Quantidade do Pedido: " />
<h:inputText id="quantidadeVenda" value="#{clienteController.venda.quantidadeVenda}"/>
<p:commandButton update=":form:tabelaVenda" oncomplete="dialogSelectProd.hide();" actionListener="#{clienteController.adicionarVendaTemp}" value="Adicionar no Carrinho"/>
</h:panelGrid>
</h:form>
</p:dialog>
<p:dialog header="Fatura" widgetVar="dialogPDFfactura" modal="true" showEffect="slide" >
<p:lightBox styleClass="PDFbox">
<p:media value="/pdf/eduardo.pdf" width="100%">
Your browser can't display pdf, <h:outputLink value="/pdf/eduardo.pdf">click</h:outputLink> to download pdf instead.
</p:media>
</p:lightBox>
</p:dialog>
Controller:
@ManagedBean
@SessionScoped
public class ClienteController {
private Cliente cliente;
private List<Cliente> clientes;
...
private long idClient;
public long getIdClient() {
return idClient;
}
public void setIdClient(long idClient) {
this.idClient = idClient;
}
public List<Cliente> getClientes() {
clientes = ClienteDaoImp.lista();
return clientes;
}
public void setClientes(List<Cliente> clientes) {
this.clientes = clientes;
}
Cliente class:
@Entity
public class Cliente implements Serializable {
@Id
@GeneratedValue
private long id;
private String nome;
private String endereco;
...
The list in Combo is well populated, but when selecting a value, the method just return me a zero. What I'm doing wrong?
immediate="true"
, as it doesn't update the values in that case (it skips model update and validation). I'm not sure because usually you put immediate in the command button or the ajax control, but maybe Primefaces works that way. – MaQyimmediate="true"
but nothing changed. – Tadashi