4

I am having trouble getting my actionListener in a <p:commandButton> to fire inside of a dialog. I've tried changing it to action, removing the (), adding the (), changing the scope of the managed bean, moving around the ajax statements and nothing has helped so far. Everything worked until I updated Netbeans, everything broke, somehow a library was removed, it was the commons-fileupload jar.

This happened with no changes to the code, only after netbeans updated. Netbeans 7.3, JSF2.2, Tomcat 7, jdk1.7, primefaces 4.0. There is a working version of this inside of my tomcat manager application, if I could possibly retrieve that hopefully everything would be back in working order but I can't find anything about getting the files back from tomcat. So my question is, why is this not firing? Is it the order of my calls in the button? I can't wrap my head around why this is not working.

EDIT Error I recieve after switching form and dialog positions -

    Jul 10, 2014 11:50:48 AM     com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
    SEVERE: Error Rendering View[/sampleExport.xhtml]
    javax.faces.FacesException: Cannot find component with expression ":searchDialogID" referenced from "mainForm:j_idt22".
    at   org.primefaces.expression.SearchExpressionFacade.resolveComponentInternal(SearchExpressionFacade.java:271)

EDIT 3 Revised Bean

@ManagedBean
@ViewScoped
public class SampleExportController implements Serializable {


//Variables used to show or hide panels on the webpage
private boolean _addTill = false;
private boolean _allowAddingExport;
private boolean _allowDelExport;
private boolean _allowModExport;
private boolean _allowReading;
private boolean _previousCrop;
private boolean _spreadSelected;
//Variables Used For Whole Form
private ArrayList<Account> _agronomers;

private StreamedContent _file;
private ArrayList<String> _growers;
private SampleSearch _search;
private LabSampleHelper _labHelper;
private ArrayList<AdminLabNumber> _labNumbers;
private NutrientsGuide _nutriGuide;
private SampleAdminHelper _saHelper;
private List<String> _sampleTypes;
private SampleAlter _selectedSample;
private AdminLabNumber _selectedLab;
private QueryHelper _qHelper;
private List<String> _years;

public SampleExportController() {
    AllowedRights awdRight = AllowedRights.getAllowedRights();
    Access rights = awdRight.getAccessRigths("exportSample");
    if (rights != null) {
        _allowAddingExport = rights.getOperationAdd();
        _allowDelExport = rights.getOperationDel();
        _allowModExport = rights.getOperationMod();
        _allowReading = rights.getReadAccess();
    } else {
        _allowAddingExport = false;
        _allowDelExport = false;
        _allowModExport = false;
        _allowReading = false;
    }
    _search = new SampleSearch();
    _saHelper = new SampleAdminHelper();
    _qHelper = new QueryHelper();
    _years = _saHelper.getYears();
    if (_years != null && !_years.isEmpty()) {
        _search.setYear(_years.get(0));
    }
    _sampleTypes = _saHelper.getSampleTypes();
    _labHelper = new LabSampleHelper();
}




public void initSearch() {
    AccountHelper acHelper = new AccountHelper();
    _agronomers = acHelper.getAllAgronomers();
    SampleAdminHelper saHelper = new SampleAdminHelper();
    _growers = saHelper.getAllGrowers();
}

public void loadSearch() {
    UIComponent table = FacesContext.getCurrentInstance().getViewRoot().findComponent(":mainForm:DTsamples");
    table.setValueExpression("sortBy", null);
    _search.setStage("Completed");
    _labNumbers = _saHelper.exportSampleSearch(_search);
    ExportFormatHelper efHelper = new ExportFormatHelper();
    for (int i = 0; i < _labNumbers.size(); i++) {
        _labNumbers.get(i).addExportSettings(efHelper.getFormats(_labNumbers.get(i).getAccountNumber(), _labNumbers.get(i).getSampleType()));
    }
    //loadExportSettings from account
    _agronomers.clear();
    _growers.clear();
}



/**
 * @return the _search
 */
public SampleSearch getSearch() {
    return _search;
}

/**
 * @return the _labNumbers
 */
public ArrayList<AdminLabNumber> getLabNumbers() {
    return _labNumbers;
}

/**
 * @return the _agronomers
 */
public ArrayList<Account> getAgronomers() {
    return _agronomers;
}

/**
 * @return the _growers
 */
public ArrayList<String> getGrowers() {
    return _growers;
}

/**
 * @return the _selectedSample
 */
public SampleAlter getSelectedSample() {
    return _selectedSample;
}

/**
 * @param selectedSample the _selectedSample to set
 */
public void setSelectedSample(SampleAlter selectedSample) {
    this._selectedSample = selectedSample;
    //This gets the value of the initial till level from the sample
    _initialTill = _selectedSample.getTilled();
    _initialPreviousCrop = _selectedSample.getPreviousCrop();
    if (selectedSample.getSampleType().equalsIgnoreCase("Soil")) {

        if (_crop1 == null | _crop2 == null || _crop3 == null) {
            _crop1 = new CropGuide(_qHelper, _selectedSample);
            _crop2 = new CropGuide(_qHelper, _selectedSample);

            _crop3 = new CropGuide(_qHelper, _selectedSample);
        }
        _nutriGuide = new NutrientsGuide(_crop1.getRec(),_selectedSample);
        boolean flag1, flag2, flag3;
        flag1 = _crop1.refresh();
        flag2 = _crop2.refresh();
        flag3 = _crop3.refresh();
        if (flag1 || flag2 || flag3) {
            RequestContext.getCurrentInstance().update("nutrientguides");
        }
    }
}

/**
 * @return the _file
 */
public StreamedContent getFile() {
    return _file;
}


/**
 * @return the _selectedLab
 */
public AdminLabNumber getSelectedLab() {
    return _selectedLab;
}

/**
 * @param selectedLab the _selectedLab to set
 */
public void setSelectedLab(AdminLabNumber selectedLab) {
    this._selectedLab = selectedLab;
}


/**
 * @return the _years
 */
public List<String> getYears() {
    return _years;
}

/**
 * @return the _sampleTypes
 */
public List<String> getSampleTypes() {
    return _sampleTypes;
}


public void setPreviousCrop(boolean _previousCrop) {
    this._previousCrop = _previousCrop;
}

}

