1

I'm having what I can call a strange behavior.

I have a page with a panel with several drops downs for search purposes and a datatable in it to display the results. By default when the page is loaded the values get initialized by a PostContruct init().

I can perform my search without any problem including updating the datatable.

Now, the part where it gets hard for me is the following: I have a list of tickets with Open/Closed state. My search can be performed with either Open/Closed/ALL.

  • By default the datatable is loaded with only the open tickets and I can select them and redirect to another page using the selectedRow value.
  • When I choose to filter by Closed status and I click the button to search, the datatable gets updated I can select the rows but when I try to open any page I get a null pointer exception in the bean.
  • If I choose all, the datatable gets updated, I can select rows but I can only open the pages with the data that was showed in the first page load, so basically only the tickets that are in the open state. Those that are in Closed that I cannot open them

I'm using RequestScoped bean, I would like to have somehints what could be the problem for the selectRow not work with the new added data.

    <ui:define name="content">
        <h:form id="searchForm">
            <p:panelGrid id="searchPanel" style="width: 1000px" styleClass="ticketsPanel">
                <p:row>
                    <p:column>
                        <p:outputLabel for="lstStatus" value="Status"></p:outputLabel>
                    </p:column>
                    <p:column>
                        <p:selectOneMenu id="lstStatus" value="#{ticketController.searchStatus}">
                            <f:selectItem itemValue="Open" itemLabel="Open"></f:selectItem>
                            <f:selectItem itemValue="Closed" itemLabel="Closed"></f:selectItem>
                            <f:selectItem itemValue="ALL" itemLabel="ALL"></f:selectItem>
                        </p:selectOneMenu>
                    </p:column>
                    </p:row>
                <f:facet name="footer">
                    <p:row>
                        <p:column colspan="6" style="alignment-adjust: middle">
                            <p:commandButton value="Search" action="#{ticketController.search()}" update=":searchForm:lstTicketsTable"></p:commandButton>
                            <p:commandButton value="Create" action="/tickets/createticket.xhtml?faces-redirect=true"></p:commandButton>
                            <p:commandButton value="View" action="#{ticketController.doUpdateTicket()}"></p:commandButton>
                        </p:column>
                    </p:row>
                </f:facet>
            </p:panelGrid>

<p:dataTable id="lstTicketsTable" selectionMode="single" paginator="true"
                         paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {CurrentPageReport}  {RowsPerPageDropdown}"
                         rowsPerPageTemplate="10,15,50" rows="10" paginatorPosition="bottom"
                         value="#{ticketController.ticketList}" selection="#{ticketController.selectedTicket}" var="_tl" rowKey="#{_tl.number}">

                <p:column headerText="Ticket NR">
                    <p:outputLabel value="#{_tl.number}"></p:outputLabel>
                </p:column>
                <p:column headerText="Summary">
                    <p:outputLabel value="#{_tl.summary}"></p:outputLabel>
                </p:column>
                <p:column headerText="Contact From">
                    <p:outputLabel value="#{_tl.contactfrom}"></p:outputLabel>
                </p:column>
                <p:column headerText="Researcher">
                    <p:outputLabel value="#{_tl.researcher.email == null ? '' : _tl.researcher.email}"></p:outputLabel>
                </p:column>
                <p:column headerText="NSN SR">

                </p:column>
                <p:column headerText="SR / CR">

                </p:column>
                <p:column headerText="Release">
                    <p:outputLabel value="#{_tl.release}"></p:outputLabel>
                </p:column>
                <p:column headerText="Status">
                    <p:outputLabel value="#{_tl.status}"></p:outputLabel>
                </p:column>
                <p:column headerText="Age">
                    <p:outputLabel value="#{_tl.startdate}"></p:outputLabel>
                </p:column>
                <p:column headerText="Priority">
                    <p:outputLabel value="#{_tl.priority}"></p:outputLabel>
                </p:column>
            </p:dataTable>
        </h:form>
    </ui:define>

And the backing bean functions doUpdateTicket is the one being called in the View button and the Search the one that updates the list of the datatable.

public void doUpdateTicket() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    try {
        ec.redirect("/SupportSite/faces/tickets/updateticket.xhtml?tnr=" + this.selectedTicket.getNumber().toString());
    } catch (IOException ex) {
        Logger.getLogger(TicketController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

public void search() {
    FacesContext fc = FacesContext.getCurrentInstance();
    ExternalContext ec = fc.getExternalContext();
    if (this.searchTicketNR != null) {
        Ticket t = tjc.findTicket(Integer.parseInt(this.searchTicketNR));
        if (t != null) {
            try {
               //This works when search by ticket number only
                ec.redirect("/SupportSite/faces/tickets/updateticket.xhtml?tnr=" + t.getNumber().toString()); 
            } catch (IOException ex) {
                Logger.getLogger(TicketController.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    } else if (this.getSearchStatus() != "ALL") {
        setTicketList(tjc.findTicketByStatus(this.getSearchStatus()));
        this.init();
    } else {
        setTicketList(tjc.findTicketEntities());
        this.init();
    }
}
4

0 回答 0