Stripes - Nested/Indexed Properties - Select element not populating a NULL value correctly
Joined: Oct 11, 2011
Hi Everyone. Long-time lurker, first-time poster here. I'm using Stripes and I've found some strange behavior.
I have an ActionBean that has a list of Module objects. I have a JSP that is essentially a CRUD utility to modify this list of objects. The JSP uses indexing to display and modify values for the entire list at once. One of the properties in the Module object, raVersion, is used to link the modules together (think an EMPLOYEE table in a database where each row has a managerID column that references a different employeeID in the same table). This property is represented using a select element on the JSP with an option for a NULL value and an options-collection to list all of the Module IDs/keys.
When two modules are linked together they both refer to each other's ModuleKeys in their raVersion property/field. When someone unlinks the two by selecting NULL as the raVersion for one of them on the JSP, I have the ActionBean set the raVersion as NULL for the other one as well. All of this occurs perfectly, but the NULL that I am setting for the second module programmatically is not being reflected when the JSP reloads. It retains its previous value in the select element even though its value has changed.
Here is the code:
To recap, I can set a NULL value perfectly fine for the raVersion of one of the modules via the select element. But when I use that to programmatically set the raVersion to NULL for the other module it was previously linked to, the proper value (NULL) is not displayed correctly on the JSP. I have confirmed through various log statements that the NULL value is getting set perfectly fine. It's just that the JSP is not rendering the second select the way I would expect it to (it displays its previous value instead of the newly set NULL value).
Any idea what I'm doing wrong here? Is this expected behavior??
Joined: Oct 11, 2011
After some thorough Googling, I found the source of the problem and solved it. (The only related post I found on the forum is here)
By default Stripes (as of v1.5) looks in the following places (in this order) to determine a tag's value:
The current request's parameters
An ActionBean (if one is present)
A value provided for the tag on the JSP
So, if you programmatically change a value of an element in your bean, but a non-null value was provided for that element in the original request, Stripes will choose the first non-null value: the original value that was sent in the request. For more information go the official documentation: Input Tag Population and Repopulation
If you want Stripes to look in the bean first, you just have to set its PopulationStrategy to the BeanFirstPopulationStrategy. Normally, you can set this at an application-wide level, but you can also override the PopulationStrategy per bean. Here are the pertinent links that explain how to do so: