• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using mapped properties with jsf forms

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to make form to modify custom user properties and set them one of provided values (0, 1, -1). To do this I've decided to use Map<Integer, Integer> when key is property identifier and value is one of 0, -1, 1. Following code is used to display form:



Displaying filled form works well but when I try to save following form my tmpPrivilege variable gets some strange values instead of one of integers (0, -1, 1). Strange thing is that setter I've made for this Map is never called. Maybe my setter should look different? How to make form like this?

Here is my setter:


I'm using primefaces is it's relevant.
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't code a setter for that.

Only the top-level qualifier for an EL variable reference is fetched/stored. The EL processor (which is commonly Apache BeanUtils) will then get that property and recurse on it down to the bottom-level property, where it will apply any keys or indexes.

So your backing bean only needs to supply the "getTmpPrivilege()" method, which should return the Map. BeanUtils will then invoke getPrivilegeId() on the current privilege row to get the index value, which it will look up in the tmpPrivilege map ("get" references). Or put() the selection value there (for "set" references).
 
Wojciech Sielski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok but still values which I get after calling actionListener are all messed up. For example after checking in each row radioButton with value 1, I'm getting some random values.

getter is simple creating map key => value where value {0,-1,1}
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, I don't encourage using actionListener. Action methods are better in almost all cases. But that's not important here.

Normally at this point, I'd set debug breakpoints on the Map get/set methods. If that wasn't possible, I'd subclass the Map class and add print statements to the set/get methods just to be sure I knew what values were being set. And under which keys and when.
 
Wojciech Sielski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried to debug this but couldn't find reason. I'll will try to subclass Map like you said.
 
Wojciech Sielski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok now I had some time for checking out what is happening with my code. Unfortunately there is something strange going on with values. Instead of using two times put method it's calling it like 4 times more. Another thing is, even if there were so many calls for put method none of them had value passed from form. It looks like it's creating Map like few times and keys are always ok but values are only (0 or 1) even if values available was only {99,-1,60}
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is common and proper for the get/set property methods to be invoked multiple times during the JSF lifecycle. That is why get/set methods should not have side effects and should do no heavy work.

It also sounds like you might have your backing bean defined in Request scope. Request Scope is almost totally useless in JSF, on account of the way JSF form postbacks work.
 
Wojciech Sielski
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I've found problem. It looks like Map using integer as value won;t work without proper Converter. That's why there were problem with converting String to Integer and every time I've tried to save form values were messed up.
 
Live a little! The night is young! And we have umbrellas in our drinks! This umbrella has a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic