Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSF - Rich Faces - Suggest Design for Checkboxes column in Data table  RSS feed

 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I have following design issue with JSF rich faces.

I have a rich table which will display rows of a table through a Entity class.
-->Now I need to add a checkbox column to it <--

So is it a good programming practise to place a field in my entity class, like following ?

@Entity
class Person
{
...
...
...
@transient
boolean selected = false;
}


Are we overloading Entity? what about the scenarios where in we do not require those additional transient fields?
Can I have wrapper around Person entity saying

class PersonWithUIState extends Person
{

private boolean selected = false;
private boolean editable = false;
private boolean deletable = false;

etc...

}


Please suggest.

}
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you can extend the domain model class (Person) with decorations on it to make a UI model class and use instances of that class as the wrapped row data for a dataTable. Or you can use one of the other common design patterns that allow similar enhancements. A lot of people think that the UI data model MUST be the domain model, and it simply isn't so.

As a general rule, I wouldn't modify the domain model class itself. It's too much like mixing business logic in with your persistence data definitions. And in many shops, the domain model may be a jar (or EJB jar) that comes from some other group and isn't easy to get modified. Especially if just one application needs it.
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tim. By the way could you please point any one pattern which is already addressing this problem?
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The Decorator pattern is probably the closest, although without checking the fine details I often have trouble distinguishing one enhancement pattern from another.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!