• 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

How to use JPA bean and external property with datatable

 
Ranch Hand
Posts: 31
Hibernate Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27807
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
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.
 
Bartender
Posts: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 27807
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

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: 1104
10
Netbeans IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic