You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by nhhockeyplayer nashua <nh...@hotmail.com> on 2014/12/01 05:17:02 UTC

tapestry-routing cannot show on cancel CRUD

Folks,

Using extended tapestry crud on beta-22

I have a simple model object called Year.JAVA... it implements a startYear and endYear... nothing major see below.

I didnt create any custom edit/add/show/collection pages for this. So it fits into the same framework as-is.

I got a standard Edit.JAVA which implements tapestry-routing... see below... nothing customized... this is as-is too

Everything works... except for CANCEL... it gets lost in never never land.

Everytime I ADD or EDIT with a subsequent CANCEL, it is suppose to go back to the Show.JAVA an dinstead it goes off to some ... well it takes the ROUTE atop the edit page for that model and operates that instead of operating the ROUTE to get back to the Show.JAVA page

First I do a show on the model with Show.JAVA page

url processed for this is as follows
"/psi/show/year/1"

I open up a year model into edit page and the url is as follows
"/psi/edit/year/1"

the problem is in this cancel() routine... below

then I attempt a cancel with logic below HOPING I will be brought back to the Show.JAVA page

@At("/{0}/{1}/edit")

    @OnEvent("cancel")
    Link cancel() {
        return pageRenderLinkSource.createPageRenderLinkWithContext(Show.class, passivate());
    }

after this is executed on the Year.JAVA model my REST url is as follows
"/psi/year/1"

when I am suppose to get
"/psi/show/year/1"

I am unable to debug this.. any hints ? Appreciate any help

Best regards 
and thanks... KEN

package org.tynamo.examples.psi.pages;

import org.apache.tapestry5.EventConstants;
import org.apache.tapestry5.Link;
import org.apache.tapestry5.annotations.CleanupRender;
import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.hibernate.annotations.CommitAfter;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.services.ContextValueEncoder;
import org.apache.tapestry5.services.PageRenderLinkSource;
import org.tynamo.routing.annotations.At;
import org.tynamo.services.PersistenceService;
import org.tynamo.util.TynamoMessages;
import org.tynamo.util.Utils;

@At("/{0}/{1}/edit")
public class Edit {
    @Inject
    private ContextValueEncoder contextValueEncoder;

    @Inject
    private Messages messages;

    @Inject
    private PersistenceService persitenceService;

    @Inject
    private PageRenderLinkSource pageRenderLinkSource;

    @Property(write = false)
    private Class beanType;

    @Property
    private Object bean;

    @OnEvent(EventConstants.ACTIVATE)
    Object activate(Class clazz, String id) {

        if (clazz == null)
            return Utils.new404(messages);

        this.bean = contextValueEncoder.toValue(clazz, id);
        this.beanType = clazz;

        if (bean == null)
            return Utils.new404(messages);

        return null;
    }

    @CleanupRender
    void cleanup() {
        bean = null;
        beanType = null;
    }

    /**
     * This tells Tapestry to put type & id into the URL, making it
     * bookmarkable.
     */
    @OnEvent(EventConstants.PASSIVATE)
    Object[] passivate() {
        return new Object[] { beanType, bean };
    }

    @Log
    @CommitAfter
    @OnEvent(EventConstants.SUCCESS)
    Link success() {
        persitenceService.save(bean);
        return cancel();
    }

    @OnEvent("cancel")
    Link cancel() {
        return pageRenderLinkSource.createPageRenderLinkWithContext(Show.class,
               passivate());
        //return pageRenderLinkSource.createPageRenderLinkWithContext(List.class,
        //        beanType);
    }

    public String getListAllLinkMessage() {
        return TynamoMessages.listAll(messages, beanType);
    }

    public String getTitle() {
        return TynamoMessages.edit(messages, beanType);
    }

}


@Entity
@ClassDescriptor(hasCyclicRelationships = true, nonVisual = false)
public class Year implements Cloneable, Serializable {
    private static final Log log = LogFactory.getLog(Year.class);

    private Integer id = null;

    private Integer yearStart = new Integer("0");

    private Integer yearEnd = new Integer("0");
    
    private League league = null;

    private Long created = new Long(GregorianCalendar.getInstance()
            .getTimeInMillis());

    private Long accessed = new Long(GregorianCalendar.getInstance()
            .getTimeInMillis());

    /**
     * CTOR
     */

    public Year() {
    }

    public Year(Year dto) {
        try {
            BeanUtils.copyProperties(this, dto);
        } catch (Exception e) {
            log.error(e.toString());
            e.printStackTrace();
        }
    }

    /**
     * Accessor for id
     * 
     * @return Integer
     * @hibernate.id generator-class="increment" unsaved-value="-1"
     *               type="java.lang.Integer" unique="true" insert="true"
     */
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @PropertyDescriptor(readOnly = true)
    public Integer getId() {
        return id;
    }

    @PropertyDescriptor
    public Integer getYearStart() {
        return yearStart;
    }

    @PropertyDescriptor
    public Integer getYearEnd() {
        return yearEnd;
    }

    @ManyToOne
    public League getLeague() {
        return league;
    }

    @PropertyDescriptor(nonVisual = true, searchable = false)
    public Long getCreated() {
        return created;
    }

    @PropertyDescriptor(nonVisual = true, searchable = false)
    public Long getAccessed() {
        return accessed;
    }

    @Transient
    @PropertyDescriptor(nonVisual = true, searchable = false)
    public String getCreatedAsString() {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(created.longValue());
        return DatePattern.sdf.format(cal.getTime());
    }

    @Transient
    @PropertyDescriptor(nonVisual = true, searchable = false)
    public String getAccessedAsString() {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(accessed.longValue());
        return DatePattern.sdf.format(cal.getTime());
    }

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

    public void setYearStart(Integer yearStart) {
        this.yearStart = yearStart;
    }

    public void setYearEnd(Integer yearEnd) {
        this.yearEnd = yearEnd;
    }

    public void setLeague(League league) {
        this.league = league;
    }

    @Transient
    @PropertyDescriptor(nonVisual = true, searchable = false)
    public void setCreatedAsString(String value) throws Exception {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime());
        this.created = new Long(cal.getTimeInMillis());
    }

    @Transient
    @PropertyDescriptor(nonVisual = true, searchable = false)
    public void setAccessedAsString(String value) throws Exception {
        Calendar cal = new GregorianCalendar();
        cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime());
        this.accessed = new Long(cal.getTimeInMillis());
    }

    public void setAccessed(Long accessed) {
        this.accessed = accessed;
    }

    public void setCreated(Long created) {
        this.created = created;
    }

    @Override
    public int hashCode() {
        return (getId() != null ? getId().hashCode() : 0);
    }

    @Override
    public Year clone() {
        return new Year(this);
    }

    /**
     * equals and hashCode need to be hammered out for hibernate to work
     * properly
     * 
     * Check the matrix summary for best practices at
     * http://www.hibernate.org/109.html
     */
    @Override
    public boolean equals(Object rhs) {
        if (this == rhs)
            return true; // instance equality
        if (rhs == null || getClass() != rhs.getClass())
            return false; // null/class equality

        final Year castedObject = (Year) rhs;

        return !(getId() != null ? !getId().equals(castedObject.getId())
                : castedObject.getId() != null);
    }

    public String toString() {
        return getYearStart().toString() + "/" + getYearEnd().toString();
    }
}