You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "dragan.sahpaskix@gmail.com" <dr...@gmail.com> on 2011/06/13 18:28:02 UTC

Re: onPrepare(Integer id)

Hi,
You are not missing anything.

Insert an onPrepare() with no arguments.
tapestry will not call onPrepare(Integer officeId) with null for officeId.

Cheers,
Dragan Sahpaski



On Mon, Jun 13, 2011 at 5:54 PM, Tony Nelson <tn...@starpoint.com> wrote:

> I'm trying to create a simple form that will work for both Add and Edit.
>  I'm trying to use onPrepare to setup the database object and the code works
> fine for an existing object.  When I try to use the form with a new object
> (id = null) it appears that onPrepare isn't called, so I end up with null
> pointer exceptions trying to build the form.
>
> Here is my simple controller:
>
> package com.starpoint.helpdesk.pages.office;
>
> import com.starpoint.helpdesk.business.OfficeLogic;
> import com.starpoint.helpdesk.domain.Office;
> import com.sun.istack.internal.Nullable;
> import org.apache.tapestry5.annotations.Log;
> import org.apache.tapestry5.annotations.Persist;
> import org.apache.tapestry5.annotations.Property;
> import org.apache.tapestry5.ioc.annotations.Inject;
> import org.slf4j.Logger;
>
>
> /**
>  */
> public class EditOffice {
>
>    @Inject
>    private Logger logger;
>
>    @Inject
>    private OfficeLogic officeLogic;
>
>    @Persist
>    private Integer officeId;
>
>    @Property
>    private Office office;
>
>    public Integer getOfficeId() {
>        return officeId;
>    }
>
>    @Log
>    public void setOfficeId(@Nullable Integer officeId) {
>        this.officeId = officeId;
>    }
>
>    @Log
>    void onPrepare(Integer officeId) {
>        if (office == null) {
>            office = officeId == null ? new Office() :
> officeLogic.getOffice(officeId);
>        }
>    }
>    void onActivate(Integer officeId) {
>        this.officeId = officeId;
>    }
>
>    Integer onPassivate() {
>        return officeId;
>    }
>
>    public Object onSuccess() {
>        logger.info("**************: " + office.toString());
>        return this;
>    }
> }
>
>
> And my form:
>
> <html t:type="layout" title="helpdesk Index"
>      t:sidebarTitle="Current Time"
>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>      xmlns:p="tapestry:parameter">
>
> <t:form t:id="editOfficeForm" t:context="officeId">
>    <t:errors/>
>    <table>
>        <tr>
>            <td><t:label for="officeName">Office Name</t:label></td>
>            <td><t:textfield t:id="officeName"
> value="prop:office.officeName"></t:textfield></td>
>        </tr>
>
>        <tr>
>            <td colspan="2">
>                <t:submit t:id="saveOffice" class="button">Save
> Office</t:submit>
>            </td>
>        </tr>
>    </table>
>
> </t:form>
>
> </html>
>
> What am I missing?
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>