1

I have a problem with selection primefaces datatable. When I choose any record my setter doesn't invoke. I found couple solution like change template or change to ViewSCope I'm changing everything but still does't work template.xhtml

<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:c="http://java.sun.com/jsf/composite/custom"
xmlns:p="http://primefaces.org/ui"
xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title><ui:insert name="title">Default title</ui:insert></title>
<f:facet name="first">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>Social Test</title>
</f:facet>
<f:facet name="middle">
    <h:outputStylesheet name="bootstrap/css/bootstrap.css" />
    <h:outputStylesheet name="css/style.css" />
    <h:outputStylesheet name="bootstrap/css/bootstrap-social.css" />
    <script
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" />
    <h:outputScript name="bootstrap/js/bootstrap.js" />
    <!-- h:outputScript name="js/script.js" /-->
</f:facet>
<f:facet name="last">
</f:facet>
</h:head>
<h:body>
    <div id="header"></div>
    <div id="menu"></div>
    <div id="content">
        <ui:insert name="content"></ui:insert>
    </div>
    <div id="footer"></div>
</h:body>
</html>

ticketEdit.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <ui:composition template="/template/template.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jsf/composite/custom"
xmlns:p="http://primefaces.org/ui">
<ui:define name="content">
            <h2 class="form-signin-heading">#{labRes.add_ticket}</h2>
            <h:form id="form">
                <p:accordionPanel>
                    <p:tab title="#{labRes.train_details}">
                        <h:panelGrid columns="2" cellpadding="10">
                            <c:autoComplete
                                completeMethod="#{ticketBean.trainAutoCompleteBean.complete}"
                                minQueryLength="2"
                                converter="#{ticketBean.trainAutoCompleteBean.converter}"
                                nameLable="#{labRes.train_number}"
                                autoValue="#{ticketBean.selectedTrain}" forceSelection="true"
                                queryDelay="500" effect="fade" cid="ticketAuto" listener="null"
                                labelStyleClass="labelPaddingParameter" ajax="true"
                                update="@form" />
                            <c:inputText id="nr" cid="cnr"
                                nameLable="#{labRes.train_number}" disabled="true"
                                inputValue="#{ticketBean.selectedTrain.name}"
                                labelStyleClass="labelPaddingParameter" />
                        </h:panelGrid>
                    </p:tab>
                    <p:tab title="#{labRes.train_details}">
                        <h:panelGrid columns="1" cellpadding="10" id="pgTrainDetails">
                            <c:calendar pattern="MM-dd-yyyy" value="#{ticketBean.day}"
                                isListener="true" update=":form" ajax="true"
                                nameLable="#{labRes.departure_date}" cid="depDat"
                                listener="#{ticketBean.onDateSelect}" />
                            <p:dataTable var="schedule" value="#{ticketBean.tripSchedules}"
                                selectionMode="single"
                                selection="#{ticketBean.selectedSchedule}"
                                rowKey="#{schedule.id}" styleClass="pickListWidth"
                                paginator="true" rows="10"
                                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                                rowsPerPageTemplate="5" id="scheduleTable">
                                <f:facet name="header">
                                    <c:calendar pattern="MM-dd-yyyy" value="#{ticketBean.day}"
                                        isListener="true" update=":form" ajax="true"
                                        nameLable="#{labRes.departure_date}" cid="depDat"
                                        listener="#{ticketBean.onDateSelect}" />
                                </f:facet>
                                <p:column headerText="#{menRes.id}" sortBy="#{schedule.id}"
                                    style=" text-align:center">
                                    <h:outputText value="#{schedule.id}" />
                                </p:column>
                                <p:column headerText="#{labRes.departure_time}"
                                    sortBy="#{schedule.departure}" style="text-align:center">
                                    <h:outputText value="#{schedule.departure}" />
                                </p:column>

                            </p:dataTable>
                        </h:panelGrid>
                    </p:tab>
                    <p:tab title="#{labRes.ticket_details}">
                        <h:panelGrid columns="2" cellpadding="10">
                        </h:panelGrid>
                    </p:tab>
                </p:accordionPanel>
            </h:form>
</ui:define>

My bean (I'm using Spring) but I have to use @ViewScope because spring does't contain @Scope('view')

 // the same annotations in AbstractBean

 @Component   
 @ViewScope  //faces  bean package
 public class TicketBean extends AbstractBean {


 ... code ...

 public TripSchedule getSelectedSchedule() {
return selectedSchedule;
}

public void setSelectedSchedule(TripSchedule selectedSchedule) {
this.selectedSchedule = selectedSchedule;
}

Thanks for help !

Community
  • 1
  • 1
luprogrammer
  • 155
  • 1
  • 3
  • 12
  • Are you sure @Component works with @Viewscoped? It might just be that it does not work and the default scope kicks in. There will be a different instance of the bean then and calls will not succeed. See http://stackoverflow.com/questions/2118656/commandlink-commandbutton-ajax-backing-bean-action-listener-method-not-invoked – Kukeltje Mar 31 '15 at 22:40
  • Also don't manually include jquery.js – Kukeltje Mar 31 '15 at 22:41
  • Yes `@component` works with `@ViewScope`. I remove my manully include .js and .css. I can remove these because I'm using `primefaces.THEME bootstrap` in my web.xml but selection still not working – luprogrammer Apr 01 '15 at 07:13

1 Answers1

2

I think you need to add some ajax to the datatable:

<p:ajax event="rowSelect"/>
<p:ajax event="rowUnselect"/>
Jaqen H'ghar
  • 4,305
  • 2
  • 14
  • 26