You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Artur_eol <ar...@gmail.com> on 2008/08/26 15:20:10 UTC

Tapestry 5, problem with foreign field

Hello everybody, I hava problem with foreign key - field. This is my Java
class:

package org.cimlvin.domain.model;

import java.io.Serializable;
import java.sql.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.apache.tapestry.beaneditor.Validate;

// TODO: Auto-generated Javadoc
/**
 * The Class QuestionaireQuestion.
 */
@SuppressWarnings("unchecked")
@Entity
@Table(name = "QUESTIONS")
@NamedQueries( {
                @NamedQuery(name = "QuestionaireQuestion.findByType", query
= "select e from QuestionaireQuestion e where e.questionType = ?1"),
                @NamedQuery(name = "QuestionaireQuestion.findByTitle", query
= "select e from QuestionaireQuestion e where e.title = ?1"),
                @NamedQuery(name = "QuestionaireQuestion.findById", query =
"select e from QuestionaireQuestion e where e.id = ?1"),
                @NamedQuery(name = "QuestionaireQuestion.findAll", query =
"select e from QuestionaireQuestion e") })
public class QuestionaireQuestion implements Serializable, Comparable {

    /** The Constant serialVersionUID. */
    private static final long serialVersionUID = -9137096316582763142L;

    /** The _title. */
    private String _title = "";

    /** The _create date. */
    private Date _createDate = new Date(System.currentTimeMillis());

    /** The _questionType. */
    private QuestionType _questionType;

    /** The id. */
    private long id;

    /*
     * (non-Javadoc)
     *
     * @see java.lang.Comparable#compareTo(java.lang.Object)
     */
    public int compareTo(Object o) {
        return String.valueOf(this).compareTo(String.valueOf(o));
    }

    /**
     * Gets the id.
     *
     * @return the id
     */
    @Id
    @Column(name = "QUES_ID")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    /**
     * Sets the id.
     *
     * @param id
     *                the new id
     */
    public void setId(long id) {
        this.id = id;
    }

    /**
     * Gets the title.
     *
     * @return the title
     * */
     @Column(name = "TITLE", nullable = false)
     public String getTitle() {
  return _title;
     }
   
    /**
     * Sets the title.
     *
     * @param title
     *                the new title
     */
    @Validate("required")
    public void setTitle(String title) {
        _title = title;
    }

    /**
     * Gets the creates the date.
     *
     * @return the creates the date
     */
    @Column(name = "CREATE_DATE", nullable = false)
    public Date getCreateDate() {
        return _createDate;
    }
   
    /**
     * Sets the creates the date.
     *
     * @param date
     *                the new creates the date
     */
    @Validate("required")
    public void setCreateDate(Date date) {
        _createDate = date;
    }

    /**
     * Gets the question type.
     *
     * @return the question type
     */
    @ManyToOne
    @JoinColumns( { @JoinColumn(name = "TOQ_TOQ_ID", nullable = false) })
    @Basic(fetch = FetchType.LAZY)
    public QuestionType getQuestionType() {
        return _questionType;
    }
   
    /**
     * Sets the question type.
     *
     * @param type
     *                the new question type
     */
    @Validate("required")
    public void setQuestionType(QuestionType type) {
        _questionType = type;
    }

}

My page:

ManageQuestion.java:

package org.cimlvin.web.pages.admin;

import java.util.List;

import org.acegisecurity.annotation.Secured;
import org.apache.tapestry.annotations.Property;
import org.apache.tapestry.annotations.Service;
import org.apache.tapestry.ioc.annotations.Inject;
import org.cimlvin.domain.model.QuestionaireQuestion;
import org.cimlvin.service.QuestionManager;

@Secured("ROLE_ADMIN")
public class ManageQuestions {

        /** The question manager **/
        @Inject
        @Service("QuestionManager")
        private QuestionManager questionMgr;
       
        /** The question **/
        @SuppressWarnings("unused")
        @Property
        private QuestionaireQuestion question;
       

        public List<QuestionaireQuestion> getquestions() {
            return questionMgr.getAllQuestions();
        }
       
       
}


ManageQuestions.tml:

