Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从p:SelectOne菜单获取值_Java_Primefaces_Primefaces Extensions - Fatal编程技术网

Java 从p:SelectOne菜单获取值

Java 从p:SelectOne菜单获取值,java,primefaces,primefaces-extensions,Java,Primefaces,Primefaces Extensions,我对Primefaces 3.4.1有问题。我需要从p:SelectOne菜单中获取所选值。我已经耗尽了谷歌的能量,但没有任何帮助。这是我的XHTML、控制器和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

我对Primefaces 3.4.1有问题。我需要从p:SelectOne菜单中获取所选值。我已经耗尽了谷歌的能量,但没有任何帮助。这是我的XHTML、控制器和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>

Combo中的列表填充得很好,但当选择一个值时,该方法只返回一个零。我做错了什么?

检查
getClientes()
方法返回的
Cliente
实体的ID。看起来
Cliente
实体中的
id
(选择菜单中的
itemValue
)没有从数据库中返回,并且默认为零。

据我所知,您的组件周围没有任何表单,因此它不会被提交。即使使用
p:ajax
也需要一个表单将内容发送到服务器。解决这种情况的最佳方法是使用inspector检查AJAX请求中发送的内容。

我更熟悉Seam和Richfaces,但我认为它是
immediate=“true”
,因为在这种情况下它不会更新值(它跳过模型更新和验证)。我不确定,因为通常在命令按钮或ajax控件中放置immediate,但Primefaces可能就是这样工作的。。。我想去掉
immediate=“true”
,但没有任何改变。你能发布整个xhtml文件吗?还可以使用浏览器检查器控制台查看提交时服务器的设置。好的,我已经编辑并发布了整个xhtml代码。。。即使一切都很顺利。。只是p:SelectOneMenu…谢谢Hound Dog,但是返回的列表没问题。。客户端列表正常,并返回每个客户端的Id。问题出在xhtml中。我做错了什么,我想这是一件我无法意识到的小事……哦,太棒了!!!这就是问题所在!!!变成一种形式。。。这么简单。。。非常感谢。
   @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;
}
   @Entity
   public class Cliente implements Serializable {

    @Id
    @GeneratedValue
    private long id;
    private String nome;
    private String endereco;
    ...