This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSF and the fly likes How to use JPA bean and external property with datatable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "How to use JPA bean and external property with datatable" Watch "How to use JPA bean and external property with datatable" New topic
Author

How to use JPA bean and external property with datatable

Balaji Kadam
Ranch Hand

Joined: Apr 27, 2010
Posts: 31

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

Joined: Jun 25, 2001
Posts: 16019
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
Ranganathan Kaliyur Mannar
Bartender

Joined: Oct 16, 2003
Posts: 1076
    
  10

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.


Ranga.
SCJP 1.4, OCMJEA/SCEA 5.0.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

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

Joined: Oct 16, 2003
Posts: 1076
    
  10

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...
 
wood burning stoves
 
subject: How to use JPA bean and external property with datatable