<t:layout
        title="literal:Administration Area - Manage Questions"
        xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
        <div class="post">
        <h2 class="title">Administration Area - Manage Questions</h2>
        <div class="entry">
        <h3>Question List</h3>
        <t:grid t:source="questions" row="question" rowsPerPage="20">
                <t:parameter name="titleCell">
                        <t:pagelink t:page="admin/ManageQuestion"
t:context="question.id">${question.title}</t:pagelink>
                </t:parameter>
                <t:parameter name="questionTypeCell">
                        ${question.questionType.Name}
                </t:parameter>
        </t:grid>
        </div>
        </div>
</t:layout>

So my class has 4 properties, but when I try to see it, I see only 3. grib
shows me id,title and create date. It did show me QuestionType (foreign
key). I don`t understand why..

Thank you. 
-- 
View this message in context: http://www.nabble.com/Tapestry-5%2C-problem-with-foreign-field-tp19161912p19161912.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


RE: Tapestry 5, problem with foreign field

Posted by Jonathan Barker <jo...@gmail.com>.
Skipped right over the Comparable...

I've always had to explicitly columns for related entities.  In the cases
where you have had success without "add", have you implemented Property
Editor Overrides, or anything similar such that Tapestry would know how to
wire it up correctly?



> -----Original Message-----
> From: Artur_eol [mailto:ar.abdullin@gmail.com]
> Sent: Tuesday, August 26, 2008 10:00
> To: users@tapestry.apache.org
> Subject: RE: Tapestry 5, problem with foreign field
> 
> 
> Yes, I understand that, this is my QuestionType Class:
> 
> package org.cimlvin.domain.model;
> 
> import java.io.Serializable;
> 
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.NamedQueries;
> import javax.persistence.NamedQuery;
> import javax.persistence.Table;
> 
> import org.apache.tapestry.beaneditor.Validate;
> 
> // TODO: Auto-generated Javadoc
> /**
>  * The Class QuestionType.
>  */
> @SuppressWarnings("unchecked")
> @Entity
> @Table(name = "TYPE_OF_QUESTIONS")
> @NamedQueries( {
> 	@NamedQuery(name = "QuestionType.findAll", query = "select e from
> QuestionType e"),
> 	@NamedQuery(name = "QuestionType.findByName", query = "select e from
> QuestionType e where e.name = ?1") })
> public class QuestionType implements Serializable, Comparable {
> 
>         /** The Constant serialVersionUID. */
>         private static final long serialVersionUID = 7792762941355197319L;
> 
>         /** The _name. */
>         private String _name = "";
> 
>         /** The _order. */
>         private Integer _order = null;
> 
>         /** The _description. */
>         private String _description = "";
> 
>         /** The id. */
>         private long id;
> 
>         /*
>          * (non-Javadoc)
>          *
>          * @see java.lang.Comparable#compareTo(java.lang.Object)
>          */
>         public int compareTo(Object o) {
>     	return String.valueOf(this).compareTo(String.valueOf(o));
>         }
> 
>         /**
>          * Gets the id.
>          *
>          * @return the id
>          */
>         @Id
>         @Column(name = "TOQ_ID")
>         @GeneratedValue(strategy = GenerationType.AUTO)
>         public Long getId() {
>             return id;
>         }
> 
>         /**
>          * Sets the id.
>          *
>          * @param id
>          *                the new id
>          */
>         public void setId(long id) {
>             this.id = id;
>         }
> 
> 
> 	/**
> 	 * Gets the name.
> 	 *
> 	 * @return the name
> 	 */
> 	@Column(name = "NAME", nullable = false)
> 	public String getName() {
> 	    return _name;
> 	}
> 
>         /**
>          * Sets the name.
>          *
>          * @param name
>          *                the new name
>          */
>         @Validate("required")
>         public void setName(String name) {
>             _name = name;
>         }
> 
>         /**
> 	 * Gets the description.
> 	 *
> 	 * @return the description
> 	 */
> 	@Column(name = "TOQ_DESC", nullable = true)
>         public String getDescription() {
> 	    return _description;
> 	}
> 
> 	/**
>          * Sets the description.
>          *
>          * @param desc
>          *                the new description
>          */
>         public void setDescription(String desc) {
>             _description = desc;
>         }
> 
>         /**
> 	 * Gets the order.
> 	 *
> 	 * @return the order
> 	 */
> 	@Column(name = "TOQ_ORDER", nullable = true)
> 	public Integer getOrder() {
> 		return _order;
> 	}
> 
>         /**
> 	 * Sets the order.
> 	 *
> 	 * @param order
> 	 *            the new order
> 	 */
> 	public void setOrder(Integer order) {
> 		_order = order;
> 	}
> }
> 
> And it is implements Comparable, but still it does not work. Of course I
> can
> use "add", but it should work without it. I have another couples of tables
> with Many2One reference and they work that way, but this one, does not.
> 
> 
> 
> Jonathan Barker wrote:
> >
> > You will need to explicitly add that field to your model.  You should be
> > able to just use add="questionType", or you can provide your own model.
> >
> > If you want your column to be sortable, then supply your own model, and
> > have
> > QuestionType implement Comparable.
> >
> >
> >> -----Original Message-----
> >> From: Artur_eol [mailto:ar.abdullin@gmail.com]
> >> Sent: Tuesday, August 26, 2008 09:20
> >> To: users@tapestry.apache.org
> >> Subject: Tapestry 5, problem with foreign field
> >>
> >>
> >> Hello everybody, I hava problem with foreign key - field. This is my
> Java
> >> class:
> >>
> >> package org.cimlvin.domain.model;
> >>
> >> import java.io.Serializable;
> >> import java.sql.Date;
> >>
> >> import javax.persistence.Basic;
> >> import javax.persistence.Column;
> >> import javax.persistence.Entity;
> >> import javax.persistence.FetchType;
> >> import javax.persistence.GeneratedValue;
> >> import javax.persistence.GenerationType;
> >> import javax.persistence.Id;
> >> import javax.persistence.JoinColumn;
> >> import javax.persistence.JoinColumns;
> >> import javax.persistence.ManyToOne;
> >> import javax.persistence.NamedQueries;
> >> import javax.persistence.NamedQuery;
> >> import javax.persistence.Table;
> >>
> >> import org.apache.tapestry.beaneditor.Validate;
> >>
> >> // TODO: Auto-generated Javadoc
> >> /**
> >>  * The Class QuestionaireQuestion.
> >>  */
> >> @SuppressWarnings("unchecked")
> >> @Entity
> >> @Table(name = "QUESTIONS")
> >> @NamedQueries( {
> >>                 @NamedQuery(name = "QuestionaireQuestion.findByType",
> >> query
> >> = "select e from QuestionaireQuestion e where e.questionType = ?1"),
> >>                 @NamedQuery(name = "QuestionaireQuestion.findByTitle",
> >> query
> >> = "select e from QuestionaireQuestion e where e.title = ?1"),
> >>                 @NamedQuery(name = "QuestionaireQuestion.findById",
> query
> >> =
> >> "select e from QuestionaireQuestion e where e.id = ?1"),
> >>                 @NamedQuery(name = "QuestionaireQuestion.findAll",
> query
> >> =
> >> "select e from QuestionaireQuestion e") })
> >> public class QuestionaireQuestion implements Serializable, Comparable {
> >>
> >>     /** The Constant serialVersionUID. */
> >>     private static final long serialVersionUID = -9137096316582763142L;
> >>
> >>     /** The _title. */
> >>     private String _title = "";
> >>
> >>     /** The _create date. */
> >>     private Date _createDate = new Date(System.currentTimeMillis());
> >>
> >>     /** The _questionType. */
> >>     private QuestionType _questionType;
> >>
> >>     /** The id. */
> >>     private long id;
> >>
> >>     /*
> >>      * (non-Javadoc)
> >>      *
> >>      * @see java.lang.Comparable#compareTo(java.lang.Object)
> >>      */
> >>     public int compareTo(Object o) {
> >>         return String.valueOf(this).compareTo(String.valueOf(o));
> >>     }
> >>
> >>     /**
> >>      * Gets the id.
> >>      *
> >>      * @return the id
> >>      */
> >>     @Id
> >>     @Column(name = "QUES_ID")
> >>     @GeneratedValue(strategy = GenerationType.AUTO)
> >>     public Long getId() {
> >>         return id;
> >>     }
> >>
> >>     /**
> >>      * Sets the id.
> >>      *
> >>      * @param id
> >>      *                the new id
> >>      */
> >>     public void setId(long id) {
> >>         this.id = id;
> >>     }
> >>
> >>     /**
> >>      * Gets the title.
> >>      *
> >>      * @return the title
> >>      * */
> >>      @Column(name = "TITLE", nullable = false)
> >>      public String getTitle() {
> >>   return _title;
> >>      }
> >>
> >>     /**
> >>      * Sets the title.
> >>      *
> >>      * @param title
> >>      *                the new title
> >>      */
> >>     @Validate("required")
> >>     public void setTitle(String title) {
> >>         _title = title;
> >>     }
> >>
> >>     /**
> >>      * Gets the creates the date.
> >>      *
> >>      * @return the creates the date
> >>      */
> >>     @Column(name = "CREATE_DATE", nullable = false)
> >>     public Date getCreateDate() {
> >>         return _createDate;
> >>     }
> >>
> >>     /**
> >>      * Sets the creates the date.
> >>      *
> >>      * @param date
> >>      *                the new creates the date
> >>      */
> >>     @Validate("required")
> >>     public void setCreateDate(Date date) {
> >>         _createDate = date;
> >>     }
> >>
> >>     /**
> >>      * Gets the question type.
> >>      *
> >>      * @return the question type
> >>      */
> >>     @ManyToOne
> >>     @JoinColumns( { @JoinColumn(name = "TOQ_TOQ_ID", nullable = false)
> })
> >>     @Basic(fetch = FetchType.LAZY)
> >>     public QuestionType getQuestionType() {
> >>         return _questionType;
> >>     }
> >>
> >>     /**
> >>      * Sets the question type.
> >>      *
> >>      * @param type
> >>      *                the new question type
> >>      */
> >>     @Validate("required")
> >>     public void setQuestionType(QuestionType type) {
> >>         _questionType = type;
> >>     }
> >>
> >> }
> >>
> >> My page:
> >>
> >> ManageQuestion.java:
> >>
> >> package org.cimlvin.web.pages.admin;
> >>
> >> import java.util.List;
> >>
> >> import org.acegisecurity.annotation.Secured;
> >> import org.apache.tapestry.annotations.Property;
> >> import org.apache.tapestry.annotations.Service;
> >> import org.apache.tapestry.ioc.annotations.Inject;
> >> import org.cimlvin.domain.model.QuestionaireQuestion;
> >> import org.cimlvin.service.QuestionManager;
> >>
> >> @Secured("ROLE_ADMIN")
> >> public class ManageQuestions {
> >>
> >>         /** The question manager **/
> >>         @Inject
> >>         @Service("QuestionManager")
> >>         private QuestionManager questionMgr;
> >>
> >>         /** The question **/
> >>         @SuppressWarnings("unused")
> >>         @Property
> >>         private QuestionaireQuestion question;
> >>
> >>
> >>         public List<QuestionaireQuestion> getquestions() {
> >>             return questionMgr.getAllQuestions();
> >>         }
> >>
> >>
> >> }
> >>
> >>
> >> ManageQuestions.tml:
> >>
> >> <t:layout
> >>         title="literal:Administration Area - Manage Questions"
> >>         xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
> >>         <div class="post">
> >>         <h2 class="title">Administration Area - Manage Questions</h2>
> >>         <div class="entry">
> >>         <h3>Question List</h3>
> >>         <t:grid t:source="questions" row="question" rowsPerPage="20">
> >>                 <t:parameter name="titleCell">
> >>                         <t:pagelink t:page="admin/ManageQuestion"
> >> t:context="question.id">${question.title}</t:pagelink>
> >>                 </t:parameter>
> >>                 <t:parameter name="questionTypeCell">
> >>                         ${question.questionType.Name}
> >>                 </t:parameter>
> >>         </t:grid>
> >>         </div>
> >>         </div>
> >> </t:layout>
> >>
> >> So my class has 4 properties, but when I try to see it, I see only 3.
> >> grib
> >> shows me id,title and create date. It did show me QuestionType (foreign
> >> key). I don`t understand why..
> >>
> >> Thank you.
> >> --
> >> View this message in context:
> >> http://www.nabble.com/Tapestry-5%2C-problem-
> >> with-foreign-field-tp19161912p19161912.html
> >> Sent from the Tapestry - User mailing list archive at Nabble.com.
> >>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
> >
> 
> --
> View this message in context: http://www.nabble.com/Tapestry-5%2C-problem-
> with-foreign-field-tp19161912p19162657.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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


