You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by netdawg <ne...@yahoo.com> on 2012/04/23 19:50:51 UTC

Pagelink above grid picks up context from last pagelink in grid

Here is a weird one.  

Probably a minor bug report, will open JIRA if anyone else can
agree/reproduce.

See the pagelink above grid in the code below?  If there are three records,
last id=3, it will render with the last pagelink (person/edit/3).  This
makes the Create new link pull up the third record for edit.  Instead of
rendering with empty person.  I am reusing Edit page as create, obviously.  


<html t:type="admin" title="Persons"
       xmlns:t="http://tapestry.apache.org/schema/tapestry_5_3.xsd"
       xmlns:p="tapestry:parameter">
 <body>      
  <t:pagelink page="person/edit">Create new</t:pagelink>
  <t:grid source="persons" row="person" add="delete"  
          include="code,name,organization,contact" 
          reorder="code,name,organization,contact">
    <p:deleteCell>
      <t:actionlink t:id="delete" context="person.id">Delete</t:actionlink>
    </p:deleteCell>
    <p:nameCell>
     <t:pagelink page="person/edit"
context="person.id">${person.name}</t:pagelink>
    </p:nameCell>
     <p:empty>
       <p>There are no records; you can <t:pagelink page="person/edit">add
some</t:pagelink>.</p>
     </p:empty>
  </t:grid>
 </body>
</html>

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5660049.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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
I have not used @PageActivationContext but the javadoc states that it
performs onPassivate() automatically

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
I think you want flash persistence rather than the longer lived default
session persistence

@Persist(PersistanceConstants.FLASH)

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
Thanks, again, Thiago, Lance.  We will have to pick this up later...I will be
happy to post a toy application that will illustrate this (rather minor)
anamoly.    Please note, I am not using beaneditor or its cousin the
beaneditorform.  Need project specific styling.  In think therein lies the
heart of the issue: to persist or not - both of which have their uses and
unintended side-effects (that need to be managed).  And I have found one way
to manage it (context=0).  Just wanted to post that, originally.  The only
wart I see is the logs error, which is ignored.  Otherwise all else works
fine, as intended (by design).  Thanks for the suggestions, though.  I will
consider.  

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5668865.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Thu, 26 Apr 2012 01:10:22 -0300, netdawg <ne...@yahoo.com> wrote:

> Thanks, all, for college of knowledge ;-).  Much appreciated.
>
> 1.  I am not beaneditorform (or beaneditor) in EditPerson.tml, therefore  
> the @Persist annotation is needed in Person.java for the form to accept  
> the
> submit.

No, this is not correct. You don't need @Persist for using BeanEditForm or  
Form.

> 2.  The @Persist for person in EditPerson does indeed seem to clash with  
> the declaration in Persons page,

No, this is not correct. @Persist is for a single page only. Even if you  
have @Persist private Person person; in many pages, each field has its own  
different state, being stored in different session attributes.

> but simply changing it that variable to, say, personRow in Persons does  
> not work since the object person is stored in
> session state

You shouldn't @Persist personRow.

> and even the though the link above the grid renders without
> the Id anymore, clicking edit will still pull up the last added/editted
> record since it is in the session.

Not if you use @PageActivationContext or onActivate() correctly.

> Bottom line, I really see no other workarounds to simply doing the
> following:
>
> &lt;t:pagelink page=&quot;person/edit&quot; context=&quot;0&quot;>Create
> new</t:pagelink>

We already provided you the solution. Even more than one. You either post  
your whole code (including templates) or please stop saying that Tapestry  
doesn't work.

> This create a error in logs, trying to pull up the record with zero id,  
> but the application chugs along fine.  Using null or $N0 for context  
> breaks the list page.  Only zero works.

Again, you could use null instead of zero and avoid this problem.

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
I still get the feeling that you are using a single Person property instead
of two. You MUST have two properties of type Person

One will be used by your grid to store each row as it the grid iterates
through. This MUST NOT be tied to onActivate() / onPassivate().

The other will store the Person currently being edited. This will be tied
to onActivate() and onPassivate() and init() [see my previous example]

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
Thanks, all, for college of knowledge ;-).  Much appreciated.  

1.  I am not beaneditorform (or beaneditor) in EditPerson.tml, therefore the
@Persist annotation is needed in Person.java for the form to accept the
submit.  

<form t:type=&quot;Form&quot; t:id=&quot;person&quot; 

Why?  Simply, need a much more professional looking, styled form than is
supported by these two.  

