You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Joel McConaughy <jo...@displayware.com> on 2004/04/17 02:07:42 UTC

Hibernate, Woody and repeaters

I am having trouble using the result of a hibernate query in a woody 
form.   I'm trying to do the following:

1.  Generate the bean from a hibernate mapping file using hbm2java.
2.  Load the entire contents of a table using hibernate -- obj = 
hs.find(queryString).
3.  Use the resulting object as the form model for woody -- form.load(obj).
4.  Save the (possibly) edited results -- hs.save(obj);

I think I have datatype problems but not sure how to fix them.  I've 
attached the flowscript code, exception text, form definition and bean 
class.   Any help will be GREATLY appreciated.  Thanks in advance.

Joel

Here's the offending code:

    var factory = 
cocoon.getComponent(Packages.com.displayware.hiblib.PersistenceFactory.ROLE);
    var hs = factory.createSession();
    var contacts = hs.find("from User");
    cocoon.log.debug("contacts.size() = " + contacts.size()); // RETURNS 1
    form.load(contacts);  // EXCEPTION THROWN HERE 
    form.showForm("useradmin-display-pipeline");

This throws the following exception:

"resource://org/apache/cocoon/woody/flow/javascript/woody2.js", line 
191: Invalid JavaScript value of type org.mozilla.javascript.UniqueTag


The model I'm using for the form looks like this:

<?xml version="1.0" encoding="ISO-8859-1"?>
<wd:form xmlns:wd="http://apache.org/cocoon/woody/definition/1.0"
xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
  <wd:widgets>
    <wd:field id="tab-state">
      <wd:datatype base="string" />
    </wd:field>
    <wd:repeater id="contacts">
      <wd:widgets>
        <wd:field id="username" required="true">
          <wd:label>Username</wd:label>
          <wd:datatype base="string" />
        </wd:field>
etc...
    </wd:repeater>
    <wd:repeater-action id="addcontact" action-command="add-row"
    repeater="contacts">
      <wd:label>Add contact</wd:label>
    </wd:repeater-action>
    <wd:repeater-action id="removecontacts"
    action-command="delete-rows" repeater="contacts" select="select">
      <wd:label>Remove selected contacts</wd:label>
    </wd:repeater-action>
  </wd:widgets>
</wd:form>

The bean looks like this:

package com.displayware.hiblib;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class User implements Serializable {

    /** identifier field */
    private Long id;

    /** persistent field */
    private String username;

    /** nullable persistent field */
    private String password;

    /** nullable persistent field */
    private String firstname;

    /** nullable persistent field */
    private String lastname;

    /** nullable persistent field */
    private String phone;

    /** nullable persistent field */
    private String email;

    /** full constructor */
    public User(String username, String password, String firstname, 
String lastname, String phone, String email) {
        this.username = username;
        this.password = password;
        this.firstname = firstname;
        this.lastname = lastname;
        this.phone = phone;
        this.email = email;
    }

    /** default constructor */
    public User() {
    }

    /** minimal constructor */
    public User(String username) {
        this.username = username;
    }

    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return this.password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstname() {
        return this.firstname;
    }

    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    public String getLastname() {
        return this.lastname;
    }

    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    public String getPhone() {
        return this.phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getEmail() {
        return this.email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("id", getId())
            .toString();
    }

    public boolean equals(Object other) {
        if ( !(other instanceof User) ) return false;
        User castOther = (User) other;
        return new EqualsBuilder()
            .append(this.getId(), castOther.getId())
            .isEquals();
    }

    public int hashCode() {
        return new HashCodeBuilder()
            .append(getId())
            .toHashCode();
    }

}

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Hibernate, Woody and repeaters

Posted by Marc Portier <mp...@outerthought.org>.
Enjoy those beers dudes!

-marc=



Joel McConaughy wrote:

> You're on!  The beer fridge is stocked...
>  
> Thanks for the help.
>  

<snip/>

>  
>     -----Original Message-----
>     *From:* Mark Lundquist [mailto:ml@wrinkledog.com]
 >
>     P.S. One gets so used to corresponding with people all over the
>     world on these lists, so when I saw that you're in Seattle, it felt
>     like we're practically neighbors (I'm in Portland)... "tell you
>     what, forget the email, I'll hop on I-5 and come up and just come up
>     and /look/ at your code..." :-)
> 

-- 
Marc Portier                            http://outerthought.org/
Outerthought - Open Source, Java & XML Competence Support Center
Read my weblog at                http://blogs.cocoondev.org/mpo/
mpo@outerthought.org                              mpo@apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: Hibernate, Woody and repeaters

Posted by Joel McConaughy <jo...@displayware.com>.
You're on!  The beer fridge is stocked...
 
Thanks for the help.
 
 