RE: Tapestry 5, problem with foreign field

Posted by Artur_eol <ar...@gmail.com>.
Yes, I understand that, this is my QuestionType Class:

package org.cimlvin.domain.model;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

import org.apache.tapestry.beaneditor.Validate;

// TODO: Auto-generated Javadoc
/**
 * The Class QuestionType.
 */
@SuppressWarnings("unchecked")
@Entity
@Table(name = "TYPE_OF_QUESTIONS")
@NamedQueries( {
	@NamedQuery(name = "QuestionType.findAll", query = "select e from
QuestionType e"),
	@NamedQuery(name = "QuestionType.findByName", query = "select e from
QuestionType e where e.name = ?1") })
public class QuestionType implements Serializable, Comparable {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 7792762941355197319L;
    
        /** The _name. */
        private String _name = "";
    
        /** The _order. */
        private Integer _order = null;
    
        /** The _description. */
        private String _description = "";
    
        /** The id. */
        private long id;
    
        /*
         * (non-Javadoc)
         * 
         * @see java.lang.Comparable#compareTo(java.lang.Object)
         */
        public int compareTo(Object o) {
    	return String.valueOf(this).compareTo(String.valueOf(o));
        }
    
        /**
         * Gets the id.
         * 
         * @return the id
         */
        @Id
        @Column(name = "TOQ_ID")
        @GeneratedValue(strategy = GenerationType.AUTO)
        public Long getId() {
            return id;
        }
       
        /**
         * Sets the id.
         * 
         * @param id
         *                the new id
         */
        public void setId(long id) {
            this.id = id;
        }


	/**
	 * Gets the name.
	 * 
	 * @return the name
	 */
	@Column(name = "NAME", nullable = false)
	public String getName() {
	    return _name;
	}

        /**
         * Sets the name.
         * 
         * @param name
         *                the new name
         */
        @Validate("required")
        public void setName(String name) {
            _name = name;
        }
	
        /**
	 * Gets the description.
	 * 
	 * @return the description
	 */
	@Column(name = "TOQ_DESC", nullable = true)
        public String getDescription() {
	    return _description;
	}
        
	/**
         * Sets the description.
         * 
         * @param desc
         *                the new description
         */
        public void setDescription(String desc) {
            _description = desc;
        }

        /**
	 * Gets the order.
	 * 
	 * @return the order
	 */
	@Column(name = "TOQ_ORDER", nullable = true)
	public Integer getOrder() {
		return _order;
	}
        
        /**
	 * Sets the order.
	 * 
	 * @param order
	 *            the new order
	 */
	public void setOrder(Integer order) {
		_order = order;
	}
}

And it is implements Comparable, but still it does not work. Of course I can
use "add", but it should work without it. I have another couples of tables
with Many2One reference and they work that way, but this one, does not.



Jonathan Barker wrote:
> 
> You will need to explicitly add that field to your model.  You should be
> able to just use add="questionType", or you can provide your own model.
> 
> If you want your column to be sortable, then supply your own model, and
> have
> QuestionType implement Comparable.
> 
> 
>> -----Original Message-----
>> From: Artur_eol [mailto:ar.abdullin@gmail.com]
>> Sent: Tuesday, August 26, 2008 09:20
>> To: users@tapestry.apache.org
>> Subject: Tapestry 5, problem with foreign field
>> 
>> 
>> Hello everybody, I hava problem with foreign key - field. This is my Java
>> class:
>> 
>> package org.cimlvin.domain.model;
>> 
>> import java.io.Serializable;
>> import java.sql.Date;
>> 
>> import javax.persistence.Basic;
>> import javax.persistence.Column;
>> import javax.persistence.Entity;
>> import javax.persistence.FetchType;
>> import javax.persistence.GeneratedValue;
>> import javax.persistence.GenerationType;
>> import javax.persistence.Id;
>> import javax.persistence.JoinColumn;
>> import javax.persistence.JoinColumns;
>> import javax.persistence.ManyToOne;
>> import javax.persistence.NamedQueries;
>> import javax.persistence.NamedQuery;
>> import javax.persistence.Table;
>> 
>> import org.apache.tapestry.beaneditor.Validate;
>> 
>> // TODO: Auto-generated Javadoc
>> /**
>>  * The Class QuestionaireQuestion.
>>  */
>> @SuppressWarnings("unchecked")
>> @Entity
>> @Table(name = "QUESTIONS")
>> @NamedQueries( {
>>                 @NamedQuery(name = "QuestionaireQuestion.findByType",
>> query
>> = "select e from QuestionaireQuestion e where e.questionType = ?1"),
>>                 @NamedQuery(name = "QuestionaireQuestion.findByTitle",
>> query
>> = "select e from QuestionaireQuestion e where e.title = ?1"),
>>                 @NamedQuery(name = "QuestionaireQuestion.findById", query
>> =
>> "select e from QuestionaireQuestion e where e.id = ?1"),
>>                 @NamedQuery(name = "QuestionaireQuestion.findAll", query
>> =
>> "select e from QuestionaireQuestion e") })
>> public class QuestionaireQuestion implements Serializable, Comparable {
>> 
>>     /** The Constant serialVersionUID. */
>>     private static final long serialVersionUID = -9137096316582763142L;
>> 
>>     /** The _title. */
>>     private String _title = "";
>> 
>>     /** The _create date. */
>>     private Date _createDate = new Date(System.currentTimeMillis());
>> 
>>     /** The _questionType. */
>>     private QuestionType _questionType;
>> 
>>     /** The id. */
>>     private long id;
>> 
>>     /*
>>      * (non-Javadoc)
>>      *
>>      * @see java.lang.Comparable#compareTo(java.lang.Object)
>>      */
>>     public int compareTo(Object o) {
>>         return String.valueOf(this).compareTo(String.valueOf(o));
>>     }
>> 
>>     /**
>>      * Gets the id.
>>      *
>>      * @return the id
>>      */
>>     @Id
>>     @Column(name = "QUES_ID")
>>     @GeneratedValue(strategy = GenerationType.AUTO)
>>     public Long getId() {
>>         return id;
>>     }
>> 
>>     /**
>>      * Sets the id.
>>      *
>>      * @param id
>>      *                the new id
>>      */
>>     public void setId(long id) {
>>         this.id = id;
>>     }
>> 
>>     /**
>>      * Gets the title.
>>      *
>>      * @return the title
>>      * */
>>      @Column(name = "TITLE", nullable = false)
>>      public String getTitle() {
>>   return _title;
>>      }
>> 
>>     /**
>>      * Sets the title.
>>      *
>>      * @param title
>>      *                the new title
>>      */
>>     @Validate("required")
>>     public void setTitle(String title) {
>>         _title = title;
>>     }
>> 
>>     /**
>>      * Gets the creates the date.
>>      *
>>      * @return the creates the date
>>      */
>>     @Column(name = "CREATE_DATE", nullable = false)
>>     public Date getCreateDate() {
>>         return _createDate;
>>     }
>> 
>>     /**
>>      * Sets the creates the date.
>>      *
>>      * @param date
>>      *                the new creates the date
>>      */
>>     @Validate("required")
>>     public void setCreateDate(Date date) {
>>         _createDate = date;
>>     }
>> 
>>     /**
>>      * Gets the question type.
>>      *
>>      * @return the question type
>>      */
>>     @ManyToOne
>>     @JoinColumns( { @JoinColumn(name = "TOQ_TOQ_ID", nullable = false) })
>>     @Basic(fetch = FetchType.LAZY)
>>     public QuestionType getQuestionType() {
>>         return _questionType;
>>     }
>> 
>>     /**
>>      * Sets the question type.
>>      *
>>      * @param type
>>      *                the new question type
>>      */
>>     @Validate("required")
>>     public void setQuestionType(QuestionType type) {
>>         _questionType = type;
>>     }
>> 
>> }
>> 
>> My page:
>> 
>> ManageQuestion.java:
>> 
>> package org.cimlvin.web.pages.admin;
>> 
>> import java.util.List;
>> 
>> import org.acegisecurity.annotation.Secured;
>> import org.apache.tapestry.annotations.Property;
>> import org.apache.tapestry.annotations.Service;
>> import org.apache.tapestry.ioc.annotations.Inject;
>> import org.cimlvin.domain.model.QuestionaireQuestion;
>> import org.cimlvin.service.QuestionManager;
>> 
>> @Secured("ROLE_ADMIN")
>> public class ManageQuestions {
>> 
>>         /** The question manager **/
>>         @Inject
>>         @Service("QuestionManager")
>>         private QuestionManager questionMgr;
>> 
>>         /** The question **/
>>         @SuppressWarnings("unused")
>>         @Property
>>         private QuestionaireQuestion question;
>> 
>> 
>>         public List<QuestionaireQuestion> getquestions() {
>>             return questionMgr.getAllQuestions();
>>         }
>> 
>> 
>> }
>> 
>> 
>> ManageQuestions.tml:
>> 
>> <t:layout
>>         title="literal:Administration Area - Manage Questions"
>>         xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>>         <div class="post">
>>         <h2 class="title">Administration Area - Manage Questions</h2>
>>         <div class="entry">
>>         <h3>Question List</h3>
>>         <t:grid t:source="questions" row="question" rowsPerPage="20">
>>                 <t:parameter name="titleCell">
>>                         <t:pagelink t:page="admin/ManageQuestion"
>> t:context="question.id">${question.title}</t:pagelink>
>>                 </t:parameter>
>>                 <t:parameter name="questionTypeCell">
>>                         ${question.questionType.Name}
>>                 </t:parameter>
>>         </t:grid>
>>         </div>
>>         </div>
>> </t:layout>
>> 
>> So my class has 4 properties, but when I try to see it, I see only 3.
>> grib
>> shows me id,title and create date. It did show me QuestionType (foreign
>> key). I don`t understand why..
>> 
>> Thank you.
>> --
>> View this message in context:
>> http://www.nabble.com/Tapestry-5%2C-problem-
>> with-foreign-field-tp19161912p19161912.html
>> Sent from the Tapestry - User mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Tapestry-5%2C-problem-with-foreign-field-tp19161912p19162657.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


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


RE: Tapestry 5, problem with foreign field

Posted by Jonathan Barker <jo...@gmail.com>.
You will need to explicitly add that field to your model.  You should be
able to just use add="questionType", or you can provide your own model.

If you want your column to be sortable, then supply your own model, and have
QuestionType implement Comparable.


> -----Original Message-----
> From: Artur_eol [mailto:ar.abdullin@gmail.com]
> Sent: Tuesday, August 26, 2008 09:20
> To: users@tapestry.apache.org
> Subject: Tapestry 5, problem with foreign field
> 
> 
> Hello everybody, I hava problem with foreign key - field. This is my Java
> class:
> 
> package org.cimlvin.domain.model;
> 
> import java.io.Serializable;
> import java.sql.Date;
> 
> import javax.persistence.Basic;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.FetchType;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.JoinColumn;
> import javax.persistence.JoinColumns;
> import javax.persistence.ManyToOne;
> import javax.persistence.NamedQueries;
> import javax.persistence.NamedQuery;
> import javax.persistence.Table;
> 
> import org.apache.tapestry.beaneditor.Validate;
> 
> // TODO: Auto-generated Javadoc
> /**
>  * The Class QuestionaireQuestion.
>  */
> @SuppressWarnings("unchecked")
> @Entity
> @Table(name = "QUESTIONS")
> @NamedQueries( {
>                 @NamedQuery(name = "QuestionaireQuestion.findByType",
> query
> = "select e from QuestionaireQuestion e where e.questionType = ?1"),
>                 @NamedQuery(name = "QuestionaireQuestion.findByTitle",
> query
> = "select e from QuestionaireQuestion e where e.title = ?1"),
>                 @NamedQuery(name = "QuestionaireQuestion.findById", query
> =
> "select e from QuestionaireQuestion e where e.id = ?1"),
>                 @NamedQuery(name = "QuestionaireQuestion.findAll", query =
> "select e from QuestionaireQuestion e") })
> public class QuestionaireQuestion implements Serializable, Comparable {
> 
>     /** The Constant serialVersionUID. */
>     private static final long serialVersionUID = -9137096316582763142L;
> 
>     /** The _title. */
>     private String _title = "";
> 
>     /** The _create date. */
>     private Date _createDate = new Date(System.currentTimeMillis());
> 
>     /** The _questionType. */
>     private QuestionType _questionType;
> 
>     /** The id. */
>     private long id;
> 
>     /*
>      * (non-Javadoc)
>      *
>      * @see java.lang.Comparable#compareTo(java.lang.Object)
>      */
>     public int compareTo(Object o) {
>         return String.valueOf(this).compareTo(String.valueOf(o));
>     }
> 
>     /**
>      * Gets the id.
>      *
>      * @return the id
>      */
>     @Id
>     @Column(name = "QUES_ID")
>     @GeneratedValue(strategy = GenerationType.AUTO)
>     public Long getId() {
>         return id;
>     }
> 
>     /**
>      * Sets the id.
>      *
>      * @param id
>      *                the new id
>      */
>     public void setId(long id) {
>         this.id = id;
>     }
> 
>     /**
>      * Gets the title.
>      *
>      * @return the title
>      * */
>      @Column(name = "TITLE", nullable = false)
>      public String getTitle() {
>   return _title;
>      }
> 
>     /**
>      * Sets the title.
>      *
>      * @param title
>      *                the new title
>      */
>     @Validate("required")
>     public void setTitle(String title) {
>         _title = title;
>     }
> 
>     /**
>      * Gets the creates the date.
>      *
>      * @return the creates the date
>      */
>     @Column(name = "CREATE_DATE", nullable = false)
>     public Date getCreateDate() {
>         return _createDate;
>     }
> 
>     /**
>      * Sets the creates the date.
>      *
>      * @param date
>      *                the new creates the date
>      */
>     @Validate("required")
>     public void setCreateDate(Date date) {
>         _createDate = date;
>     }
> 
>     /**
>      * Gets the question type.
>      *
>      * @return the question type
>      */
>     @ManyToOne
>     @JoinColumns( { @JoinColumn(name = "TOQ_TOQ_ID", nullable = false) })
>     @Basic(fetch = FetchType.LAZY)
>     public QuestionType getQuestionType() {
>         return _questionType;
>     }
> 
>     /**
>      * Sets the question type.
>      *
>      * @param type
>      *                the new question type
>      */
>     @Validate("required")
>     public void setQuestionType(QuestionType type) {
>         _questionType = type;
>     }
> 
> }
> 
> My page:
> 
> ManageQuestion.java:
> 
> package org.cimlvin.web.pages.admin;
> 
> import java.util.List;
> 
> import org.acegisecurity.annotation.Secured;
> import org.apache.tapestry.annotations.Property;
> import org.apache.tapestry.annotations.Service;
> import org.apache.tapestry.ioc.annotations.Inject;
> import org.cimlvin.domain.model.QuestionaireQuestion;
> import org.cimlvin.service.QuestionManager;
> 
> @Secured("ROLE_ADMIN")
> public class ManageQuestions {
> 
>         /** The question manager **/
>         @Inject
>         @Service("QuestionManager")
>         private QuestionManager questionMgr;
> 
>         /** The question **/
>         @SuppressWarnings("unused")
>         @Property
>         private QuestionaireQuestion question;
> 
> 
>         public List<QuestionaireQuestion> getquestions() {
>             return questionMgr.getAllQuestions();
>         }
> 
> 
> }
> 
> 
> ManageQuestions.tml:
> 
> <t:layout
>         title="literal:Administration Area - Manage Questions"
>         xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd">
>         <div class="post">
>         <h2 class="title">Administration Area - Manage Questions</h2>
>         <div class="entry">
>         <h3>Question List</h3>
>         <t:grid t:source="questions" row="question" rowsPerPage="20">
>                 <t:parameter name="titleCell">
>                         <t:pagelink t:page="admin/ManageQuestion"
> t:context="question.id">${question.title}</t:pagelink>
>                 </t:parameter>
>                 <t:parameter name="questionTypeCell">
>                         ${question.questionType.Name}
>                 </t:parameter>
>         </t:grid>
>         </div>
>         </div>
> </t:layout>
> 
> So my class has 4 properties, but when I try to see it, I see only 3. grib
> shows me id,title and create date. It did show me QuestionType (foreign
> key). I don`t understand why..
> 
> Thank you.
> --
> View this message in context: http://www.nabble.com/Tapestry-5%2C-problem-
> with-foreign-field-tp19161912p19161912.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org


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