- This topic has 10 replies, 4 voices, and was last updated 20 years, 2 months ago by support-jeff.
-
AuthorPosts
-
Lee HarringtonMemberOk…a somewhat related question to my earlier one. Consider a list screen where you select a record and are presented with a maintenance screen for that record.
Going from list screen to maintenance screen you call your Action which:
1. Gets the primary key from getParameter
Int primaryKey = request.getParameter("primaryKey");
2. Calls the hibernate wizard generated service to get the record from the database returned as an instance of a POJO.
MyTable mytable = MyTableService.getInstance().getMyTable(primaryKey);
This is terrific. You’ve used the wizard generated hibernate code and now have a POJO representation of the desired row of your database.
Now you need to populate the ActionForm with values from the “mytable” POJO. But what a pain that is.
MyActionForm.setField1(mytable.getField1()); MyActionForm.setField2(mytable.getField2()); MyActionForm.setField3(mytable.getField3()); MyActionForm.setField4(mytable.getField4()); MyActionForm.setField5(mytable.getField5()); ....
Am I not thinking this through correctly?
Lee
Riyad KallaMemberNope, you are… unless you add a custom method to the form to do this for you, I’m not aware of another way to mass-populate a forms values.
Riyad KallaMemberMoving to Random Thoughts, this is a design question…
snpeMemberYou can try with commons-beanutils
regards
Lee HarringtonMember@snpe wrote:
You can try with commons-beanutils
regards
That worked splendedly.
Long primaryKey = Long.decode(request.getParameter("primaryKey")); // Get instance of record for the given primaryKey MyTable myTable = MyTableService.getInstance().getMyTable(primaryKey); // Get the Form instance from the request scope MyTableForm myForm = (MyTableForm) request.getAttribute("myTableForm"); // Copy the values from myTable to myForm BeanUtils.copyProperties(myForm,myTable);
Lee
Riyad KallaMember😐
I had no idea comons-beanutils could do that, very cool followup Lee, thanks!
Lee HarringtonMemberWell…thanks to SNPE…. 🙂
I’m in the process of creating my first CRUD screen, and I’m trying to establish best standards and practices along the way. I just knew there had to be a better way then hand coding that stuff.
Speaking of hand coding — how would one go about changing the code that the hibernate wizard automatically generates?
Lee
Riyad KallaMemberSpeaking of hand coding — how would one go about changing the code that the hibernate wizard automatically generates?
In terms of hand coding…. I’d open it in the Java editor and start typing 😀
Do you mean the templates? How do you want to “change” it? If you want to add customizations to it, do it in the extended class, the base Abstract classes are regenerated.
Lee HarringtonMember@support-rkalla wrote:
Speaking of hand coding — how would one go about changing the code that the hibernate wizard automatically generates?
In terms of hand coding…. I’d open it in the Java editor and start typing 😀
(smile) — in terms of AVOIDING hand coding 🙂
@support-rkalla wrote:
Do you mean the templates? How do you want to “change” it? If you want to add customizations to it, do it in the extended class, the base Abstract classes are regenerated.
If I wanted to change how the base Abstract classes are generated. Oh, and thanks for cleaering a question for me as to why they class/abastract class design was done. Makes sense to me, wouldn’t want to lose my customizations. Kudos on your design.
However, I an foresee new methods that I would want to be automatically generated in the abstract class — can we modify this?
Lee
Riyad KallaMemberLee,
I’ll ask the Hib dev to take a look at this, we’ve hit the cieling on my knowledge of that module 😉
support-jeffMemberDepends on what you want to do…
If you have standard code you want in all generated Hibernate POJO classes, then add it to the velocity templates in $MYECLIPSE_HOME/plugins/com.genuitec.eclipse.hibernate/templates. Just be sure to backup the originals in case, you know, you screw something up 😉
The $mappedObject variable is exposed in these templates, but there is no published API (yet) for the class behind the object.
-
AuthorPosts