cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Joel McConaughy <j...@displayware.com>
Subject Hibernate, Woody and repeaters
Date Sat, 17 Apr 2004 00:07:42 GMT
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


Mime
View raw message