This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin for Android App Development and have Peter Sommerhoff on-line!
See this thread for details.
Win a copy of Kotlin for Android App Development this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Devaka Cooray
  • Jeanne Boyarsky
  • Bear Bibeault
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

How to Trigger Ajax To Load Nested Dropdowns After Loading A Form?  RSS feed

Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm using Primefaces.
I have a button to display an edit dialog form with a selectOneMenu that holds prefix number values in it and,
after selecting one of those prefix values, three selectCheckboxMenu are loaded with employees data. This is workinkg fine.

The Listener:

The methods to load the employees lists:

Native queries to retrieve database:

But when editing a register that already has prefix and employee values (saved earlier by some user),
the 3 selectCheckboxMenu are loaded showing (undesired) id's entity class name on its labels value
and empty dropdowns:

e.g.: in the figure above, when the edit form was loaded, it shows the values saved earlier by some user:
- the prefix 9882 (displayed as expected) and
- the three (empty) dropdowns for employees (displayed with the undesired class names in it).
If I select a different value than 9882, the dropdowns are (ajax) filled as expected and if I select 9882 again,
the employees are displayed as expected (without the class names):

I'm trying to resolve it activating the ajax as below, but I don't know how to call it from inside the function:

Does anyone knows how to trigger ajax to load nested dropdowns after loading a form?

Or if someone has any other solution to display the values in the labels (without the class name) and automattically load the nested dropdowns, I appreciate that.

Thanks in advance.
Posts: 20348
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am probably missing the most important part, but there are a couple of items there that distract me. !Most notably, a backing bean is not a Controller! Apparently NetBeans has a wizard that creates backing beans like this, but in JSF, you do not write Controllers, only Models (Backing Beans) and View Templates. Some people get confused because the Backing Bean can contain action methods, but a Controller is responsible for transferring values to and from the View, and action methods are business logic.

From your screenshot, I think you've improperly defined your property-get methods on your SelectItems, because what's displaying is what a toString() method would return on a raw object and not the label. A SelectItem is a sub-model object that contains 2 components: the displayed label String and the associated value Object. What you are assigning to the label property of the SelectItem is not a String, it's an Object, so JSF is calling toString() in the hope that it can get a usable label string from it.

Probably the easiest way to do an explicit AJAX call from PrimeFaces is to understand that PrimeFaces is built on jQuery. So you can use the jQuery AJAX methods, with a few qualifications. First, the version of jQuery that PrimeFaces is normally using may be fairly old, so check to make sure that whatever you're coding works under that release of jQuery. There are ways to use a newer version of jQuery, but it's complicated.

The second thing to beware of is that the jQuery "$" notation does not work in JSF, because in JSF, "$" and "#" are meta-characters of the Unified Expression Language (EL). So you have to use the long-form "jQuery.something()" form, instead.
Can't .... do .... plaid .... So I did this tiny ad instead:
Programmatically Create PDF Using Free Spire.PDF with Java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!