You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Josh Kamau <jo...@gmail.com> on 2010/11/08 13:52:21 UTC

Passing an object from one page to another

I am trying to pass an object from one page (a page with a grid) to another
page (the page with BeanDisplay).

I know am making a silly mistake somewhere but i have spent 2 hours on it
and i still cant figure out the issue.

Here is the page with the grid

<html t:type="layout" t:title="Show all contacts"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
      xmlns:p="tapestry:parameter">


      <div class="span-6">
          <div t:type="menu"/>
      </div>

      <div class="span-16">
              <table  t:type="grid" t:source="contacts" t:row="contact"
t:add="Actions">
                  <p:actionscell>
                       <t:actionlink t:id="delete" t:context="contact.id
">delete</t:actionlink>|
                       <t:actionlink t:id="view" t:context="contact.id
">view</t:actionlink>
                  </p:actionscell>
              </table>
      </div>

</html>

public class ShowAll {

    @Inject
    private Dao dao ;

    @Property
    private Contact contact ;

    @InjectPage
    private ViewContact viewContact ;

    public List<Contact> getContacts(){
        return dao.getAll();
    }

    @OnEvent(value="action", component="delete")
    private void deleteContact(Long id){
        dao.delete(id, Contact.class);
    }

    @OnEvent(value="action", component="view")
    private Object viewContact(Long id){
        Contact contact = dao.getById(id, Contact.class);
        viewContact.setContact(contact);
        return viewContact ;
    }

}


The view page

<html t:type="layout" t:title="Show all contacts"
      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
      xmlns:p="tapestry:parameter">

      <div class="span-6">
          <t:menu title="Viewing Contact"/>
      </div>

      <div class="span-16">
          <t:beandisplay object="contact"/>
      </div>

</html>

package com.josh.addressbook.pages;

import com.josh.addressbook.entities.Contact;

public class ViewContact {


    private Contact contact  ;

    public Contact getContact() {
        return contact;
    }

    public void setContact(Contact contact) {
        this.contact = contact;
    }


}


Error message

An unexpected application exception has occurred.

   - org.apache.tapestry5.internal.services.RenderQueueException
   Render queue error in SetupRender[ViewContact:beandisplay]: Parameter
   'object' of component ViewContact:beandisplay is bound to null. This
   parameter is not allowed to be null.
   activeComponents
      - ViewContact (class com.josh.addressbook.pages.ViewContact)
      - ViewContact:layout (class com.josh.addressbook.components.Layout)
      classpath:com/josh/addressbook/pages/ViewContact.tml, line 31<html
      t:type="layout" t:title="Show all contacts"2 xmlns:t="
      http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"3xmlns:p="tapestry:parameter">
      4
      5 <div class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
      - ViewContact:beandisplay (class
      org.apache.tapestry5.corelib.components.BeanDisplay)
      classpath:com/josh/addressbook/pages/ViewContact.tml, line 105 <div
      class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
      9 <div class="span-16">10 <t:beandisplay object="contact"/>11 </div>12
      13</html>
   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line 10
   - org.apache.tapestry5.ioc.internal.util.TapestryException
   Parameter 'object' of component ViewContact:beandisplay is bound to null.
   This parameter is not allowed to be null.
   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line 10Hide
   uninteresting stack frames Stack trace
      - org.apache.tapestry5.internal.transform.ParameterWorker$2$1.readFromBinding(ParameterWorker.java:328)

      - org.apache.tapestry5.internal.transform.ParameterWorker$2$1.get(ParameterWorker.java:413)

      - org.apache.tapestry5.corelib.components.BeanDisplay._$get_object(BeanDisplay.java)

      - org.apache.tapestry5.corelib.components.BeanDisplay.setupRender(BeanDisplay.java:128)

      - org.apache.tapestry5.corelib.components.BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.invoke(BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.java)

      -
      org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderP

Re: Passing an object from one page to another

Posted by françois facon <fr...@gmail.com>.
in your sample you need a
@Persist("flash")
private Contact contact  ;

in your view contact

But using activate passivate would be smarter.

To  complete Stephan advice
I suggest to read also activate passivate sample
http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/navigation/onactivateandonpassivate/3

You will need to replace your actionlink by an pagelink with the same
t:context="contact.id

and add the following code to the your view contact

	private Long _Id;
	

	
	// The code
	// onPassivate() is called by Tapestry to get the activation context
to put in the URL.

	Long onPassivate() {
		return _Id;
	}

	// onActivate() is called by Tapestry to pass in the activation
