0

I currently working on a project for my school andwant to use Ajax with a Listbox and a Datatable. I've tried a lot of things but they don't work. If I select an item in the Listbox nothing happens. Here is my .xhtml:

    <ui:define name="content">
    <f:view>
        <p:layout style="min-width:400px;min-height:300px;">
            <p:spacer width="400" height="10" />
            <p:layoutUnit position="west" minSize="400" header="List of Rooms">
                <h:form id="RoomForm">
                    <p:selectOneListbox id="list" value="#{roomBean.currentR.name}" onchange="submit()">
                        <f:selectItems value="#{roomBean.guideService.roomList}" var="r" itemLabel="#{r.name}"/>
                        <f:ajax render="PersonForm" execute="@this"/>
                    </p:selectOneListbox> 
                </h:form>  
            </p:layoutUnit>
            <p:layoutUnit position="center" visible="false"/>
            <p:layoutUnit position="east" minSize="700" header="List of Persons" rendered="#{roomBean.currentR.name}">
                <h:form id="PersonForm">
                    <h:dataTable var="pers" value="#{personBean.guideService.persList}">
                        <f:facet name="header">
                            <h:outputText value="List of Persons"/>
                        </f:facet>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="First Name"/>
                            </f:facet>
                            <h:outputText value="#{pers.firstName}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Last Name"/>
                            </f:facet>
                            <h:outputText value="#{pers.lastName}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Age"/>
                            </f:facet>
                            <h:outputText value="#{pers.age}"/>
                        </h:column>

                        <h:column>
                            <f:facet name="header">
                                <h:outputText value="Roomnumber"/>
                            </f:facet>
                            <h:outputText value="#{pers.roomNr}"/>
                        </h:column>

                        <h:column>
                            <h:commandLink value="edit" action="#{personBean.editPerson(pers)}"/>
                        </h:column>

                        <h:column>
                            <h:commandLink value="delete" action="#{personBean.delPerson(pers)}"/>
                        </h:column>
                    </h:dataTable>

                </h:form>
            </p:layoutUnit>

        </p:layout>
        <center>
            <p:commandButton value="New Room" action="createRoom"/>
            <p:commandButton value="New Person" action="createPers"/>
            <p:commandButton value="Delete Room" action="#{roomBean.delRoom(roomBean.currentR)}"/>
        </center>
    </f:view>
    </ui:define> 

Now my question: How can I add Ajax to render the Datatable if something is selected in the Listbox?

Thanks for help!

  • Hi, start by learning how to create a [mcve] and describe what the technical problems/errors are... Since you do seem to have ajax in there. (and 'not working' is not a technical problem/error, it is an end-user description) – Kukeltje Mar 01 '18 at 08:10
  • Remove `onchange="submit()"` and learn about `p:ajax` – Jasper de Vries Mar 01 '18 at 08:27
  • 'nothing happens' is just as bad as 'not working'. Lots of things you can investigate... Please do... and learn about debugging... https://stackoverflow.com/questions/2118656/commandbutton-commandlink-ajax-action-listener-method-not-invoked-or-input-value – Kukeltje Mar 01 '18 at 08:28

0 Answers0