1
votes

I am working with Primefaces 3.5, Spring 3.2, JSF 2.2 and Apache is my server.

My problem is that whenever i click on the row, the row select event is never triggered in my backing bean and my store details panel is never updated.

My backing bean is in request scope and contains onRowSelect method. However when i change my backing bean to sessions scope(it requires a few changes in backing bean), instant row selection works.

For the simplicity of my question i have modified my code to include only relevant part. In my param, for the sake of testing i just put existing customer with ID 35 in my test page.

Here is my dialog.xhtml

    <h:form id="customerListingsForm">

    <p:dialog id="manageStoresDialog"
            header="Manage #{manageStoreBean.store.owner.name}'s Stores"
            widgetVar="manageStoresDlg"
            modal="true"
            resizable="false">


        <p:panelGrid id="storePanel" rendered="#{manageStoreBean.owner != null}">
            <f:facet name="header">
                <p:row>
                    <p:column>Store Details</p:column>
                    <p:column>Customer Store List</p:column>
                </p:row>
            </f:facet>

            <p:row>
                <p:column>
                    <p:panelGrid id="storeDetails">         
                        <p:row>
                            <p:column>Name: </p:column>
                            <p:column>
                                <h:inputText value="#{manageStoreBean.store.name}" />
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Description: </p:column>
                            <p:column>
                                <h:inputText value="#{manageStoreBean.store.description}" />
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Short Code: </p:column>
                            <p:column>
                                <h:inputText value="#{manageStoreBean.store.shortCode}" />
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Owner name:</p:column>
                            <p:column>
                                <h:inputText value="#{manageStoreBean.store.owner.name}" readonly="true" />
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Store Type: </p:column>
                            <p:column>
                                <p:selectOneMenu
                                        id="storeTypeSelected"
                                        value="#{manageStoreBean.placeType}"
                                        var="storeType"
                                        style="height:25px"
                                        converter="#{placeTypeConverter}">
                                    <f:selectItems 
                                            value="#{manageStoreBean.typeList}"
                                            var="storeTypeItem"
                                            itemLabel="#{storeTypeItem.code}"
                                            itemValue="#{storeTypeItem}"/>
                                    <p:column>#{storeType.description}</p:column>
                                </p:selectOneMenu>
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Country: </p:column>
                            <p:column>
                                <p:selectOneMenu
                                        id="storeCountrySelected"
                                        value="#{manageStoreBean.country}"
                                        var="country"
                                        style="height:25px"
                                        converter="#{countryConverter}">
                                    <f:selectItems 
                                            value="#{manageStoreBean.countryList}"
                                            var="countryItem"
                                            itemLabel="#{countryItem.isoNumericCode}"
                                            itemValue="#{countryItem}"/>
                                    <p:column>#{country.isoNumericCode}</p:column>
                                </p:selectOneMenu>
                            </p:column>
                        </p:row>

                        <p:row>
                            <p:column>Localisation: </p:column>
                            <p:column>
                                <p:selectOneMenu
                                        id="storeLocalisationSelected"
                                        value="#{manageStoreBean.localisationData}"
                                        var="storeLocal"
                                        style="height:25px"
                                        converter="#{localisationConverter}">
                                    <f:selectItems 
                                            value="#{manageStoreBean.localisationList}"
                                            var="local"
                                            itemLabel="#{local.regionCode}"
                                            itemValue="#{local}"/>
                                    <p:column>#{storeLocal.id} - #{storeLocal.regionCode}</p:column>
                                </p:selectOneMenu>
                            </p:column>
                        </p:row>
                    </p:panelGrid>
                </p:column>

                <p:column style="width:250px">
                    <p:dataTable id="stores" 
                            var="store" 
                            value="#{manageStoreBean.storeList}" 
                            rowKey="#{store.id}"
                            scrollHeight="240"
                            scrollable="true"
                            selectionMode="single"
                            selection="#{manageStoreBean.selectedStore}"
                            lazy="true">

                        <p:ajax event="rowSelect" immediate="true" 
                                listener="#{manageStoreBean.onRowSelect}"
                                update=":customerListingsForm:storeDetails"/>

                        <p:column headerText="Salon Name">
                            <h:outputText value="#{store.name}" />
                        </p:column>
                        <p:column headerText="ID">
                            <h:outputText value="#{store.id}" />
                        </p:column>
                    </p:dataTable>
                </p:column>
            </p:row>
        </p:panelGrid>

        <p:commandButton 
                value="Save"
                action="#{manageStoreBean.saveStore}"
                oncomplete="manageStoresDlg.hide()">
                <f:param name="storeCustomerId" value="#{manageStoreBean.owner.id}" />
        </p:commandButton>

        <h:outputText value="&nbsp;&nbsp;&nbsp;" />

        <p:commandButton 
                value="Close" 
                oncomplete="manageStoresDlg.hide()"/>
    </p:dialog>


    <p:commandButton value="Add Store" 
            oncomplete="manageStoresDlg.show()"
            update=":customerListingsForm:manageStoresDialog"
            process="@this">
        <f:param name="storeCustomerId" value="35" />
    </p:commandButton>


</h:form>

Also i'm new to primefaces and web dev, but did a lot of learning myself before i started this project. I spent 2 days try to understand what's wrong and searched all web but could not find any solution. May be i'm missing something or doing wrong not sure.

Any help is much appreciated.

2

2 Answers

1
votes

Try making your bean view scoped.

If you are making it request scoped, then you are telling JSF to throw out all of your existing data every time the user is done talking to your server. So it makes no sense to have JSF run a listener on an existing page. In particular, PrimeFaces has a tendency to malfunction when it encounters an odd set of scopes.

See also Difference between View and Request scope in managed beans

0
votes

By searching a lot of stuff on the internet i came to conclusion that datatable does not work very well with backing bean in request scope when table is loaded using dynamic argument. That is very shame. I do not see any other option but to implement viewscope in spring for my beans.