0

I apologize up front because I am sure this simple question has been asked but I have been unable to find it.

The way I have been doing partial submit in JSF is by ajaxifying the input fields of interest and providing getters and setters for each. So the user inputs something in field A and moves to field B, an ajax message is sent to update the backing bean for field A, and this repeats until the user clicks Submit. The form fields are "bound" to the corresponding backing bean fields. The Submit commandButton uses "process=" to limit submitted data to the fields of interest and the actionListener now processes the already-updated fields in the backing bean.

In some cases, this approach is fine because I want to know (in the backing bean) what the user entered BEFORE submit, perhaps for immediate validation in the backing bean. In other cases I don't care until AFTER submit, and this seems a lot of unnecessary traffic and code. I'd like to omit all those getters and setter and ajax on the input fields, and just use the ajax commandButton, processing only the fields I select with "process=". My problem is I don't know how to collect the submitted form data in the actionListener method like in a traditional form submit where I get the form field values directly from the request object. Is this possible? I'm using Primefaces.

snakedog
  • 357
  • 1
  • 2
  • 13
  • Are you saying that your action method is located on a different backing bean class than where properties are located? If not, why not just accessing those properties directly? – BalusC Jan 19 '18 at 18:11
  • No, I have only one backing bean. I am trying to avoid having a separate class-level property in the backing bean for every form field in the view. Before ajax we just collected the submitted fields from the request and processed them in one method, no need for mutators for every field. I'm wondering if I can do the same thing with partial submit, without having to bother to "bind" the fields to dedicated getters/setters. – snakedog Jan 19 '18 at 18:35
  • I think I have confused this. It occurs to me that it is not necessary to ajaxify the input fields of interest. Their values will be sent at submit time. I guess I'm just looking for a graceful way to collect their values from the request without bloating my code by providing mutators for them. This probably defeats the purpose of JSF. – snakedog Jan 19 '18 at 18:39
  • Just put them in an entity? You're gonna need it anyway for JPA and what not which consumes beans. – BalusC Jan 19 '18 at 18:41
  • Researching JPA Entities... Thanks! – snakedog Jan 19 '18 at 18:52
  • OMG why did nobody tell me about JPA before now?? Spring has huge support. Thanks so much. – snakedog Jan 19 '18 at 19:16
  • Even better, you can do all this **without** spring... – Kukeltje Jan 20 '18 at 13:58
  • Okay now you have my curiosity. Can you please point me to something that explains why life is better without Spring? Thank you! – snakedog Jan 20 '18 at 17:01

0 Answers0