facebook

Hibernate, DataService, and ActionForms

  1. MyEclipse IDE
  2.  > 
  3. Comments
Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #214996 Reply

    Ok…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

    #215002 Reply

    Riyad Kalla
    Member

    Nope, 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.

    #215003 Reply

    Riyad Kalla
    Member

    Moving to Random Thoughts, this is a design question…

    #215025 Reply

    snpe
    Member
    #215081 Reply

    @snpe wrote:

    You can try with commons-beanutils

    see http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/org/apache/commons/beanutils/BeanUtils.html

    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

    #215083 Reply

    Riyad Kalla
    Member

    😐

    I had no idea comons-beanutils could do that, very cool followup Lee, thanks!

    #215085 Reply

    Well…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

    #215093 Reply

    Riyad Kalla
    Member

    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 😀

    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.

    #215099 Reply

    @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

    #215104 Reply

    Riyad Kalla
    Member

    Lee,
    I’ll ask the Hib dev to take a look at this, we’ve hit the cieling on my knowledge of that module 😉

    #215136 Reply

    support-jeff
    Member

    Depends 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.

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Hibernate, DataService, and ActionForms

You must be logged in to post in the forum log in