使用jsf中的panelGroup和commandButton传递给辅助bean的空值

时间:2014-08-13 08:46:45

标签: jsf-2

在关注XHTML文件中,我想使用托管bean在createPdfFile方法中传递invoiceNumber。

<h:body>
<h:form id="form">
    <br />
    <h3 align="center">Tax Invoice</h3>
    <p:selectOneMenu id="selectOne" value="#{invoiceBean.selectOneOption}"
        required="true">
        <f:selectItem itemValue="Add New Invoice" itemLabel="Add New Invoice" />
        <f:selectItem itemValue="Old Invoice" itemLabel="Old Invoice" />
        <f:ajax render="groups" />
    </p:selectOneMenu>

    <h:panelGroup id="groups">
        <h:panelGroup id="inputs"
            <p> Panel Group Inputs </p>
        </h:panelGroup>

        <h:panelGroup id="outputs"
            rendered="#{invoiceBean.selectOneOption == 'Old Invoice'}">
            <p:panelGrid columns="3">
                <p:outputLabel value="Enter Invoice Number :" />
                <p:inputText id="inputInvoiceNumber"
                    value="#{invoiceBean.invoiceNumber}" />
                <p:commandButton value="Search" type="submit">
                    <f:ajax execute="inputInvoiceNumber" render="outputInvoiceNumber" />
                </p:commandButton>
            </p:panelGrid>
            <br />
            <p:dataTable id="outputInvoiceNumber"
                value="#{invoiceBean.invoices}" var="invoice">
                <p:column headerText="Invoice Id ">
                    <p:outputLabel value="#{invoice.id}" />
                </p:column>
                <p:column headerText="Invoice Number ">
                    <p:outputLabel value="#{invoice.invoiceNumber}" />
                </p:column>
                <p:column headerText="Buyer Name ">
                    <p:outputLabel value="#{invoice.buyerName}" />
                </p:column>
            </p:dataTable>
        </h:panelGroup>
    </h:panelGroup>
    <br />
    <br />
    <p:dataTable id="invoiceTable" var="invoiceProductsServicesDetail"
        value="#{invoiceBean.invoiceProductsServicesDetails}" border="1"
        editable="true">
        <p:column headerText="Sr. No.">
            <p:outputLabel value="#{invoiceProductsServicesDetail.serialNumber}" />
        </p:column>
    </p:dataTable>
    <br />
    <p:commandButton value="Create Pdf"
        action="#{createPdf.createPdfFile}" ajax="false" />
</h:form>
</h:body>

托管bean方法:createPdf

public void createPdfFile() {

    System.out.println("CreatePdf.createPdfFile");

    invoiceDao = new InvoiceDao();
    transactionDao = new TransactionDao();

    invoicesList = new ArrayList<Invoice>();
    invoiceProductsServicesDetails = new ArrayList<InvoiceProductsServicesDetail>();
    transactionList = new ArrayList<Transaction>();

    invoicesList = invoiceDao.getInvoiceData(invoiceNumber);
    int n = invoicesList.size() - 1;
    invoiceProductsServicesDetails = invoiceDao
            .getInvoiceProductsServicesDetailData();
    transactionList = transactionDao.getTransactions(invoicesList.get(n).getId());  
}

这里,我在invoiceNumber中获得NULL值。 我想要来自XHTML文件inputText标签的invoiceNumber。

1 个答案:

答案 0 :(得分:0)

你可以像这样设置:

<p:commandButton value="Create Pdf" action="#{createPdf.createPdfFile}" ajax="false">
    <f:setPropertyActionListener value="#{invoiceBean.invoiceNumber}" target="#{createPdf.invoiceNumber}"/>
</p:commandButton>