• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to use JPA bean and external property with datatable

 
Balaji Kadam
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I want a datatable to display value from DB and for that i have used JPA bean as value to datatable, it is working fine but now i want a more property to datatable for checkbox but there is no property in JPA bean that i can assign to check box. and i dont wanted to create that.

how can i achieve this?

Thanks
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Unfortunately, you cannot. Converters can't handle binary checkbox conversion and checkboxes MUST be backed by binary. properties.

That means that unless you create a checkbox control of your own with more forgiving capabilities, you can only implement a checkbox against some sort of façade model rather than directly against the JPA object itself.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can consider having a boolean field in the JPA bean and mark it with the @Transient annotation. This way, it won't be persisted and you can use it only for UI purposes.
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18226
53
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ranganathan Kaliyur Mannar wrote:You can consider having a boolean field in the JPA bean and mark it with the @Transient annotation. This way, it won't be persisted and you can use it only for UI purposes.


Which is basically a decoration (similar to a façade), but it's a kludge that may confuse people when maintenance time comes. Personally, I'd feel more comfortable doing an external decoration instead of coding it into the ORM (which some shops don't allow anyway).

I should point out that in a few ORM systems, there's a provision within the ORM itself to convert values to/from non-boolean to boolean properties at the ORM level. It's not standard, however, so I didn't mention it initially.
 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so, you mean in the backing bean i.e have the ORM model as an instance variable in the backing bean and other boolean instance variables for the UI?
yah, that will be cleaner though the EL be will be longer...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic