You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@click.apache.org by johnfilo <jo...@layerm.com.au> on 2010/11/25 12:26:45 UTC

HibernateForm - How do I pass an object into the form to edit?

Hiya

New to Click and Hibernate, let that be known.

Been trying to use the HibernateForm from click-extras but not having any
luck in figuring out how to pass an object into the form for editing?

Does anyone care to share an example?

My object is called User. It has the following properties:

id (db identity column)
username
password
email

I have the form and page created no problems, and can add a new object to
the DB, but can't figure out how to pass an object into the form to edit...

>From the doco here
http://click.apache.org/docs/extras-api/org/apache/click/extras/hibernate/HibernateForm.html
it has this to say:

"To edit an existing user object, the object is passed to the page as a
request parameter"

Now I have tried everything I can think of......but still nothing.

Please please enlighten me :) hahaha

Cheers
John
-- 
View this message in context: http://click.1134972.n2.nabble.com/HibernateForm-How-do-I-pass-an-object-into-the-form-to-edit-tp5773903p5773903.html
Sent from the click-user mailing list archive at Nabble.com.

Re: HibernateForm - How do I pass an object into the form to edit?

Posted by johnfilo <jo...@layerm.com.au>.
Hi Bob,

Thanks for responding. I have found that out myself that HibernateForm is a
little annoying in it's limited validation.

I have started to look into using the standard Form, with some of the
concepts of HibernateForm, and this seems to give me what I need for this
app.

Thanks again

John 
-- 
View this message in context: http://click.1134972.n2.nabble.com/HibernateForm-How-do-I-pass-an-object-into-the-form-to-edit-tp5773903p5787132.html
Sent from the click-user mailing list archive at Nabble.com.

Re: HibernateForm - How do I pass an object into the form to edit?

Posted by Bob Schellink <sa...@gmail.com>.
Hi John,

The quoted javadoc seems a bit off. I've never seen an object passed as a request attribute or even
parameter. Generally only the object ID or surrogate key is passed around. As Gilberto has said you
then lift the entity and set it on the Form. Once an enity has been set HibernateForm uses two
HiddenFields to pass the Entity ID and Entity class between posts. The Form will automatically load
the Entity from Hibernate Session when getValueObject is called.

Since you are new to both Click and Hibernate it might be worth considering using just a normal Form
when you find you are struggling with HibernaterForm. When using a Form you essentially need to use
a HiddenField to pass the entity ID (or a surrogate ID) between posts. HibernateForm also adds
limited validation to it's Fields based on Entity meta data supplied by Hibernate. For example if
the db column does't allow null, the Field will be required.

Kind regards

Bob

On 26/11/2010 08:57, johnfilo wrote:
> 
> Hi Gilberto,
> 
> Your a champ! Thanks for the help and quick response. I tried this out and
> it now populates the form as expected.
> 
> I have another issue now around the Transaction Manager used by hibernate
> and WebSphere, but I will open a new topic if I can't figure that out 
> 
> Thanks again!
> 
> John


Re: HibernateForm - How do I pass an object into the form to edit?

Posted by johnfilo <jo...@layerm.com.au>.
Hi Gilberto,

Your a champ! Thanks for the help and quick response. I tried this out and
it now populates the form as expected.

I have another issue now around the Transaction Manager used by hibernate
and WebSphere, but I will open a new topic if I can't figure that out 

Thanks again!

John
-- 
View this message in context: http://click.1134972.n2.nabble.com/HibernateForm-How-do-I-pass-an-object-into-the-form-to-edit-tp5773903p5775593.html
Sent from the click-user mailing list archive at Nabble.com.

Re: HibernateForm - How do I pass an object into the form to edit?

Posted by Gilberto <gi...@gmail.com>.
Correction:

replace

form.copyFrom(naturalPerson);

with

setValueObject(naturalPerson);

Hth,

Gilberto


2010/11/25 Gilberto <gi...@gmail.com>

> Hi, John!
>
> I think it isn't different from normal Form control.
> This one is my:
> <quote>
>     /**
>      * When page is first displayed on the GET request.
>      *
>      * @see Page#onGet()
>      */
>     @Override
>     public void onGet() {
>         if (id != null) {
>             NaturalPerson naturalPerson = naturalPersonService.find(id);
>
>             if (naturalPerson != null) {
>                 // Copy naturalPerson data to form. The idField value will
> be set by
>                 // this call
>                 form.copyFrom(naturalPerson);
>             }
>         }
>
>         if (referrer != null) {
>             // Set referrerField HiddenField to bound referrer field
>             referrerField.setValue(referrer);
>         }
>     }
> </quote>
>
> Hth,
>
> Gilberto
>
> 2010/11/25 johnfilo <jo...@layerm.com.au>
>
>
>> Hiya
>>
>> New to Click and Hibernate, let that be known.
>>
>> Been trying to use the HibernateForm from click-extras but not having any
>> luck in figuring out how to pass an object into the form for editing?
>>
>> Does anyone care to share an example?
>>
>> My object is called User. It has the following properties:
>>
>> id (db identity column)
>> username
>> password
>> email
>>
>> I have the form and page created no problems, and can add a new object to
>> the DB, but can't figure out how to pass an object into the form to
>> edit...
>>
>> From the doco here
>>
>> http://click.apache.org/docs/extras-api/org/apache/click/extras/hibernate/HibernateForm.html
>> it has this to say:
>>
>> "To edit an existing user object, the object is passed to the page as a
>> request parameter"
>>
>> Now I have tried everything I can think of......but still nothing.
>>
>> Please please enlighten me :) hahaha
>>
>> Cheers
>> John
>> --
>> View this message in context:
>> http://click.1134972.n2.nabble.com/HibernateForm-How-do-I-pass-an-object-into-the-form-to-edit-tp5773903p5773903.html
>> Sent from the click-user mailing list archive at Nabble.com.
>>
>
>

Re: HibernateForm - How do I pass an object into the form to edit?

Posted by Gilberto <gi...@gmail.com>.
Hi, John!

I think it isn't different from normal Form control.
This one is my:
<quote>
    /**
     * When page is first displayed on the GET request.
     *
     * @see Page#onGet()
     */
    @Override
    public void onGet() {
        if (id != null) {
            NaturalPerson naturalPerson = naturalPersonService.find(id);

            if (naturalPerson != null) {
                // Copy naturalPerson data to form. The idField value will
be set by
                // this call
                form.copyFrom(naturalPerson);
            }
        }

        if (referrer != null) {
            // Set referrerField HiddenField to bound referrer field
            referrerField.setValue(referrer);
        }
    }
</quote>

Hth,

Gilberto

2010/11/25 johnfilo <jo...@layerm.com.au>

>
> Hiya
>
> New to Click and Hibernate, let that be known.
>
> Been trying to use the HibernateForm from click-extras but not having any
> luck in figuring out how to pass an object into the form for editing?
>
> Does anyone care to share an example?
>
> My object is called User. It has the following properties:
>
> id (db identity column)
> username
> password
> email
>
> I have the form and page created no problems, and can add a new object to
> the DB, but can't figure out how to pass an object into the form to edit...
>
> From the doco here
>
> http://click.apache.org/docs/extras-api/org/apache/click/extras/hibernate/HibernateForm.html
> it has this to say:
>
> "To edit an existing user object, the object is passed to the page as a
> request parameter"
>
> Now I have tried everything I can think of......but still nothing.
>
> Please please enlighten me :) hahaha
>
> Cheers
> John
> --
> View this message in context:
> http://click.1134972.n2.nabble.com/HibernateForm-How-do-I-pass-an-object-into-the-form-to-edit-tp5773903p5773903.html
> Sent from the click-user mailing list archive at Nabble.com.
>