2.  The @Persist for person in EditPerson does indeed seem to clash with the
declaration in Persons page, but simply changing it that variable to, say,
personRow in Persons does not work since the object person is stored in
session state and even the though the link above the grid renders without
the Id anymore, clicking edit will still pull up the last added/editted
record since it is in the session.  Ditto for returning Id, flash
persistence etc.  Basically, the session will either store person (thereby
pulling the last record) or not (thereby breaking the input form).  

3.  I am using EditPerson from the User Guide

http://tapestry.apache.org/hibernate-user-guide.html

Just added onPrepareForRender to create a new Person when in Create mode.  

Bottom line, I really see no other workarounds to simply doing the
following: 

&lt;t:pagelink page=&quot;person/edit&quot; context=&quot;0&quot;>Create
new</t:pagelink>

This create a error in logs, trying to pull up the record with zero id, but
the application chugs along fine.  Using null or $N0 for context breaks the
list page.  Only zero works.  

The application is working fine now...doing all the CRUD.  I would like to
extend it to CRUDS-QBE...search and QBE as well...that is what I am working
on now.  Will follow the suggestions here.  

Thanks, again.  





--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5666672.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: Pagelink above grid picks up context from last pagelink in grid

Posted by Joakim Olsson <jo...@unbound.se>.
Just use another property than person in your page class for storing
the current value in the grid.

Regards,
Joakim


On Wed, Apr 25, 2012 at 10:54 AM, netdawg <ne...@yahoo.com> wrote:
> I will try this to improve.  But the bad design, as you put it (and I agree),
> is required by the grid
> ...
>  <t:grid source="persons" row="person" add="delete"
>          include="code,name,organization,contact"
>          reorder="code,name,organization,contact">
> ...
>
> The row attribute complained that there is no person attribute of class
> Persons...hence the added person as property, which in turn leads to
> unintended consequences noted.
>
> --
> View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5664249.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 25 Apr 2012 06:10:47 -0300, Lance Java <la...@googlemail.com>  
wrote:

> Please stop saying that there is a bug in tapestry or that tapestry is
> forcing bad design on you.
>
> Thiago has pointed out that he often uses a single page for create and  
> edit.
>
> This grid issue seems to have nothing to do with that. Of course you  
> need a
> property to store the current row in a grid. That is the tapestry way.

And it seems that you're reusing the same field for the grid's current row  
*and* the object being edited or created. This is probably the cause of  
your problems. Have two separate fields, one for each scenario (listing or  
editing).

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
Please stop saying that there is a bug in tapestry or that tapestry is
forcing bad design on you.

Thiago has pointed out that he often uses a single page for create and edit.

This grid issue seems to have nothing to do with that. Of course you need a
property to store the current row in a grid. That is the tapestry way.

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
I will try this to improve.  But the bad design, as you put it (and I agree),
is required by the grid 
...
 <t:grid source="persons" row="person" add="delete"   
          include="code,name,organization,contact" 
          reorder="code,name,organization,contact">
...

The row attribute complained that there is no person attribute of class
Persons...hence the added person as property, which in turn leads to
unintended consequences noted.   

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5664249.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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
> @Persist(PersistenceConstants.FLASH) makes nullifies Person in Persons
page (listing page), thereby breaking it...

This sounds like bad design if your ListPersons page is referencing an
object persisted by your EditPerson page. It sounds like the flash
persistance should instead be on your ListPersons page and that your
EditPerson page should initialize and return an instance of ListPersons
(instead of returning ListPersons.class). Something like this:

public class ListPersons {
   @Property
   @Persist(PersistenceConstants.FLASH)
   private Person lastEditedPerson;

   @Property
   private List<Person> persons;

   public void init(Person lastEditedPerson) {
      this.lastEditedPerson = lastEditedPerson;
   }
   ...
}


public class EditPerson {
   @Property
   private Person person;

   @InjectPage
   private ListPersons listPersons;

   private Long personId;

   @Inject
   private Session session;

   public void onActivate(EventContext context) {
      if (context.getCount() > 0) {
         personId = context.get(Long.class, 0);
      }
   }

   void setupRender() throws Exception {
      if (personId != null) {
         person = session.get(Person.class, personId);
      } else {
         person = new Person();
      }
   }

   @CommitAfter
   Object onSuccess() {
      session.saveOrUpdate(person);
      listPersons.init(person);
      return listPersons;
   }