xhtml mostly full

<!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:ui="http://java.sun.com/jsf/facelets"
  xmlns:p="http://primefaces.org/ui">
<h:body>
    <ui:composition template="template/desktop_viewer.xhtml">
        <ui:define name="PageName">
            <title>Sample Export</title> 
        </ui:define>

        <ui:define name="PageHeader">
            Sample Export
        </ui:define>

        <ui:define name="PageLocation">
            Viewer
        </ui:define>  

        <ui:define name="Body" >
            <script type="text/javascript">
                function start() {
                    statusDialog.show();
                }

                function stop() {
                    statusDialog.hide();
                }
            </script> 
            <h:form id="mainForm" rendered="#{sampleExportController.allowReading eq true}">
                <p:dialog modal="true" widgetVar="statusDialog" header="Status" resizable="false" draggable="false" closable="false" appendToBody="true">
                    <p:graphicImage value="./resources/images/ajaxloading.gif" />
                </p:dialog>

                <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">
                    <f:facet name="start">
                        <h:graphicImage value="./resources/images/ajaxloading.gif" />
                    </f:facet>
                    <f:facet name="complete">
                        <h:outputText value="" />
                    </f:facet>
                </p:ajaxStatus>
                <p:growl id="growl" showDetail="true" autoUpdate="true"/>

                <p:commandButton oncomplete="searchDialog.show()" update=":innerSearch:searchDialogID" value="Search" icon="ui-icon-search" actionListener="#{sampleExportController.initSearch}"/>  
                <p:dataTable id="DTsamples" widgetVar="DTsamplesVw" var="labNumbers" value="#{sampleExportController.labNumbers}" 
                             paginator="true" rows="10" scrollable="true" rowStyleClass="#{labNumbers.rowColorByType}">
                    <p:column style="width:10px">
                        <p:rowToggler />
                    </p:column>
                    <p:column headerText="LabNumber" footerText="LabNumber">
                        #{labNumbers.number} 
                    </p:column>
                    <p:column headerText="Sample Type" footerText="Sample Type">
                        #{labNumbers.sampleType} 
                    </p:column>
                    <p:rowExpansion > 
                        <p:panelGrid style="width: 460px;">
                            <f:facet name="header">  
                                <p:row>
                                    <p:column colspan="1" style="width: 320px">
                                        Submitter
                                    </p:column>
                                    <p:column colspan="1" style="width:150px">
                                        Lab Number Report Export  
                                    </p:column>
                                    <p:column colspan="1" style="width: 280px">
                                        Lab Number CSV Export 
                                    </p:column>
                                </p:row>
                            </f:facet>  
                            <p:row>
                                <p:column>
                                    <h:panelGrid columns="1" styleClass="Ignore" >                                           
                                        <h:outputText value=" #{''.concat(labNumbers.getSamples().get(0).agronomer.accountNumber).concat(' - ').concat(labNumbers.getSamples().get(0).agronomer.lastName ).concat(' , ').concat(labNumbers.getSamples().get(0).agronomer.firstName)}"/>

                                        <h:outputText value=" #{'Email: '.concat(labNumbers.getSamples().get(0).agronomer.primaryEmail)}"/>
                                        <h:outputText value=" #{'Email 2: '.concat(labNumbers.getSamples().get(0).agronomer.email2)}"/>
                                        <h:outputText value=" #{'Email 3: '.concat(labNumbers.getSamples().get(0).agronomer.email3)}"/>
                                    </h:panelGrid>
                                </p:column>
                                <p:column style="text-align: center;">

                                    <h:panelGrid styleClass="Ignore">

                                        <p:commandLink ajax="false" id="AlternativeValues" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateAlternativeValueReport(labNumbers,false)}">
                                            <p:fileDownload value ="#{sampleExportController.file}" />
                                        </p:commandLink>

                                        <p:commandLink ajax="false" id="multiPdf" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateMultiSampleReportPDFLab(labNumbers,false)}">  
                                                 <p:fileDownload value="#{sampleExportController.file}" />  
                                            <p:graphicImage value="./resources/images/pdf.png" alt="Download the report by lab Number as a PDF." title="Normal Report"/>  
                                        </p:commandLink> 

                                        <p:commandLink ajax="false" id="multiPdfPage" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateMultiSampleReportPDFLab(labNumbers,true)}" rendered="#{labNumbers.sampleType eq 'Manure'}">  
                                            <p:fileDownload value="#{sampleExportController.file}" />  
                                            <p:graphicImage value="./resources/images/pdf_multi.jpg" alt="Download the report by lab Number as a PDF." title="Sample Per Page Report"/>  
                                        </p:commandLink> 
                                    </h:panelGrid>
                                </p:column>

                                <p:column>
                                    <p:outputLabel for="exportsetting" value="Export Setting:"/>

                                    <p:selectOneMenu id="exportsetting" value="#{labNumbers.selectedExport}" effect="fade" style="width:160px">
                                        <f:selectItem itemLabel="Select One" itemValue="" />
                                        <f:selectItems value="#{labNumbers.exportSettings}" var="export" itemLabel="#{export}" itemValue="#{export}" />
                                        <p:ajax update=":mainForm:DTsamples:downloadLink" event="change" listener="#{sampleExportController.setSelectedLab(labNumbers)}"/> 
                                    </p:selectOneMenu>

                                    <p:commandLink id="downloadLink" ajax="false" onclick="PrimeFaces.monitorDownload(start, stop)"   
                                                   disabled="#{empty labNumbers.selectedExport}" actionListener="#{sampleExportController.generateSpreadSheet()}">                                 
                                        <p:graphicImage value="./resources/images/csv.png" alt="Download the report by lab Number as a CSV."/>  
                                        <p:fileDownload value="#{sampleExportController.file}"/>
                                    </p:commandLink>
                                </p:column>
                            </p:row>
                        </p:panelGrid>

                        <p:dataTable id="nested" var="sampleheader" value="#{labNumbers.samples}" scrollable="true"
                                     rowStyleClass="#{sampleheader.rowColorByType}" scrollHeight="150">
                            <p:column headerText="Container ID">  
                                #{sampleheader.containerID}

                            </p:column>
                            <p:column headerText="Sample ID">  
                                #{sampleheader.sampleID}
                            </p:column>
                            <p:column headerText="Field ID">  
                                #{sampleheader.fieldID}
                            </p:column> 
                            <p:column headerText="Grower">  
                                #{sampleheader.grower}
                            </p:column>  
                            <p:column headerText="Sample Type">  
                                #{sampleheader.sampleType}
                            </p:column>
                            <p:column headerText="Notes">  
                                #{sampleheader.note}
                            </p:column>
                            <p:column headerText="View Sample" style="width:8%">                            
                                <p:commandButton update=":viewerID" oncomplete="viewerDialog.show()" process="@this" styleClass="compress" icon="ui-icon-newwin">  
                                    <f:setPropertyActionListener value="#{sampleheader}" target="#{sampleExportController.selectedSample}" />  
                                </p:commandButton>  
                            </p:column>
                        </p:dataTable>
                    </p:rowExpansion>                       
                </p:dataTable> 
            </h:form>            
            <h:outputText value="Nice Try" rendered="#{sampleExportController.allowReading eq false}"/>
            <h:form id="innerSearch"><p:dialog id="searchDialogID" widgetVar="searchDialog" header="Sample search" resizable="false" draggable="false" showEffect="puff"
                      hideEffect="puff" appendToBody="false" modal="true" rendered="#{sampleExportController.allowReading eq true}">

                    <h:panelGrid columns="4">
                        <h:outputText value="Starting Lab Number:"/>
                        <p:inputText value="#{sampleExportController.search.labnumberStart}" maxlength="20"/>
                        <h:outputText value="Ending Lab Number:"/>
                        <p:inputText value="#{sampleExportController.search.labnumberEnd}" maxlength="20"/>
                        <h:outputText value="Starting Container ID:"/>
                        <p:inputText value="#{sampleExportController.search.containerIDStart}" maxlength="11"/>
                        <h:outputText value="Ending Container ID:"/>
                        <p:inputText value="#{sampleExportController.search.containerIDEnd}" maxlength="11"/>
                        <h:outputText value="Season:"/>
                        <p:selectOneMenu  value="#{sampleExportController.search.year}"  
                                          panelStyle="width:150px" effect="fade" var="p" style="width:160px"  
                                          filter="true" filterMatchMode="contains">  
                            <f:selectItem itemLabel="Select One" itemValue="" />  
                            <f:selectItems value="#{sampleExportController.years}" var="year" itemLabel="#{year}" itemValue="#{year}"/>                              
                        </p:selectOneMenu>
                    </h:panelGrid>
                    <h:panelGrid columns="2">
                        <p:outputLabel for="acAg" value="Agronomist -- You may now search by any value"/>
                        <p:selectOneMenu id="acAg" value="#{sampleExportController.search.agronomist}" converter="agronomerSampleExportConverter" 
                                         panelStyle="width:170px" effect="fade" var="p" style="width:160px"  
                                         filter="true" filterMatchMode="contains" >  
                            <f:selectItem itemLabel="Select One" itemValue="" />  
                            <f:selectItems value="#{sampleExportController.agronomers}" var="agronomer" itemLabel="#{agronomer.lastName} #{agronomer.company} #{agronomer.firstName} #{agronomer.accountNumber}" itemValue="#{agronomer}"/>  
                            <p:column >
                                Base Ac. #: #{p.account.accountNumber}<br/>
                                Company Name: #{p.company}<br/>First Name:#{p.firstName}<br/><strong>Last Name:#{p.lastName}</strong>
                            </p:column>
                        </p:selectOneMenu> 

                        <h:outputText value="Sample Type:"/>
                        <p:selectOneMenu id="sampleType" value="#{sampleExportController.search.sampleType}" effect="fade" >
                            <f:selectItem itemLabel="Select One" itemValue="" />
                            <f:selectItems value="#{sampleExportController.sampleTypes}" var="stype" itemLabel="#{stype}" itemValue="#{stype}"/>
                        </p:selectOneMenu>

                        <p:outputLabel for="acGro" value="Grower"/>
                        <p:selectOneMenu id="acGro" value="#{sampleExportController.search.grower}"  
                                         panelStyle="width:150px" effect="fade" var="p" style="width:160px"  
                                         filter="true" filterMatchMode="contains" >  
                            <f:selectItem itemLabel="Select One" itemValue="" />  
                            <f:selectItems value="#{sampleExportController.growers}" var="grower" itemLabel="#{grower}" itemValue="#{grower}"/>

                        </p:selectOneMenu>

                    </h:panelGrid>
                    <p:commandButton update=":mainForm:DTsamplesVw" process="innerSearch" icon="ui-icon-search" value="Search" actionListener="#{sampleExportController.loadSearch}" oncomplete="searchDialog.hide()"/>

            </p:dialog>
            </h:form>
            <p:dialog id="viewerID" widgetVar="viewerDialog" modal="true" dynamic="true" hideEffect="puff" showEffect="puff"  appendToBody="false"
                      maximizable="true" header="Viewing selected samples" rendered="#{sampleExportController.allowReading eq true}">
                <h:form id="innerView">   
                    <h:panelGrid columns="2" width="100%">
                        <h:panelGrid>
                            <p:panelGrid >
                                <f:facet name="header">  
                                    <p:row>
                                        <p:column colspan="1" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">
                                            CSV Single Sample Report 
                                        </p:column>
                                        <p:column colspan="1" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">
                                            Single Sample Report Export  
                                        </p:column>
                                        <p:column colspan="1">
                                            Lab Number Report Export
                                        </p:column>
                                    </p:row>
                                </f:facet>  
                                <p:row>
                                    <p:column style="text-align: center;" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">
                                        <p:commandLink ajax="false" id="cOnecsv" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateSingleSampleReportCSV}" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">  
                                            <p:fileDownload value="#{sampleExportController.file}" />  
                                            <p:graphicImage value="./resources/images/csv.png" alt="Download the report by sample as a PDF."/>  
                                        </p:commandLink> 
                                        <p:tooltip for="cOnecsv" value="Download the report by sample as a CSV." showEffect="fade" hideEffect="fade" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}"/> 
                                    </p:column>
                                    <p:column style="text-align: center;" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">
                                        <p:commandLink ajax="false" id="cOnePdf" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateSingleSampleReportPDF}" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}">  
                                            <p:fileDownload value="#{sampleExportController.file}" />  
                                            <p:graphicImage value="./resources/images/pdf.png" alt="Download the report by sample as a PDF."/>  
                                        </p:commandLink> 
                                        <p:tooltip for="cOnePdf" value="Download the report by sample as a PDF." showEffect="fade" hideEffect="fade" rendered="#{sampleExportController.selectedSample.sampleType eq 'Soil'}"/> 
                                    </p:column>
                                    <p:column style="text-align: center;">
                                        <p:commandLink ajax="false" id="cMultiPdf" onclick="PrimeFaces.monitorDownload(start, stop)" actionListener="#{sampleExportController.generateMultiSampleReportPDF}">  
                                            <p:fileDownload value="#{sampleExportController.file}" />  
                                            <p:graphicImage value="./resources/images/pdf.png" alt="Download the report by lab Number as a PDF."/>  
                                        </p:commandLink> 
                                        <p:tooltip for="cOnePdf" value="Download the report by lab Number as a PDF." showEffect="fade" hideEffect="fade" /> 
                                    </p:column>
                                </p:row>
                            </p:panelGrid>

