Yesterday I was trying to implement a Listener for a SelectManyListbox using Ajax in JSF 2.
Following code is from my memory, since I dont have it available right now 🙂
<h:head>
<title>Test</title>
</h:head>
<h:body>
<h:selectManyListbox value="#{myBean.myList}">
<f:ajax render="delete" listener="#{myBean.listener}" />
<h:selectManyListbox>
<h:commandbutton id="delete" disabled="#{myBean.disabled}" value="Delete" />
<h:body>
I tried a lot of different things because my listener was never called. In the end I just added a surrounding <h:form> tag and everything worked. Why is that?
My goal is a composite-control that just displays a list and enables/disables the delete-button when a item is selected/unselected. In my understanding a form is only needed when I want to submit multiple values at once.
Thanks
This is thus untrue. A
<h:form>is necessary when you want to send a POST request to the server by JSF by anUIInputcomponent such as<h:selectManyListbox>. This is regardless of whether the POST request is performed by a regular (synchronous) request or an ajaxical (asynchronous) request. This is regardless of the amount of inputs. You should not forget that thejavax.faces.ViewStatehidden input field and if necessary also the name=value of the command button itself also needs to be sent along as well, so there’s basically never means of a single input value in a JSF postback request.POST has the major advantage over GET that there’s no limit in the amount of data which can be sent. In GET this is dependent on the webbrowser used and ranges from 255 characters until 2~4KB in older browsers and 8~10KB in newer browsers. In POST the limit is usually around 2GB.