   public void onPassivate() {
      if (person.getId() != null) {
         return person.getId();
      }
   }
}

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by trsvax <tr...@gmail.com>.
> 2. Never use onActivate with a parameter 

Why not? What about onActivate(EventContext context)? It's always invoked,   
no matter how many activation context values is passed, and you have   
TypeCoercer-backed coercions for free. 


In general I never use onActivate at all. I try and define my page interface
completely with @PageActivationContext and @ActivationRequestParameter. I
also created @Connect which allows me to connect various page fields and I
use that to initialize things. I've found this gives me a very consistent
page interface and allows me to figure out what it is when using Plastic.
This allows me to do things like
	
@SessionState
	@Property
	private CartSession cartSession;
	
	@Property
	@Connect("cartSession.items")
	private List<OrderItem> items;

Don't worry CartSession is really stored in AWS DynamoDB not the session.

and

public class RowNew {

	@ReplaceBreadCrumb(RowEdit.class)
	Object onSuccess() {
		return row;		
	}

Which modifies my breadcrumb trail and causes the method return to the Edit
page with the correct arguments.

I can also dynamically generate documentation for each page and how to call
it. I can't help it I used ACS openacs.org before Tapestry.

> 6. Always use BeanEditForm 

I never use BeanEditForm, but I do use BeanEditor a lot. :) 

I can see that. I have a few hacks to make BeanEditForm work for me.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5664809.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
By the way, now I'm 100% sure, Pagelink above grid picks up context from  
last pagelink in grid because you're using the same field for object  
editing/creation and for the Grid current object parameter. Then you  
(netdawg) return the field value in onPassivate(). In other words,  
Tapestry is behaving exactly like expected, your code is wrong in this  
case. Never use the same field for two different roles.

Ah, and my suggestion of onPassivate() should have been this:

Object onPassivate() {
	// avoids an NPE
	if (person != null) {
		return person.getId();
	}
	else {
		return null;
	}
}

Based on your answer, you used my original solution but said it didn't  
work without even looking at the stack trace to know what happened. If you  
did, it would be quite clear what was wrong (the lack of a null person  
check).

Again, I suggest you separate the listing/searching page from the  
creating/editing one. It just complicates things.

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by Chris Mylonas <ch...@opencsta.org>.
> and remember rules are made to be broken.

LOL

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


Re: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 25 Apr 2012 08:47:37 -0300, trsvax <tr...@gmail.com> wrote:

> I would say this is more of style preference than anything else. It can  
> be made to work in many ways.

Agreed. :)

> My personal style is to use the URL for state and not the session.  
> Generally
> I only use the session to store a non changing user object. If you start
> there it dictates many of the decisions that follow. I believe this makes
> the site more scalable, bookmarkable and reliable (testable).

Agreed. :)

> As far as code reuse at first I had some of the same feelings.  
> Create/Edit seem like the same and the only real difference is the  
> onSuccess() method.

I don't think so. Just use Hibernate's Session.merge() or JPA's  
EntityManager.merge() methods and you have a method that handles both  
updates and inserts. ;)

> However Tapestry/Hibernate/Beaneditform is so efficient at this task the
> only code is in the onSuccess() method. In fact if you look at my example
> the only code (1 line) that does anything is in the onSuccess() method of
> the create page so trying to combine the two just makes for more code not
> less.

I'm really not following you here. It contradicts what you just said above.

> I've found if I follow this simple set of rules everything just fails  
> into place.

Fails or falls? :P

> 1. Never use @Persist

There are some scenarios in which you'll need to use @Persist, but I agree  
that is something to be avoided when there's some other option.

> 2. Never use onActivate with a parameter

Why not? What about onActivate(EventContext context)? It's always invoked,  
no matter how many activation context values is passed, and you have  
TypeCoercer-backed coercions for free.

> 5. Never use inheritance for code reuse use Plastic or a service.

There are some scenarios in which using inheritance is a good idea, but I  
agree that is something to be avoided when there's some other option.

> 6. Always use BeanEditForm

I never use BeanEditForm, but I do use BeanEditor a lot. :)

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
I agree with trsvax that avoiding session use is good. I can see that by
adding appropriate onActivate / onPassivate methods to my ListPersons
example, you could avoid session use.

I had a quick look at the PageActivationContextWorker and from what I can
see, @PageActivationContext is mandatory so will not work for this case
where it might be null. Perhaps a nice addition might be
@PageActivationContext(false) in a similar way to @Environmental.

