1

On my page i have form with data from database. I want to implement, as default behaviour, writing all changes to db.
I found such example

<h:selectOneMenu value="#{bean.options}" onchange="submit()"
                        var="#{bean.options}" valueChangeListener="#{bean.changeListernMethod}">
                        <f:selectItem itemValue="1" itemLabel="option1" />
                        <f:selectItem itemValue="2" itemLabel="option2" />
                        <f:selectItem itemValue="3" itemLabel="option3" />
                    </h:selectOneMenu>

but it not call listener method and reload all page. I can't reload page on every inputText edit or menu selection change. Do you have idea how to achieve such behaviour? Update objects in bean without page reload.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Have you considered using AJAX? – Tim Biegeleisen Jul 14 '15 at 07:36
  • AJAX could be a good idea. But how to use it in JSP with Primefaces? –  Jul 14 '15 at 07:37
  • Did you just randomly downvote one of my answers? – Tim Biegeleisen Jul 14 '15 at 08:52
  • I don't know where is your answer now. Something is happend with your answer but i dont know what. –  Jul 14 '15 at 09:32
  • Hmmm, i don't see such 'downvote' action in my user panel. –  Jul 14 '15 at 09:33
  • Don't start changing questions. Create new ones instead and accept answers if they solved something – Kukeltje Jul 14 '15 at 10:28
  • This is still the same question. I want to update object in bean without reload page. I have problem that ajax solution is not working inside p:dataTable. I don't know if i can use ajax inside p:dataTable. Maybe this should be done in other way. –  Jul 14 '15 at 10:32
  • Related and maybe helpful in your problem (I still don't understand it, your comments are indicating a different problem than the question in its current form does): http://stackoverflow.com/questions/11879138/when-to-use-valuechangelistener-or-fajax-listener/ – BalusC Jul 14 '15 at 10:53
  • I created new question. http://stackoverflow.com/questions/31404987/pajax-dont-work-for-pselectonemenu-inside-pdatatable –  Jul 14 '15 at 11:13

1 Answers1

2
<f:ajax listener="#{bean.changeListernMethod}" render="@form" event="valueChange"/>

This is how you implement partial submit, or in your words: update objects in bean without page reload. The line I typed will fire ajax and update (only) the form whenever a value is selected and is different from the previous selected.

For more info:

https://docs.oracle.com/javaee/6/javaserverfaces/2.1/docs/vdldocs/facelets/f/ajax.html

onderbewustzijn
  • 935
  • 7
  • 32
  • So it working for selectOneMenu not in tag. I added sources to my post. For selectOneMenu in listener is not called. –  Jul 14 '15 at 09:59
  • If using with prime faces use – onderbewustzijn Jul 14 '15 at 10:37
  • Something is wrong here. My editions and new comments are deleted. I'm using p:ajax now but listener not working inside p:dataTable –  Jul 14 '15 at 10:47
  • You should really put some more information about your source code... :) Paste the whole page if you can. I offered two solutions, if it doesn't work more code is needed... – onderbewustzijn Jul 14 '15 at 10:55