0

My xhtml page:

<h:form id="myform">
    <p:panel header="Requests">
        <p:tabView dynamic="true" cache="true">
            <p:tab title="New requests">
                <h:panelGrid columns="1" cellpadding="10">
                    <p:dataTable id="newReq" value="#{requestsBean.newRequests}" var="newReq" selectionMode="single" selection="#{requestsBean.selectedRequest}" rowKey="#{newRequest.id}" scrollRows="20" scrollable="true" liveScroll="false" scrollHeight="400" style="margin-bottom:0">
                        <p:ajax event="rowSelect" listener="#{requestsBean.onRowSelect}" update=":requestForm:requestDetail" oncomplete="PF('requestDialog').show()"/>
...Columns...
                    </p:dataTable>
                </h:panelGrid>
            </p:tab>
            ...One More Tab...
        </p:tabView>
    </p:panel>
</h:form>
<h:form id="requestForm">
    <p:dialog header="Details" widgetVar="requestDialog" modal="true" showEffect="fade" hideEffect="fade" resizable="false">
        <p:outputPanel id="requestDetail" style="text-align:center;">
            <h:panelGrid columns="2" cellpadding="5">
                <h:outputText value="Req #:"/>
                <h:outputText value="#{requestsBean.selectedRequest.reqNo}"/>
                <h:outputText value="Submitted By:" />
                <h:outputText value="#{requestsBean.selectedRequest.user}"/>
                <h:outputText style="font-weight:bold;" value="Submitted On:"/>
                <h:outputText value="#{requestsBean.selectedRequest.date}"/>
            </h:panelGrid>
        </p:outputPanel>
    </p:dialog>
</h:form>

My ManagedBean:

import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.event.ActionEvent;
import javax.faces.view.ViewScoped;
import org.primefaces.event.SelectEvent;
import com.company.model.Requests;
import com.company.service.RequestsService;

@ViewScoped
public class RequestsBean implements Serializable {
    @ManagedProperty(value = "#{requestsService}")
    private RequestsService requestsService;
    private Requests selectedRequest;
    private List<Requests> newRequests;
    public List<Requests> getNewRequests() {
        if (newRequests == null) {
            newRequests = requestsService.getNewRequests();
        }
        return newRequests;
    }
    public void onRowSelect(SelectEvent event) {
    }
    ...getters...setters...
}

My Model Class:

@Entity
@Table(name = "REQUESTS")
public class Requests implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "request_gen")
    @SequenceGenerator(name = "request_gen", sequenceName = "REQUESTS_SEQUENCE")
    @Column(name = "REQ_NO")
    private Long reqNo;
    @Column(name = "DATE", nullable = false)
    private Date date;
    @Column(name = "USER", nullable = false)
    private Long user;
...getters setters...
}

The list query fetches the Requests with all details (model attributes). When I select a row in the datatable the dialog opens with the desired result but the list query is fired again (method getNewRequests() is called again with newRequests = null). I want to prevent the query to fire again since all the data is already fetched with the RequestList.

Can anyone help here please?

GSS
  • 3
  • 1
  • 5
  • tried removing the tabview? and what method is fired again? Please create an [mcve] and you miss a form close tag somewhere. Please post **real** code in mcve format, not some copy/paste/edited trial/failure – Kukeltje Jan 15 '16 at 10:04
  • The form tag ends right before and when the p:ajax call is made, getNewRequests() method is called again with newRequests = null – GSS Jan 15 '16 at 16:27
  • wrong viewscoped? Show imports... And a model class is not needed. Inline plain string ArrayLists work perfectly in an [mcve] – Kukeltje Jan 15 '16 at 16:39
  • Next time please create an [mcve] upfront. You'll get quicker answers then and it saves us time (and sorry I missed the suggestion about the wrong scope import initially) – Kukeltje Jan 15 '16 at 16:46
  • Sorry .. I am still a beginner here. Thanks for your suggestions. I will try to take care of these next time. – GSS Jan 15 '16 at 17:04
  • trying scope changes if some things do not work is also a good thing to try (not as a solution, but to try). But does it work now? – Kukeltje Jan 15 '16 at 17:05
  • And if you are new, may I suggest to go for CDI instead of JSF managed beans? They are more future proof!!! – Kukeltje Jan 15 '16 at 17:06
  • That did solve my problem! Yay! But .. now i face another problem because of this. After changing the import to javax.faces.bean.ViewScoped, the stopped working. The page is still caching the datalists. I don't want to cache them, I want to fetch them from DB whenever the user clicks the tab. Any ideas? – GSS Jan 15 '16 at 17:13
  • And I will definitely check your suggestion to go for CDI. So, I have integrated JSF 2.2 with Spring 4.x and Hibernate 4.x. Do you see any problems in moving to CDI? – GSS Jan 15 '16 at 17:15
  • Will respond later tonight, what is your timezone? Most likely the tabs are still not cached, but the content of the datalist is. Look at the http traffic when switching tabs – Kukeltje Jan 15 '16 at 17:40
  • I am in MST timezone. Thanks a lot for your help! – GSS Jan 15 '16 at 17:53

0 Answers0