Since onActivate() is called more often than you might think, I would avoid
using @PageActivationContext for complex objects (ie hibernate entities)
and I think it should only be used for storing the id's. Geoff describes
this more here
http://jumpstart.doublenegative.com.au/jumpstart/examples/navigation/onactivateandonpassivate/3

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by trsvax <tr...@gmail.com>.
I would say this is more of style preference than anything else. It can be
made to work in many ways. 

My personal style is to use the URL for state and not the session. Generally
I only use the session to store a non changing user object. If you start
there it dictates many of the decisions that follow. I believe this makes
the site more scalable, bookmarkable and reliable (testable).

As far as code reuse at first I had some of the same feelings. Create/Edit
seem like the same and the only real difference is the onSuccess() method.
However Tapestry/Hibernate/Beaneditform is so efficient at this task the
only code is in the onSuccess() method. In fact if you look at my example
the only code (1 line) that does anything is in the onSuccess() method of
the create page so trying to combine the two just makes for more code not
less. I'm pretty amazed you can create/edit any object with a few lines of
declarations and 1 line of code.

As far as search pages go I always use @ActivationRequestParameter to get
the search criteria in the URL. If you want a QBE type function I'd build a
url and call the search page.

I'm sure others have their own styles. Mine is state goes in the URL and
Tapestry supports that workflow just about perfectly. I also prefer
declarations instead of code and again Tapestry delivers. 

I've found if I follow this simple set of rules everything just fails into
place.

1. Never use @Persist
2. Never use onActivate with a parameter
3. Use @PageActivationContext
4. Use @ActivationRequestParamter
5. Never use inheritance for code reuse use Plastic or a service.
6. Always use BeanEditForm

I'm not saying this is the only way but these rules keep me out of trouble
and remember rules are made to be broken.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5664614.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Wed, 25 Apr 2012 02:07:55 -0300, netdawg <ne...@yahoo.com> wrote:

> THIAGO: return person.getId() breaks the Edit Page completely with Render
> queue error in BeginRender...

Full stack trace please.

> Fully qualifying the Edit link, as below, works fine to get the Edit  
> page to render as Create (edit/) ...without filling the last record as  
> (edit/5)
>
> <t:pagelink page="person/EditPerson">Create NEW Person/Advanced
> Search</t:pagelink>

Have you tried <t:pagelink page="person/EditPerson" context="null">Create  
NEW Person/Advanced
  Search</t:pagelink>

> Page re-use seems fraught with session/objects management issues.

I still don't think so. Use the activation context (and passivate) and you  
won't have problems.

> In any case, this is all looking like Struts, only a bit  
> backwards...Create,
> Edit and QBE pages are all identical except for the ACTION of the submit
> button.  In Struts, you just send the action to a different METHOD in the
> same CRUD class - if it needs something in the Valuestack it will get it  
> otherwise it just proceed merrily along.

You can use EventLink instead of PageLink for this kind of scenario.

> But due to apparent ambiguity of activate/passivate in Create/Edit,

What ambiguity?

> I would be happy to be proved wrong - if there is a working app out there
> which does all three Create/Update and QBE...

I usually have one page for creating and updating and another for searches.

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
Thanks, guys.  

LANCE:  @Persist(PersistenceConstants.FLASH) makes nullifies Person in
Persons page (listing page), thereby breaking it...

THIAGO: return person.getId() breaks the Edit Page completely with Render
queue error in BeginRender...

Here is probably the clincher that this is a bug or some type of unitended
workflow problem  

Fully qualifying the Edit link, as below, works fine to get the Edit page to
render as Create (edit/) ...without filling the last record as (edit/5)

<t:pagelink page="person/EditPerson">Create NEW Person/Advanced
Search</t:pagelink>

BUT.............

then clicking the create/update button after coming into edit (in create
mode) nullifies person and breaks the persons listing page....hope that
makes sense.  

I am agreeing with trsvax at the moment...

Page re-use seems fraught with session/objects management issues.  

I am trying to re-use not just Create/Update but also Query by Example
(QBE).  

I have a button called Search and a method called onSelectedFromSearch in
EditPerson.java

That, too, seems to mess up the session as well, nullifying the person
before it can be employed in QBE Search.

In any case, this is all looking like Struts, only a bit backwards...Create,
Edit and QBE pages are all identical except for the ACTION of the submit
button.  In Struts, you just send the action to a different METHOD in the
same CRUD class - if it needs something in the Valuestack it will get it -
otherwise it just proceed merrily along.  