context from the URL.
        void onActivate(Long Id) {
		_Id = Id;
	}

	// setupRender() is called by tapestry at the start of rendering -
it's good for things that are display only.

	void setupRender() throws Exception {
		// Convert the id into a Person.
		contact = dao.getById(_Id, Contact.class);
	}




2010/11/8 Stephan Windmüller <st...@tu-dortmund.de>

> On 08.11.2010 13:52, Josh Kamau wrote:
>
> > I am trying to pass an object from one page (a page with a grid) to
> another
> > page (the page with BeanDisplay).
>
> Perhaps you should take a closer look into JumpStart, since it covers
> many basic Tapestry concepts:
>
> http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/
>
> Your question is answered here:
>
>
> http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/state/passingdatabetweenpages1
>
> HTH
>  Stephan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Passing an object from one page to another

Posted by Stephan Windmüller <st...@tu-dortmund.de>.
On 08.11.2010 13:52, Josh Kamau wrote:

> I am trying to pass an object from one page (a page with a grid) to another
> page (the page with BeanDisplay).

Perhaps you should take a closer look into JumpStart, since it covers
many basic Tapestry concepts:

http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/

Your question is answered here:

http://jumpstart.doublenegative.com.au:8080/jumpstart/examples/state/passingdatabetweenpages1

HTH
 Stephan

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


Re: Passing an object from one page to another

Posted by Taha Hafeez <ta...@gmail.com>.
Thanks for correcting, ... I had read it but forgotten !!!

regards
Taha


On Mon, Nov 8, 2010 at 6:44 PM, Thiago H. de Paula Figueiredo <
thiagohp@gmail.com> wrote:

> On Mon, 08 Nov 2010 10:57:33 -0200, Taha Hafeez <ta...@gmail.com>
> wrote:
>
>  Use onActivate() onPassivate() in ViewContact Page.
>> As pages are pooled in tapestry, they don't remember what was in them
>>
>
> +1 to Taha's suggestion, just the explanation isn't quite correct. Pages in
> Tapestry aren't pooled since 5.2. The cause of the apparent loss of
> information is Tapestry using redirect-after-post in form submits and event
> requests. This way, the action request returns a redirection for the
> ViewContact page.
>
> --
> Thiago H. de Paula Figueiredo
> Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,
> and instructor
> Owner, Ars Machina Tecnologia da Informação Ltda.
> http://www.arsmachina.com.br
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Passing an object from one page to another

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Mon, 08 Nov 2010 10:57:33 -0200, Taha Hafeez <ta...@gmail.com>  
wrote:

> Use onActivate() onPassivate() in ViewContact Page.
> As pages are pooled in tapestry, they don't remember what was in them

+1 to Taha's suggestion, just the explanation isn't quite correct. Pages  
in Tapestry aren't pooled since 5.2. The cause of the apparent loss of  
information is Tapestry using redirect-after-post in form submits and  
event requests. This way, the action request returns a redirection for the  
ViewContact page.

-- 
Thiago H. de Paula Figueiredo
Independent Java, Apache Tapestry 5 and Hibernate consultant, developer,  
and instructor
Owner, Ars Machina Tecnologia da Informação Ltda.
http://www.arsmachina.com.br

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


Re: Passing an object from one page to another

Posted by Taha Hafeez <ta...@gmail.com>.
My mailbox is

Josh
Josh
Josh
Josh
Josh
...
Josh
...
Josh

Just Joking :)

taha


On Mon, Nov 8, 2010 at 6:27 PM, Taha Hafeez <ta...@gmail.com>wrote:

