Hi,

I'm trying to use http://wiki.apache.org/tapestry/Tapestry5HowtoSelectWithObjects to create a selection for my Goal objects.

In the component I've got code

    @Inject
    private PropertyAccess _access;


    public GenericSelectModel<Goal> getGoalModel()
    {
_goalModel = new GenericSelectModel<Goal>(user.getGoals(), Goal.class, "name", "id", _access);
        return _goalModel;
    }

And in the TML
<input t:type="Select" type="text" t:id="goalId" t:value="goal" t:model="goalModel" t:encoder="goalModel"/>

But when I access the page I get:

Render queue error in BeforeRenderTemplate[Index:lygactionplan.goalid]: Error reading property 'id' of com.liftyourgame.application.entities.g...@40ff24: object is not an instance of declaring class.

Any ideas on what I might be doing wrong? It would be so nice if Tapestry handled selects of objects all by itself within the framework.

Thanks.


Goal.java:
package com.liftyourgame.application.entities;

import java.io.Serializable;
import java.util.Date;
import java.util.Iterator;
import java.util.SortedSet;

import javax.persistence.*;

import org.apache.tapestry5.beaneditor.NonVisual;
import org.apache.tapestry5.beaneditor.Validate;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.Sort;
import org.hibernate.annotations.SortType;
import org.hibernate.annotations.Where;



@Entity
@Table(name = "goals")
public class Goal extends LygEntity implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -1935356898924192713L;

    public Goal()
    {

    }

    private Long id;

@SequenceGenerator(name="goals_goal_id_seq", sequenceName="goals_goal_id_seq")
    @Id
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="goals_goal_id_seq")
    @Column(name = "goal_id", unique = true, nullable = false)
    @NonVisual
    public Long getId() {
        return id;
    }

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

    private String goalName;
    private String goalDescription;
    private Date targetDate;
    private GoalCategory goalCategory;

//    @ManyToOne
//    @JoinColumn(name="user_id", nullable=false)
    private User user;

    @Column(name="goal_name")
    @Validate("required")
    public String getGoalName() {
        return goalName;
    }

    public void setGoalName(String goalName) {
        this.goalName = goalName;
    }

    @Column(name="goal_category")
    @Validate("required")
    public GoalCategory getGoalCategory() {
        return goalCategory;
    }

    public void setGoalCategory(GoalCategory goalCategory) {
        this.goalCategory = goalCategory;
    }

    @Column(name="target_date")
    @Validate("required")
    public Date getTargetDate() {
        return targetDate;
    }

    public void setTargetDate(Date targetDate) {
        this.targetDate = targetDate;
    }

    @ManyToOne
    // 1. The owning side
    //@JoinColumn(name="user_id", nullable=false)
    // 2. Reverse relationship owner
    @JoinColumn(name="user_id", updatable = false, insertable=false)
    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    private SortedSet<Action> actions;

    @OneToMany(fetch = FetchType.EAGER)
    @Fetch(FetchMode.SELECT)
    @OrderBy("targetDate")
    @JoinColumn(name="goal_id")
    @Where(clause = "deletiondate is null")
    @Sort(type=SortType.NATURAL)
    public SortedSet<Action> getActions() {
        return actions;
    }

    public void setActions(SortedSet<Action> actions) {
        this.actions = actions;
    }

    @Transient
    public long getDaysLeft()
    {
        Date endDt = getTargetDate();
        Date today = new Date();
        if (endDt == null)
        {
            return 0;
        }
return (long) ((endDt.getTime() - today.getTime())/(24.0*3600.0*1000.0));
    }

    @Transient
    public double getActualPctComplete()
    {
        if (actions.size() == 0)
        {
            return 0.0;
        }

        double numComplete = 0;

        Date now = new Date();
        Iterator<Action> it = actions.iterator();
        while(it.hasNext())
        {
            Action step = it.next();
            if (step.getActualDate() != null)
            {
                if (!step.getActualDate().after(now))
                {
                    numComplete++;
                }
            }
        }

        return numComplete / actions.size() * 100.0;
    }

    @Transient
    public double getTargetPctComplete()
    {
        if (actions.size() == 0)
        {
            return 0.0;
        }

        double numComplete = 0;

        Date now = new Date();

        Iterator<Action> it = actions.iterator();
        while(it.hasNext())
        {
            Action step = it.next();
            if (step.getTargetDate() != null)
            {
                if (!step.getTargetDate().after(now))
                {
                    numComplete++;
                }
            }
        }

        return numComplete / actions.size() * 100.0;
    }

    @Transient
    public String getGoalStatus()
    {
/*        if(getDaysLeft()<=0)
        {
            return "Late";
        }*/

        if(getActions().size()==0)
        {
            return "Do Plan";
        }

        if (getTargetDate() == null)
        {
            return "Warning";
        }

        Date now = new Date();
        if (!getTargetDate().after(now))
        {
            return "Late";
        }

        if (getActualPctComplete() < getTargetPctComplete())
        {
            return "Warning";
        }

        return "OnTarget";
    }

    @Column(name="goal_description")
    public String getGoalDescription() {
        return goalDescription;
    }

    public void setGoalDescription(String goalDescription) {
        this.goalDescription = goalDescription;
    }

    @Transient
    public Action getNextAction()
    {
        Action nextAction = null;

        Iterator<Action> it = actions.iterator();
        while(it.hasNext())
        {
            Action step = it.next();
            if (step.getTargetDate() != null && step.getActualDate()==null)
            {
                if(nextAction == null)
                {
                    nextAction = step;
                }
else if (step.getTargetDate().before(nextAction.getTargetDate()))
                {
                    nextAction = step;
                }
            }
        }

        return nextAction;
    }

}




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

Reply via email to