But due to apparent ambiguity of activate/passivate in Create/Edit,  seems
like we are best off maintaining three separate sets of files - tml and java
- one each for Create, Update and QBE.  Otherwise each of these operations
end up driving in each other's lanes.  And, IF SO, this seems like a
fundamental architectural weakness, not just a bug(?).  

Using a component (or jsp) to render most of the form will probably save
tripling the pain...but that would defeat the purpose of form re-use. 

I would be happy to be proved wrong - if there is a working app out there
which does all three Create/Update and QBE...



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5663892.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 24 Apr 2012 13:51:09 -0300, trsvax <tr...@gmail.com> wrote:

> The first read will return Person 5 but what you want is a blank form.

Not if you always set the person field from the page activation context  
(none -> new object, some value -> existing object). I use the same page  
for editing and creating new objects without any problems.

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by trsvax <tr...@gmail.com>.
Flash will change it but I don't think it will fix it. For example

if you go to
editPerson/5

and then save, Person 5 will be in the session and you return to Persons

Now press new and you go to
editPerson

The first read will return Person 5 but what you want is a blank form. It's
possible to fix this with more code but ultimately I think the two page
solution ends up being simpler. Not only that but it does not put anything
into the session.

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5662645.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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
Did you try flash persistence as I suggested earlier?

Flash persistence only stores in the session momentarily so that state can
be maintained through a  "redirect after post".

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by trsvax <tr...@gmail.com>.
While it seems like a good idea (and believe me I've tried) to have one page
handle create/update it turns out that many things conspire to make this
more difficult than it seems and I've just returned to having a PersonNew
and a PersonEdit.

The first problem is if you use @Persist like you are using it the Person is
persisted in the session forever. This means if you return to the PersonEdit
page and do not provide an activation context you will get the last person
created/edited. This is almost never what you want and I suspect it part of
your problem. The easiest way to solve this is don't use @Persist

So my suggestion would be something like:

public class PersonEdit {

@PageActivationContext
@Property
private Person person;

@CommitAfter
Object onSuccess() {
return Persons.class
}

and 

public class PersonNew {
@Property
private Person person;

@Inject
private Session session;

@CommitAfter
Object onSuccess() {
session.saveOrUpdate(person); 
return Persons.class
}
}

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5662588.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: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
Neither does this work...

Object onPassivate()   {     return new Person();   }

Only context=0.  

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5661353.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: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
Commenting out onPassivate does not help.  Thanks 

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5661333.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: Pagelink above grid picks up context from last pagelink in grid

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
On Tue, 24 Apr 2012 05:31:03 -0300, netdawg <ne...@yahoo.com> wrote:

>   Object onPassivate()
>   {
>     return person;
>   }

Try returning person.getId() please.

-- 
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: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
package org.pacificcis.piko.pages.person;

import org.hibernate.Session;

import org.pacificcis.piko.entities.Person;
import org.pacificcis.piko.pages.Persons;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.PageActivationContext;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;


import org.apache.tapestry5.hibernate.annotations.CommitAfter;

import org.apache.tapestry5.ioc.annotations.Inject;

import org.apache.log4j.Logger;


public class EditPerson 
{

  private static Logger logger = Logger.getLogger(EditPerson.class);
	
  @Inject
  private Session session;

  @PageActivationContext
  @Property
  @Persist
  private Person person;
  
  @InjectPage
  private Persons persons;
  

  Object onSuccess()
  {
    saveOrUpdate();
    return persons;
  }
  
  @CommitAfter
  private void saveOrUpdate()
  {
    session.saveOrUpdate(person);
  }
	  
  void onActivate(Person person)
  {
    this.person = person;
  }

  Object onPassivate() 
  { 
    return person; 
  }

  void onPrepareForRender()
  {
    if (this.person == null) this.person = new Person();
  }
  
}


--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5661321.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: Pagelink above grid picks up context from last pagelink in grid

Posted by Lance Java <la...@googlemail.com>.
Can I see the serverside code for your edit page?

I get the feeling that onPassivate() is being called on the edit page and
returning an id persisted in the session.

Re: Pagelink above grid picks up context from last pagelink in grid

Posted by netdawg <ne...@yahoo.com>.
This seems to fix it.

<t:pagelink page="person/edit" context="0">Create new</t:pagelink>

So, there is a workaround....for now.  As I said, minor bug.  

--
View this message in context: http://tapestry.1045711.n5.nabble.com/Pagelink-above-grid-picks-up-context-from-last-pagelink-in-grid-tp5660049p5660054.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