You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Michael Prescott <mi...@gmail.com> on 2012/08/01 21:41:59 UTC

Simple zone/form conundrum

I have an add/edit form - if the context is non-null, then I'm editing,
otherwise I'm adding. So far, so good.

As the user edits, they occasionally submit to the server to get the
server's impressions of what they've posted so far (it looks at what
they've submitted, works out some metrics).  These metrics are displayed in
the zone that the form is linked to.

So, I got a curious problem where I'd go to the form to add a new entity,
click submit and the metrics would show up.  But each time I did this, a
new record was saved.

I suspect that, when the form updates a zone, the form has no chance to
realize that the page now has a context.  Only a full-page refresh (or
perhaps of a zone that contains the form) will do that.

Is there a workaround for this?  Is there some way I can get the form to
update its sense of the page context?  (Short of ditching the zone and
having the page refresh, which is easy.)

Gratefully,

Michael

Re: Simple zone/form conundrum

Posted by Michael Prescott <mi...@gmail.com>.
Yes - excellent.  Thanks very much for your help.

On 1 August 2012 16:12, George Christman <gc...@cardaddy.com> wrote:

> your event is always null on a new record after the zone refreshes. You
> need
> to somehow set the event obj after the zone update. Thiago might have a
> better solution than using persisting the object.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Simple-zone-form-conundrum-tp5714957p5714967.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: Simple zone/form conundrum

Posted by George Christman <gc...@cardaddy.com>.
your event is always null on a new record after the zone refreshes. You need
to somehow set the event obj after the zone update. Thiago might have a
better solution than using persisting the object. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Simple-zone-form-conundrum-tp5714957p5714967.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: Simple zone/form conundrum

Posted by Michael Prescott <mi...@gmail.com>.
Thanks for replying.

Yes, I'm trying to add/edit in the same page.

I wondered the same thing, but I think I am.  The relevant snippets look
like this:

// my page
public class EventEdit {
 @Inject
private EventDao eventDao;

@Property
 private Event event;

@InjectComponent("predictionszone")
 private Zone predictionsZone;

void onActivate(Event event) {
 this.event = event;
}

Object onPassivate() {
 return event;
}

void onPrepare() {
 if (event == null)
event = new Event();
}

@CommitAfter
Object onSuccess() throws Exception {
eventDao.save(event);
 predictions = predictor.getPredictions(event.getQuestionnaire());
return predictionsZone.getBody();
 }
}



<t:form zone="predictionszone" context="event">
 <t:beaneditor object="event"/>
<t:linksubmit>Save/Predict</t:linksubmit>

  <div t:type="zone" t:id="predictionszone" class="event-predictions">
  <!-- all sorts of crap in here -->
  </div>
</t:form>

Michael


On 1 August 2012 15:55, George Christman <gc...@cardaddy.com> wrote:

> Michael, are you trying to to add / edit your form in the same page? ie
> passing a url parameter when the record exist and not having a url
> parameter
> when the record is new, but updating with ajax? If so, it sounds like your
> not setting your object after the zone saves and reloads the form.
>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Simple-zone-form-conundrum-tp5714957p5714959.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: Simple zone/form conundrum

Posted by George Christman <gc...@cardaddy.com>.
Michael, are you trying to to add / edit your form in the same page? ie
passing a url parameter when the record exist and not having a url parameter
when the record is new, but updating with ajax? If so, it sounds like your
not setting your object after the zone saves and reloads the form. 



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Simple-zone-form-conundrum-tp5714957p5714959.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: Simple zone/form conundrum

Posted by Michael Prescott <mi...@gmail.com>.
Thanks for these recommendations.  The @Persist approach works fine, when
the form is submitted in 'add' mode, I can store the newly created
identifier temporarily for use on the next ajax call.

The form context parameter works as advertised, but I don't think solves my
problem as the context is set to 'null' when you arrive at the form in
'add' mode, and this never changes.  So @Persist it is.

Thank you both for your advice.

On 1 August 2012 16:14, Thiago H de Paula Figueiredo <th...@gmail.com>wrote:

> On Wed, 01 Aug 2012 17:11:26 -0300, Michael Prescott <
> michael.r.prescott@gmail.com> wrote:
>
>  (posted)
>> Okay, yes, I may just be running counter to the grain - ajax requests
>> aren't supposed to change the context.  I suppose (since the zone is in
>> the form) I could have the zone contain a sort of 'custom context', so that
>> when I move from adding to editing.
>>
>
> The Form component does have a context parameter you can use to receive
> the edited object in event handler methods when submitting. Or you can use
> @Persist.
>
>
> --
> Thiago H. de Paula Figueiredo
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Simple zone/form conundrum

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 01 Aug 2012 17:11:26 -0300, Michael Prescott  
<mi...@gmail.com> wrote:

> (posted)
> Okay, yes, I may just be running counter to the grain - ajax requests
> aren't supposed to change the context.  I suppose (since the zone is in  
> the form) I could have the zone contain a sort of 'custom context', so  
> that
> when I move from adding to editing.

The Form component does have a context parameter you can use to receive  
the edited object in event handler methods when submitting. Or you can use  
@Persist.

-- 
Thiago H. de Paula Figueiredo

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


Re: Simple zone/form conundrum

Posted by Michael Prescott <mi...@gmail.com>.
(posted)

Okay, yes, I may just be running counter to the grain - ajax requests
aren't supposed to change the context.  I suppose (since the zone is in the
form) I could have the zone contain a sort of 'custom context', so that
when I move from adding to editing.

Michael

On 1 August 2012 15:59, Thiago H de Paula Figueiredo <th...@gmail.com>wrote:

> On Wed, 01 Aug 2012 16:41:59 -0300, Michael Prescott <
> michael.r.prescott@gmail.com> wrote:
>
>  I suspect that, when the form updates a zone, the form has no chance to
>> realize that the page now has a context.
>>
>
> The page context is tied to the current URL. AJAX requests don't change
> the current URL.
>
>
>  Only a full-page refresh (or
>> perhaps of a zone that contains the form) will do that.
>>
>
> Please post your code. Otherwise, we can only guess.
>
> --
> Thiago H. de Paula Figueiredo
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>

Re: Simple zone/form conundrum

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Wed, 01 Aug 2012 16:41:59 -0300, Michael Prescott  
<mi...@gmail.com> wrote:

> I suspect that, when the form updates a zone, the form has no chance to
> realize that the page now has a context.

The page context is tied to the current URL. AJAX requests don't change  
the current URL.

> Only a full-page refresh (or
> perhaps of a zone that contains the form) will do that.

Please post your code. Otherwise, we can only guess.

-- 
Thiago H. de Paula Figueiredo

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