Joel McConaughy 
Managing Partner 
Displayware 
800 Fifth Ave., #101-316 
Seattle, WA 98104-3191 
206-300-4732 Direct 
206-382-2188 Fax 
 <ma...@execs.com> joel@displayware.com 

-----Original Message-----
From: Mark Lundquist [mailto:ml@wrinkledog.com] 
Sent: Saturday, April 17, 2004 11:04 AM
To: users@cocoon.apache.org
Subject: Re: Hibernate, Woody and repeaters



On Apr 17, 2004, at 10:28 AM, Joel McConaughy wrote:



I think maybe we're getting to problem.



Definitely, I would say so... :-)



 I haven't created a binding under the (probably mistaken) assumption
that there is a default jxpath binding that maps the structure of the
form definition file to a corresponding bean -- this binding runs for
example when form.getModel() is called.  So, I have been trying to use
this default binding as is, substituting the bean created by hbm2java.
In the form2bean sample, I can't even find a binding file.  Do I need
one?



Yep... can't do load()/save() without a binding. From the samples
sitemap, here's the pipeline that invokes the form2bean controller:

<map:match pattern="form2bean.flow">
<map:call function="handleForm">
<map:parameter name="function" value="form2bean"/>
<map:parameter name="form-definition" value="forms/form2_model.xml"/>
<map:parameter name="bindingURI" value="forms/form2_bind_bean.xml"/>
</map:call>
</map:match>

The parameter "bindingURI" specifies the binding descriptor - so have a
look-see in forms/form2_bind_bean.xml, and you'll be well on your way!

~mark

P.S. One gets so used to corresponding with people all over the world on
these lists, so when I saw that you're in Seattle, it felt like we're
practically neighbors (I'm in Portland)... "tell you what, forget the
email, I'll hop on I-5 and come up and just come up and look at your
code..." :-)




Re: Hibernate, Woody and repeaters

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Apr 17, 2004, at 10:28 AM, Joel McConaughy wrote:

> I think maybe we're getting to problem.

Definitely, I would say so... :-)

>  I haven't created a binding under the (probably mistaken) assumption 
> that there is a default jxpath binding that maps the structure of the 
> form definition file to a corresponding bean -- this binding runs for 
> example when form.getModel() is called.  So, I have been trying to use 
> this default binding as is, substituting the bean created by 
> hbm2java.  In the form2bean sample, I can't even find a binding file.  
> Do I need one?

Yep... can't do load()/save() without a binding.  From the samples 
sitemap, here's the pipeline that invokes the form2bean controller:

        <map:match pattern="form2bean.flow">
        <map:call function="handleForm">
          <map:parameter name="function" value="form2bean"/>
          <map:parameter name="form-definition" 
value="forms/form2_model.xml"/>
          <map:parameter name="bindingURI" 
value="forms/form2_bind_bean.xml"/>
        </map:call>
      </map:match>

The parameter "bindingURI" specifies the binding descriptor — so have a 
look-see in forms/form2_bind_bean.xml, and you'll be well on your way!

~mark

P.S. One gets so used to corresponding with people all over the world 
on these lists, so when I saw that you're in Seattle, it felt like 
we're practically neighbors (I'm in Portland)... "tell you what, forget 
the email, I'll hop on I-5 and come up and just come up and look at 
your code..." :-)


RE: Hibernate, Woody and repeaters

Posted by Joel McConaughy <jo...@displayware.com>.
I think maybe we're getting to problem. I haven't created a binding
under the (probably mistaken) assumption that there is a default jxpath
binding that maps the structure of the form definition file to a
corresponding bean -- this binding runs for example when form.getModel()
is called.  So, I have been trying to use this default binding as is,
substituting the bean created by hbm2java.  In the form2bean sample, I
can't even find a binding file.  Do I need one?
 
 

Joel McConaughy 
Managing Partner 
Displayware 
800 Fifth Ave., #101-316 
Seattle, WA 98104-3191 
206-300-4732 Direct 
206-382-2188 Fax 
 <ma...@execs.com> joel@displayware.com 

-----Original Message-----
From: Mark Lundquist [mailto:ml@wrinkledog.com] 
Sent: Friday, April 16, 2004 8:27 PM
To: users@cocoon.apache.org
Subject: Re: Hibernate, Woody and repeaters



On Apr 16, 2004, at 7:42 PM, Joel McConaughy wrote:



Mark,

Glad to hear from you! Here's the form template.



OK, but let's see the binding... you know, the thing with <wd:context>
as the root element... :-)
~ mark




Re: Hibernate, Woody and repeaters

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Apr 16, 2004, at 7:42 PM, Joel McConaughy wrote:

> Mark,
>
> Glad to hear from you!  Here's the form template.

OK, but let's see the binding... you know, the thing with <wd:context> 
as the root element... :-)
~ mark


RE: Hibernate, Woody and repeaters

Posted by Joel McConaughy <jo...@displayware.com>.
Mark,