> Use onActivate() onPassivate() in ViewContact Page.
> As pages are pooled in tapestry, they don't remember what was in them
>
> You may also use @Persist on field contact in ShowAll page
>
> regards
> Taha
>
>
>
> On Mon, Nov 8, 2010 at 6:22 PM, Josh Kamau <jo...@gmail.com> wrote:
>
>> I am trying to pass an object from one page (a page with a grid) to
>> another
>> page (the page with BeanDisplay).
>>
>> I know am making a silly mistake somewhere but i have spent 2 hours on it
>> and i still cant figure out the issue.
>>
>> Here is the page with the grid
>>
>> <html t:type="layout" t:title="Show all contacts"
>>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>>      xmlns:p="tapestry:parameter">
>>
>>
>>      <div class="span-6">
>>          <div t:type="menu"/>
>>      </div>
>>
>>      <div class="span-16">
>>              <table  t:type="grid" t:source="contacts" t:row="contact"
>> t:add="Actions">
>>                  <p:actionscell>
>>                       <t:actionlink t:id="delete" t:context="contact.id
>> ">delete</t:actionlink>|
>>                       <t:actionlink t:id="view" t:context="contact.id
>> ">view</t:actionlink>
>>                  </p:actionscell>
>>              </table>
>>      </div>
>>
>> </html>
>>
>> public class ShowAll {
>>
>>    @Inject
>>    private Dao dao ;
>>
>>    @Property
>>    private Contact contact ;
>>
>>    @InjectPage
>>    private ViewContact viewContact ;
>>
>>    public List<Contact> getContacts(){
>>        return dao.getAll();
>>    }
>>
>>    @OnEvent(value="action", component="delete")
>>    private void deleteContact(Long id){
>>        dao.delete(id, Contact.class);
>>    }
>>
>>    @OnEvent(value="action", component="view")
>>    private Object viewContact(Long id){
>>        Contact contact = dao.getById(id, Contact.class);
>>        viewContact.setContact(contact);
>>        return viewContact ;
>>    }
>>
>> }
>>
>>
>> The view page
>>
>> <html t:type="layout" t:title="Show all contacts"
>>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>>      xmlns:p="tapestry:parameter">
>>
>>      <div class="span-6">
>>          <t:menu title="Viewing Contact"/>
>>      </div>
>>
>>      <div class="span-16">
>>          <t:beandisplay object="contact"/>
>>      </div>
>>
>> </html>
>>
>> package com.josh.addressbook.pages;
>>
>> import com.josh.addressbook.entities.Contact;
>>
>> public class ViewContact {
>>
>>
>>    private Contact contact  ;
>>
>>    public Contact getContact() {
>>        return contact;
>>    }
>>
>>    public void setContact(Contact contact) {
>>        this.contact = contact;
>>    }
>>
>>
>> }
>>
>>
>> Error message
>>
>> An unexpected application exception has occurred.
>>
>>   - org.apache.tapestry5.internal.services.RenderQueueException
>>   Render queue error in SetupRender[ViewContact:beandisplay]: Parameter
>>   'object' of component ViewContact:beandisplay is bound to null. This
>>   parameter is not allowed to be null.
>>   activeComponents
>>      - ViewContact (class com.josh.addressbook.pages.ViewContact)
>>      - ViewContact:layout (class com.josh.addressbook.components.Layout)
>>      classpath:com/josh/addressbook/pages/ViewContact.tml, line 31<html
>>      t:type="layout" t:title="Show all contacts"2 xmlns:t="
>>      http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
>> "3xmlns:p="tapestry:parameter">
>>      4
>>      5 <div class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
>>      - ViewContact:beandisplay (class
>>      org.apache.tapestry5.corelib.components.BeanDisplay)
>>      classpath:com/josh/addressbook/pages/ViewContact.tml, line 105 <div
>>      class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
>>      9 <div class="span-16">10 <t:beandisplay object="contact"/>11
>> </div>12
>>      13</html>
>>   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line 10
>>   - org.apache.tapestry5.ioc.internal.util.TapestryException
>>   Parameter 'object' of component ViewContact:beandisplay is bound to
>> null.
>>   This parameter is not allowed to be null.
>>   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line
>> 10Hide
>>   uninteresting stack frames Stack trace
>>      -
>> org.apache.tapestry5.internal.transform.ParameterWorker$2$1.readFromBinding(ParameterWorker.java:328)
>>
>>      -
>> org.apache.tapestry5.internal.transform.ParameterWorker$2$1.get(ParameterWorker.java:413)
>>
>>      -
>> org.apache.tapestry5.corelib.components.BeanDisplay._$get_object(BeanDisplay.java)
>>
>>      -
>> org.apache.tapestry5.corelib.components.BeanDisplay.setupRender(BeanDisplay.java:128)
>>
>>      -
>> org.apache.tapestry5.corelib.components.BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.invoke(BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.java)
>>
>>      -
>>
>>  org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderP
>>
>
>

Re: Passing an object from one page to another

Posted by Taha Hafeez <ta...@gmail.com>.
Use onActivate() onPassivate() in ViewContact Page.
As pages are pooled in tapestry, they don't remember what was in them

You may also use @Persist on field contact in ShowAll page

regards
Taha


On Mon, Nov 8, 2010 at 6:22 PM, Josh Kamau <jo...@gmail.com> wrote:

