-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Best way of handling/convert pojo to view (mvc) from model ?
PostPosted: Tue Sep 16, 2008 7:01 am 
Newbie

Joined: Fri May 11, 2007 3:04 am
Posts: 3
Hibernate version:3.2.5 or newer
What is the best way of handling/convert pojo to view from the model?
I am not using spring/seam/ejb etc, just java with hibernate.
(Later on maybe we will convert this to use ejb3 instead.)

If I have for example a table named tabl1 with columns col1,col2,col3 mapped to tabl1.java pojo and wish to use this in the view part in a web or swing application for a TableComponent or a DropDownComponent.
where I would need specific properties for the TableComponent, like selectedrow, sortable, editable that is not stored in a db, just runtime properties that is used in the view.

I am using bean binding to get the properties in the pojo.
I am trying to do this using netbeans 6.1 witth jdk 6 and glassfish2.
I haven found any example that does not add the properties to the pojo/bean directly, but I am not sure this is the right way to go, since you are then messing with the model objects/pojos directly. The point of the mvc is that the model should stay the same regardless if it is a webb application or a swing application that use it, but it will need to be transformed/converted for the user interface.

Original pojo/bean
Code:
class tab1 {
public tab1(){
};
String col1;
String col2;
String col3;
}


Could I do something like this?
Code:
class tab1web extends tab1 {
public tab1web(){
   super();
};
Boolean selectedrow;
Boolean sortable;
Boolean editable;
}


Or something like this
Code:
class tab1 {
public tab1(){
};
String col1;
String col2;
String col3;
// Not bound properties, only used in runtime
Boolean selectedrow;
Boolean sortable;
Boolean editable;
}

Or should it be done in another way ? Is there some other way to do it ?

Would one then create a new class that inherits from the base class, and include the extra properties ? Do you extend it using hibernate mappings or have to do this ?

Do you create a new class that include the extra properties along with the mapped ones in a table and use this ?

Would this class also have to be mapped using hibernate or can one accomplish this in another way, by only having the base class mapped ?

Any insight,ideas,recommendations would be greatly appreciated on how to do this the best/recommended way.
Since we want to try and keep the view model separated or as loosely coupled to the model as possible, yet handle this conversion/transformation efficiently.

This must be a fairly common problem to any developer trying to use hibernate in a web application or a swing application. However I haven't found any good solutions and examples on how you handle this the mvc way.

Any links to other forums or articles describing this would also be useful.
I have looked at all examples on netbeans and tried looking at the hibernate documentation and searched the web but not found the information i need.

/Kind Regards Roger


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.