Glad to hear from you!  Here's the form template.  Basically, a cut n
paste from Hugo's sample with a few things changed.  If I comment out
the form.load() in the flow, this form displays fine (albeit empty). 

joel

 <?xml version="1.0" ?> 
  <page xmlns:wt="http://apache.org/cocoon/woody/template/1.0"
xmlns:wi="http://apache.org/cocoon/woody/instance/1.0">
  <title>Centerpad User Administration</title> 
  <logout /> 
  <content>
  <wt:form-template action="#{$continuation/id}.continue" method="POST">
  <table align="center">
  <tr>
  <td>
  <!--  group with tabs. Each of the children of <items> will constitute
a tab 
  --> 
  <wi:group>
  <wi:styling type="tabs" /> 
  <wi:label>Choose a panel:</wi:label> 
  <wi:state>
  <wt:widget id="tab-state" /> 
  </wi:state>
  <!--  group with automatic two-column layout 
  --> 
  <wi:items>
  <wi:group>
  <wi:styling layout="columns" /> 
  <wi:label>User fields</wi:label> 
  <wi:items>
  <!--  manual layout of fieldw, without use of a wi:group 
  --> 
  <wt:widget-label id="contacts" /> 
  <br /> 
  <wt:repeater-size id="contacts" /> 
  <table border="1">
  <tr>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="username" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="password" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="firstname" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="lastname" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="phone" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="email" /> 
  </th>
  <th>
  <wt:repeater-widget-label id="contacts" widget-id="select" /> 
  </th>
  </tr>
  <!-- 
 The contents of the repeater-widget element is a template that will
        be applied to each row in the repeater. 

  --> 
  <wt:repeater-widget id="contacts">
  <tr>
  <td>
  <wt:widget id="username" /> 
  </td>
  <td>
  <wt:widget id="password" /> 
  </td>
  <td>
  <wt:widget id="firstname" /> 
  </td>
  <td>
  <wt:widget id="lastname" /> 
  </td>
  <td>
  <wt:widget id="phone" /> 
  </td>
  <td>
  <wt:widget id="email" /> 
  </td>
  <td>
  <wt:widget id="select" /> 
  </td>
  </tr>
  </wt:repeater-widget>
  <tr>
  <td colspan="4" align="right">
  <wt:widget id="addcontact" /> 
  <wt:widget id="removecontacts" /> 
  </td>
  </tr>
  </table>
  <input type="submit" /> 
  </wi:items>
  </wi:group>
  </wi:items>
  </wi:group>
  <input type="submit" /> 
  </td>
  </tr>
  </table>
  </wt:form-template>
  </content>
  </page>

Joel McConaughy
Managing Partner
Displayware
800 Fifth Ave., #101-316
Seattle, WA 98104-3191
206-300-4732 Direct
206-382-2188 Fax
joel@displayware.com


-----Original Message-----
From: Mark Lundquist [mailto:ml@wrinkledog.com] 
Sent: Friday, April 16, 2004 6:09 PM
To: users@cocoon.apache.org
Subject: Re: Hibernate, Woody and repeaters



On Apr 16, 2004, at 5:07 PM, Joel McConaughy wrote:

> I am having trouble using the result of a hibernate query in a woody
> form.

ha ha, as it so happens I am up to my elbows in Hibernate today, too... 
:-)

>    I'm trying to do the following:
>
> 1.  Generate the bean from a hibernate mapping file using hbm2java. 2.

> Load the entire contents of a table using hibernate -- obj = 
> hs.find(queryString). 3.  Use the resulting object as the form model 
> for woody -- form.load(obj).
> 4.  Save the (possibly) edited results -- hs.save(obj);
>
> I think I have datatype problems but not sure how to fix them.  I've
> attached the flowscript code, exception text, form definition and bean

> class.   Any help will be GREATLY appreciated.  Thanks in advance.

What does your form binding document look like?
~mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: Hibernate, Woody and repeaters

Posted by Mark Lundquist <ml...@wrinkledog.com>.
On Apr 16, 2004, at 5:07 PM, Joel McConaughy wrote:

> I am having trouble using the result of a hibernate query in a woody 
> form.

ha ha, as it so happens I am up to my elbows in Hibernate today, too... 
:-)

>    I'm trying to do the following:
>
> 1.  Generate the bean from a hibernate mapping file using hbm2java.
> 2.  Load the entire contents of a table using hibernate -- obj = 
> hs.find(queryString).
> 3.  Use the resulting object as the form model for woody -- 
> form.load(obj).
> 4.  Save the (possibly) edited results -- hs.save(obj);
>
> I think I have datatype problems but not sure how to fix them.  I've 
> attached the flowscript code, exception text, form definition and bean 
> class.   Any help will be GREATLY appreciated.  Thanks in advance.

What does your form binding document look like?
~mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org