> I am trying to pass an object from one page (a page with a grid) to another
> page (the page with BeanDisplay).
>
> I know am making a silly mistake somewhere but i have spent 2 hours on it
> and i still cant figure out the issue.
>
> Here is the page with the grid
>
> <html t:type="layout" t:title="Show all contacts"
>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>      xmlns:p="tapestry:parameter">
>
>
>      <div class="span-6">
>          <div t:type="menu"/>
>      </div>
>
>      <div class="span-16">
>              <table  t:type="grid" t:source="contacts" t:row="contact"
> t:add="Actions">
>                  <p:actionscell>
>                       <t:actionlink t:id="delete" t:context="contact.id
> ">delete</t:actionlink>|
>                       <t:actionlink t:id="view" t:context="contact.id
> ">view</t:actionlink>
>                  </p:actionscell>
>              </table>
>      </div>
>
> </html>
>
> public class ShowAll {
>
>    @Inject
>    private Dao dao ;
>
>    @Property
>    private Contact contact ;
>
>    @InjectPage
>    private ViewContact viewContact ;
>
>    public List<Contact> getContacts(){
>        return dao.getAll();
>    }
>
>    @OnEvent(value="action", component="delete")
>    private void deleteContact(Long id){
>        dao.delete(id, Contact.class);
>    }
>
>    @OnEvent(value="action", component="view")
>    private Object viewContact(Long id){
>        Contact contact = dao.getById(id, Contact.class);
>        viewContact.setContact(contact);
>        return viewContact ;
>    }
>
> }
>
>
> The view page
>
> <html t:type="layout" t:title="Show all contacts"
>      xmlns:t="http://tapestry.apache.org/schema/tapestry_5_1_0.xsd"
>      xmlns:p="tapestry:parameter">
>
>      <div class="span-6">
>          <t:menu title="Viewing Contact"/>
>      </div>
>
>      <div class="span-16">
>          <t:beandisplay object="contact"/>
>      </div>
>
> </html>
>
> package com.josh.addressbook.pages;
>
> import com.josh.addressbook.entities.Contact;
>
> public class ViewContact {
>
>
>    private Contact contact  ;
>
>    public Contact getContact() {
>        return contact;
>    }
>
>    public void setContact(Contact contact) {
>        this.contact = contact;
>    }
>
>
> }
>
>
> Error message
>
> An unexpected application exception has occurred.
>
>   - org.apache.tapestry5.internal.services.RenderQueueException
>   Render queue error in SetupRender[ViewContact:beandisplay]: Parameter
>   'object' of component ViewContact:beandisplay is bound to null. This
>   parameter is not allowed to be null.
>   activeComponents
>      - ViewContact (class com.josh.addressbook.pages.ViewContact)
>      - ViewContact:layout (class com.josh.addressbook.components.Layout)
>      classpath:com/josh/addressbook/pages/ViewContact.tml, line 31<html
>      t:type="layout" t:title="Show all contacts"2 xmlns:t="
>      http://tapestry.apache.org/schema/tapestry_5_1_0.xsd
> "3xmlns:p="tapestry:parameter">
>      4
>      5 <div class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
>      - ViewContact:beandisplay (class
>      org.apache.tapestry5.corelib.components.BeanDisplay)
>      classpath:com/josh/addressbook/pages/ViewContact.tml, line 105 <div
>      class="span-6">6 <t:menu title="Viewing Contact"/>7 </div>8
>      9 <div class="span-16">10 <t:beandisplay object="contact"/>11 </div>12
>      13</html>
>   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line 10
>   - org.apache.tapestry5.ioc.internal.util.TapestryException
>   Parameter 'object' of component ViewContact:beandisplay is bound to null.
>   This parameter is not allowed to be null.
>   locationclasspath:com/josh/addressbook/pages/ViewContact.tml, line 10Hide
>   uninteresting stack frames Stack trace
>      -
> org.apache.tapestry5.internal.transform.ParameterWorker$2$1.readFromBinding(ParameterWorker.java:328)
>
>      -
> org.apache.tapestry5.internal.transform.ParameterWorker$2$1.get(ParameterWorker.java:413)
>
>      -
> org.apache.tapestry5.corelib.components.BeanDisplay._$get_object(BeanDisplay.java)
>
>      -
> org.apache.tapestry5.corelib.components.BeanDisplay.setupRender(BeanDisplay.java:128)
>
>      -
> org.apache.tapestry5.corelib.components.BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.invoke(BeanDisplay$MethodAccess_setupRender_12c2b7e6fa2.java)
>
>      -
>
>  org.apache.tapestry5.internal.transform.RenderPhaseMethodWorker$Invoker.invoke(RenderP
>