+ random ending tags
SkaiiNyght
  • 63
  • 1
  • 1
  • 8
  • AFAIK `` should wrap ``, not the other way around. Also, you can just keep the bean as `@ViewScoped`. Just to note: Netbeans update *is not the problem at all*. JSF and basically all Java code are IDE independent. – Luiggi Mendoza Jul 10 '14 at 16:27
  • @LuiggiMendoza I tried switching the dialog and form around and now I am getting an error for the page. – SkaiiNyght Jul 10 '14 at 16:30
  • @LuiggiMendoza The person that created this system has it so if there is an error at all it will go to a generic _There was an error page_ it doesn't give specifics it just says there was an unexpected error. – SkaiiNyght Jul 10 '14 at 16:40
  • Doesn't your IDE log the exception? If so, edit the post and add the stacktrace or exception message. – Luiggi Mendoza Jul 10 '14 at 16:46
  • For your *new* error: change here: `` to `` (do it in other places when you called the dialog as well). Make the change and test again. – Luiggi Mendoza Jul 10 '14 at 17:00
  • @LuiggiMendoza Ok that works, and now it brings up the records but they are empty, and when I try to re-search for everything the the initSearch function is not run so nothing is loaded into any of the select one menus – SkaiiNyght Jul 10 '14 at 17:09
  • Provide the relevant code for your managed bean to replicate your problem. – Luiggi Mendoza Jul 10 '14 at 17:11
  • @LuiggiMendoza I don't know if this helps but I can go into my bean code and type _labnumbers.get(0).getSamples() with no errors because it knows there is something there. But when I try to retype in the datatable #{sampleheader. and try to use intellisence there is nothing there - No suggestions. – SkaiiNyght Jul 10 '14 at 17:50
  • I never trust in intellisense or autocomplete from IDEs. Again: provide the relevant code from your managed bean to replicate the problem. – Luiggi Mendoza Jul 10 '14 at 17:52
  • @LuiggiMendoza I'm not sure if this is what you were wanting or not. Literally the only part of the bean that gets everything is in the loadSearch(). So I added in another class function that actually sends the information back. Like I said earlier when this is run _labNumbers has items in it. But the datatable will not display them. Side note the datatable in my second edit is inside of another datatable. – SkaiiNyght Jul 10 '14 at 18:38
  • The relevant code to replicate the problem would be: the Java class and its annotations, the necessary fields, getters and setters and any other method involved to copy, paste it into a new JSF project along with the Facelets code for the view, with the necessary elements to execute it and replicate the issue. If you have an external data source like a database, it can be mocked, so don't worry about providing such classes/data or instead provide guidance to mock/simulate such elements. – Luiggi Mendoza Jul 10 '14 at 19:06
  • @LuiggiMendoza I think this should be mimicable with the code now. Thank you so much for your help so far it means a lot! – SkaiiNyght Jul 10 '14 at 19:43
  • Inside your dialog is a `` Shouldn't it be `update=":mainForm:DTsamples"` (id not widgetVar)? – rion18 Jul 10 '14 at 21:53
  • @rion18 That works! I don't know why it worked before with the widgetvar name and not now, but this has solved it! Thank you both so much! – SkaiiNyght Jul 11 '14 at 13:06
  • @rion18 post an answer. – Luiggi Mendoza Jul 11 '14 at 15:22
  • Damn that's good spotted @rion18... – Jaqen H'ghar Jul 11 '14 at 15:50

1 Answers1

7

The problem resides in your dialog. There's p:commandButton that contains the following:

<p:commandButton update=":mainForm:DTsamplesVw" process="innerSearch" 
    icon="ui-icon-search" value="Search" 
    actionListener="#{sampleExportController.loadSearch}" 
    oncomplete="searchDialog.hide()"/>`

It should be update=":mainForm:DTsamples" since you need to reference the id and not the widgetVar. Have a nice day!

rion18
  • 1,211
  • 16
  • 22