Re: Form using both a zone and no zone.

2011-07-27 Thread nillehammer

George Christman wrote:
> 
> Nillehammer, I don't mind. I've been an interface designer for years, so
> moving to the backend I'm rather green. I am very confused with how to use
> annotations in my situation, so I'm going to post a snippet of my code and
> hopefully you guys will be able to help clarify this for me. 
> 
You'll soon discover that the real hard work is needed in the frontend.
Programming the backend is quite a lazy job compared to that. (Don't take
this 100% serious ;-)) ).


George Christman wrote:
> 
> I am very confused with how to use annotations in my situation, so I'm
> going to post a snippet of my code and hopefully you guys will be able to
> help clarify this for me.
> 
Thiago has already provided the code. This just for clarification.

For every event caused by user action (like clicking a link, submitting a
form) and for a lot of events trigered by components (like form's failure or
success) that you want get handeled you use the Annotation @OnEvent. To
narrow down the events you actually want to get handeled you use a) the
event type (the annotation's value-attribute) and b) the event source's name
(the annotation's component-attribute). 

You'll find those in the names of your event handler methods too, e.g.
on*Selected*From*Update*.
So "selected" is the event type and "update" is the event source's name.

For events that are widely used around applications Tapestry provides a
constants class "EventConstants". This should be your first stop. Browse the
constants to get an overwiew of the several events that are triggered. A
second stop would be Tapestry's component reference. You'll find a detailed
explanation of which events are triggered when by each component. Each event
gives you the possibility to hook in by providing a handler.

And if that isn't enough, you can even trigger events of your choice
yourself!

Hope this was helpfull.


-
http://www.winfonet.eu
--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4639057.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-27 Thread Thiago H. de Paula Figueiredo
On Wed, 27 Jul 2011 10:19:18 -0300, George Christman  
 wrote:



opps my save is backwards in my previous example


@CommitAfter
@OnEvent(value = EventConstants.SELECTED, component = "update")
Object updatePurchaseRequest() {
  purchaseRequestState.setPurchaseRequest(getPurchaseRequest());
  return formZone.getBody();
}

@OnEvent(value = EventConstants.SELECTED, component = "save")
Object savePurchaseRequest() { // or any other name
  session.saveOrUpdate(getPurchaseRequest());
  return
 pageRenderLinkSource.createPageRenderLinkWithContext(Update.class,
 getPurchaseRequest().getId());
}

You can also rewrite the method above in a simpler, more refactory-safe  
manner:


@InjectPage
private Update update;

@OnEvent(value = EventConstants.SELECTED, component = "save")
Object savePurchaseRequest() { // or any other name
  session.saveOrUpdate(getPurchaseRequest());
  update.setPurchaseRequest(getPurchaseRequest());
  return update;
}

In your Update page class, you should need to add this (very recommended  
for any page with activation context anyway)


Object onPassivate() {
Object value = null;
if (purchaseRequest != null) {
value = purchaseRequest.getId();
}
return value;
}

This supposes the Update page class has a purchaseRequest property.

--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Form using both a zone and no zone.

2011-07-27 Thread George Christman
opps my save is backwards in my previous example

@CommitAfter
Object onSelectedFromUpdate() {
 purchaseRequestState.setPurchaseRequest(getPurchaseRequest()); 
 return formZone.getBody();
}

Object onSelectedFromSave() {
 session.saveOrUpdate(getPurchaseRequest());

 return
pageRenderLinkSource.createPageRenderLinkWithContext(Update.class,
getPurchaseRequest().getId());
}
Free Emb

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4638731.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-27 Thread George Christman
Nillehammer, I don't mind. I've been an interface designer for years, so
moving to the backend I'm rather green. The more I can learn the better. I
am very confused with how to use annotations in my situation, so I'm going
to post a snippet of my code and hopefully you guys will be able to help
clarify this for me. 

If I understood Thiago correctly, I should be using onSuccess with the
onSelect events.

Thanks!

My two events. 

@CommitAfter
Object onSelectedFromUpdate() {
 session.saveOrUpdate();
 return formZone.getBody();
}

Object onSelectedFromSave() {
 purchaseRequestState.setPurchaseRequest(getPurchaseRequest());

 return
pageRenderLinkSource.createPageRenderLinkWithContext(Update.class,
getPurchaseRequest().getId());
}

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4638729.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-27 Thread dragan.sahpas...@gmail.com
On Tue, Jul 26, 2011 at 11:48 PM, nillehammer <
tapestry.nilleham...@winfonet.eu> wrote:

>
> Dragan Sahpaski  wrote:
> >
> > Interesting,
> > As I never had used annotations for event handlers in any project so far.
> > I choose the name of the event to imply what is needed to be done in the
> > method, which I prefer to keep it as short as possible (3-4 lines of
> >  code, rarely any more).
> >
> Same with me. My methods also mostly contain no more than a few lines. But
> to get to know, what is done, one would have to read the source code and
> hopefully understand it.
>


Wow, thanks for they example, that certainly points out the advantage of
using the annotation approach instead of the naming convention approach.

I'm just not sure why I've never used it. Guess I never thought about this
advantage too much. Thanks for the example once again.

Another advantage of the annotation approach would be that it can be easy to
rename an event during development of a custom component for example by
using @OnEvent(value=MyEvents.SOME_EVENT), using simple refactor->rename in
an IDE. This doesn't happen with tapestry events I suppose because they are
considered as a public api, but can clearly happen during development of
some t5 project using new events.

Also, sorry for stealing the thread :)

Cheers,
Dragan Sahpaski


>
> To give you simple example:
> Imagine someone would have to read your code (perhaps even you in 6 monts)
> trying to figure out what's going on. First aproach event handler with
> naming convention:
>
> final Class onSuccessFromForm() {
>  // Ok, he's handling the succsess event of the form. But what's he doing?
>
>  this.dao.save(this.entity);
>  // Ah, he has saved an entity using a dao.
>
>  return Success.class;
>  // He returns a Success.class. Hmm, why is he doing that?
>  // ... read Tapestry documentation... come back here
>  // Ok, Success.class is in the pages subpackage and returning classes
>  // from there means to forward to the particular page.
> }
>
> Now Annotation aproach with meaningfull name:
> @OnEvent(value="success", component="form")
> final Class storeEntityAndForwardToSuccess() {
>  // Ok, got it he saves an entity and forwards to Success.
>  // I'm not interested in HOW he does it and am glad not to have
>  // to read any further.
>
>  this.dao.save(this.entity);
>  return Success.class;
> }
>
> I know this example may be a bit over simplified, but I hove you got my
> point.
>
> Lastly I want to apologize to George for stealing his thread. I am glad to
> discuss code styling matters, but perhaps we should open a new thread for
> that.
>
> Cheers nillehammer
>
>
>
>
> -
> http://www.winfonet.eu
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4636545.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Form using both a zone and no zone.

2011-07-26 Thread nillehammer

Dragan Sahpaski  wrote:
> 
> Interesting,
> As I never had used annotations for event handlers in any project so far.
> I choose the name of the event to imply what is needed to be done in the
> method, which I prefer to keep it as short as possible (3-4 lines of  
>  code, rarely any more).
> 
Same with me. My methods also mostly contain no more than a few lines. But
to get to know, what is done, one would have to read the source code and
hopefully understand it. 

To give you simple example:
Imagine someone would have to read your code (perhaps even you in 6 monts)
trying to figure out what's going on. First aproach event handler with
naming convention:

final Class onSuccessFromForm() {
 // Ok, he's handling the succsess event of the form. But what's he doing?

  this.dao.save(this.entity);
  // Ah, he has saved an entity using a dao.

  return Success.class;
  // He returns a Success.class. Hmm, why is he doing that? 
  // ... read Tapestry documentation... come back here
  // Ok, Success.class is in the pages subpackage and returning classes
 // from there means to forward to the particular page.
}

Now Annotation aproach with meaningfull name:
@OnEvent(value="success", component="form")
final Class storeEntityAndForwardToSuccess() {
  // Ok, got it he saves an entity and forwards to Success.
  // I'm not interested in HOW he does it and am glad not to have
  // to read any further.
 
  this.dao.save(this.entity);
  return Success.class;
}

I know this example may be a bit over simplified, but I hove you got my
point.

Lastly I want to apologize to George for stealing his thread. I am glad to
discuss code styling matters, but perhaps we should open a new thread for
that.

Cheers nillehammer




-
http://www.winfonet.eu
--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4636545.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-26 Thread Thiago H. de Paula Figueiredo
On Tue, 26 Jul 2011 16:55:11 -0300, dragan.sahpas...@gmail.com  
 wrote:



Interesting,
As I never had used annotations for event handlers in any project so far.
I choose the name of the event to imply what is needed to be done in the
method, which I prefer to keep it as short as possible (3-4 lines of  
code, rarely any more).


Sometimes just the event name isn't sufficient to tell what the method  
does.


--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Form using both a zone and no zone.

2011-07-26 Thread dragan.sahpas...@gmail.com
On Tue, Jul 26, 2011 at 9:48 PM, nillehammer <
tapestry.nilleham...@winfonet.eu> wrote:

>
> Thiago H. de Paula Figueiredo wrote:
> >
> > By the way, any event in Tapestry can be handled by using an annotation
> in
> > the method instead of relying on naming conventions. It's your choice. :)
> >
> That cannot be repeated often enough. I think it is better style to use a
> name that explains, what is realy done in the method rather than that it is
> jus an event handler.
>

Interesting,
As I never had used annotations for event handlers in any project so far.
I choose the name of the event to imply what is needed to be done in the
method, which I prefer to keep it as short as possible (3-4 lines of code,
rarely any more).

Anyway it's nice to hear different opinions.

Cheers,
Dragan Sahpaski




>
> -
> http://www.winfonet.eu
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4636078.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Form using both a zone and no zone.

2011-07-26 Thread nillehammer

Thiago H. de Paula Figueiredo wrote:
> 
> By the way, any event in Tapestry can be handled by using an annotation in  
> the method instead of relying on naming conventions. It's your choice. :)
> 
That cannot be repeated often enough. I think it is better style to use a
name that explains, what is realy done in the method rather than that it is
jus an event handler.

-
http://www.winfonet.eu
--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4636078.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-26 Thread Thiago H. de Paula Figueiredo
On Tue, 26 Jul 2011 16:08:43 -0300, George Christman  
 wrote:


I wasn't aware of the onSelected method. Worked like a charm. Thanks  
guys.


Actually, there's no onSelected method per se: the Submit component  
triggers the "selected" event. You could also handle it by declaring a  
method with @OnEvent(value = "selected") without any naming conventions.  
By the way, any event in Tapestry can be handled by using an annotation in  
the method instead of relying on naming conventions. It's your choice. :)


--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Form using both a zone and no zone.

2011-07-26 Thread George Christman
Yup, tons of nested zones, but your exactly right, just resolved it moments
ago with the attribute id. Thanks

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635991.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-26 Thread dragan.sahpas...@gmail.com
I wasn't aware you had nested zones.
Please paste the code here.

It probably is the case that when the outer zone gets updated, tapestry
changes the id of the inner zone, so if you wire the inner zone to the form
using the zone paramter with a literal value of the id, than the form cannot
find that zone.

Anyway please paste the code here and the exact error.

Cheers,
Dragan Sahpaski

On Tue, Jul 26, 2011 at 9:11 PM, George Christman
wrote:

> I think I spoke to soon, I'm getting a different error with all the nested
> zones. Can't find zone. Any thoughts
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635965.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Re: Form using both a zone and no zone.

2011-07-26 Thread George Christman
I think I spoke to soon, I'm getting a different error with all the nested
zones. Can't find zone. Any thoughts

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635965.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-26 Thread George Christman
I wasn't aware of the onSelected method. Worked like a charm. Thanks guys. 

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635955.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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



Re: Form using both a zone and no zone.

2011-07-26 Thread Thiago H. de Paula Figueiredo
On Tue, 26 Jul 2011 15:23:42 -0300, dragan.sahpas...@gmail.com  
 wrote:



Hi,


Hi!


When you submit a form using ajax you can return a Link that will send a
redirect read more in the doc
here
.


Even easier, you can return a class or page instance too.


When having two submit buttons you can identify which one is clicked by
using the onSelected event. For example submit with t:id="saveDB" will  
fire

onSelectedFromSaveDB.


Yep! :)

--
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-unsubscr...@tapestry.apache.org
For additional commands, e-mail: users-h...@tapestry.apache.org



Re: Form using both a zone and no zone.

2011-07-26 Thread dragan.sahpas...@gmail.com
Hi,
When you submit a form using ajax you can return a Link that will send a
redirect read more in the doc
here<http://tapestry.apache.org/ajax-and-zones.html#AjaxandZones-EventHandlerReturnTypes>
.

When having two submit buttons you can identify which one is clicked by
using
the onSelected event. For example submit with t:id="saveDB" will fire
onSelectedFromSaveDB.

Cheers,
Dragan Sahpaski



On Tue, Jul 26, 2011 at 7:47 PM, George Christman
wrote:

> Hello, I'm using  the AjaxFormLoop component in my page. Nested within it
> is
> a select menu that contains an "Add New" option. When you click add new a
> popup box appears with an additional AddFormLoop component that contains
> all
> the options contained within the select menu.  When you add a new row with
> item to the popup AjaxFormLoop component and click the popup save button,
> the data is persisted to the main object and the entire page is reloaded
> wiith persisted data. The nested select menu from page AjaxFormLoop is now
> rendered with new values from popup box. In order to commit the main object
> to the database, there is a second save button on the page which handles
> database commits.
>
> What I'd like to do.
>
> When you only need to commit data to the user session, I'd like to submit
> form using ajax which will allow the menus to update and popup box to
> disappear while allowing page scroll to remain static
>
> Now when saving to the database using the Save to Database button, I'd like
> to just commit the object to the database and return page with context.
>
> I'm not sure how to get both functions out of the form. Any Ideas?
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635695.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> -
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>


Form using both a zone and no zone.

2011-07-26 Thread George Christman
Hello, I'm using  the AjaxFormLoop component in my page. Nested within it is
a select menu that contains an "Add New" option. When you click add new a
popup box appears with an additional AddFormLoop component that contains all
the options contained within the select menu.  When you add a new row with
item to the popup AjaxFormLoop component and click the popup save button,
the data is persisted to the main object and the entire page is reloaded
wiith persisted data. The nested select menu from page AjaxFormLoop is now
rendered with new values from popup box. In order to commit the main object
to the database, there is a second save button on the page which handles
database commits. 

What I'd like to do.

When you only need to commit data to the user session, I'd like to submit
form using ajax which will allow the menus to update and popup box to
disappear while allowing page scroll to remain static

Now when saving to the database using the Save to Database button, I'd like
to just commit the object to the database and return page with context. 

I'm not sure how to get both functions out of the form. Any Ideas?

--
View this message in context: 
http://tapestry.1045711.n5.nabble.com/Form-using-both-a-zone-and-no-zone-tp4635695p4635695.html
Sent from the Tapestry - User mailing list archive at Nabble.com.

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