You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Angelo Chen <an...@yahoo.com.hk> on 2008/03/05 04:02:40 UTC

T5: determine button clicked in a beaneditor

Hi,

How to determine which button is clicked in the following case:

<t:form>
  <t:beaneditor>
  </t:beaneditor>

  <input type="submit" class="t-beaneditor-submit" value="Update"
id="update"/>
  <input type="submit" value="Cancel" id="cancel"/>
 </t:form>

Thanks,

A.C.
-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15841944.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: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Martin,

It works, thanks, I'll update that wiki.

A.C.


Martin Kersten-2 wrote:
> 
> Hi A.C.
> 
>    
> If this works for you, can you do me a favor? 
> Check out: 
> http://wiki.apache.org/tapestry/Tapestry5HowToUseForms
> 
> And add this multi button handling. I am to buzzy right
> now but I can do it as well at weekend.
> 
> 
> Cheers,
> 
> Martin (Kersten)
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
> Gesendet: Mittwoch, 5. März 2008 04:03
> An: users@tapestry.apache.org
> Betreff: T5: determine button clicked in a beaneditor
> 
> 
> Hi,
> 
> How to determine which button is clicked in the following case:
> 
> <t:form>
>   <t:beaneditor>
>   </t:beaneditor>
> 
>   <input type="submit" class="t-beaneditor-submit" value="Update"
> id="update"/>
>   <input type="submit" value="Cancel" id="cancel"/>  </t:form>
> 
> Thanks,
> 
> A.C.
> --
> View this message in context:
> http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15841944.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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15844779.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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Davor Hrg <hr...@gmail.com>.
as said,
just like any event
you declare a method properly named

for example form fires prepare success event
and you capture it by declaring in enclosing component:

public void onSuccess()
or
public void onSuccessFromMyForm()

so to capture entitySaved event
just declare
public void onEntitySaved(Long id, MyEntity entity, boolean isNew)

or for cancel
public void onCancel()


Davor Hrg


On Wed, Mar 5, 2008 at 4:12 PM, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>  Hi Davor,
>
>  I got your point, the thing I can't understand is the event, how to use
>  those events triggered in the onSuccess?
>
>
>
>  Davor Hrg wrote:
>  >
>  > public void onSuccess(){
>  >     if(isCancel){
>  >         _session.evict(_entity);//it is forgotten now
>  >         _resources.triggerEvent("cancel", new Object[0],null);
>  >     }else{
>  >         boolean isNew = _entity.getId() == null;
>  >         _session.saveOrUpdate(_entity);
>  >         _resources.triggerEvent("entitySaved", new
>  > Object[]{_entity.getId(), _entity, isNew},null);
>  >     }
>  >
>  > }
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15852447.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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Davor,

I got your point, the thing I can't understand is the event, how to use
those events triggered in the onSuccess?


Davor Hrg wrote:
> 
> public void onSuccess(){
>     if(isCancel){
>         _session.evict(_entity);//it is forgotten now
>         _resources.triggerEvent("cancel", new Object[0],null);
>     }else{
>         boolean isNew = _entity.getId() == null;
>         _session.saveOrUpdate(_entity);
>         _resources.triggerEvent("entitySaved", new
> Object[]{_entity.getId(), _entity, isNew},null);
>     }
> 
> }
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15852447.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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Davor Hrg <hr...@gmail.com>.
if you have two buttons:

<t:submit value="message:save">
<t:submit t:id="cancel" value="message:cancel">


in java code
    @Inject private Session _session;
    @Inject private ComponentResources _resources;

     private boolean isCancel;

public void onSelectedFromCancel(){
    isCancel = true;
}

public void onSuccess(){
    if(isCancel){
        _session.evict(_entity);//it is forgotten now
        _resources.triggerEvent("cancel", new Object[0],null);
    }else{
        boolean isNew = _entity.getId() == null;
        _session.saveOrUpdate(_entity);
        _resources.triggerEvent("entitySaved", new
Object[]{_entity.getId(), _entity, isNew},null);
    }

}


this way your component gives more information on what happened
and parent component can add extra logic I've mentioned before

onEntitySaved(id, entity, isNew)
onCancel()

I've actualy encapsulated all this into a Generic component
so in my impl there is extra code using TypeCoercer for translating entity id
for some operations.

Davor Hrg
On Wed, Mar 5, 2008 at 3:46 PM, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>  Hi Davor,
>
>  This is interesting, can you give a simple but complete sample how it works?
>  thanks.
>
>  A.C.
>
>
>
>  Davor Hrg wrote:
>  >
>  >
>  > I for enitity editing have a component
>  > and throw new events based on button clicked;
>  >
>  > then capture them
>  > onEntitySaved(id, entity, isNew)
>  > onCancel()
>  >
>  > this way outside component need not know about buttons inside..
>  > but can rely on event names..
>  >
>  > When I have parent enitity form that embeds child entity form
>  > I can then do:
>  > onEntitySavedFromChildForm(id, child,isNew){
>  >     if(isNew) child.setParent(parent);
>  > }
>  >
>  >
>  > to generate your own event:
>  >
>  >     @Inject private ComponentResources _resources;
>  > ....
>  >    _resources.triggerEvent("entitySaved", new Object[]{_entityId,
>  > _entity, isNew}, null);
>  >
>  >
>  > Davor Hrg
>  >
>
>  --
>  View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15851594.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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Davor,

This is interesting, can you give a simple but complete sample how it works?
thanks.

A.C.


Davor Hrg wrote:
> 
> 
> I for enitity editing have a component
> and throw new events based on button clicked;
> 
> then capture them
> onEntitySaved(id, entity, isNew)
> onCancel()
> 
> this way outside component need not know about buttons inside..
> but can rely on event names..
> 
> When I have parent enitity form that embeds child entity form
> I can then do:
> onEntitySavedFromChildForm(id, child,isNew){
>     if(isNew) child.setParent(parent);
> }
> 
> 
> to generate your own event:
> 
>     @Inject private ComponentResources _resources;
> ....
>    _resources.triggerEvent("entitySaved", new Object[]{_entityId,
> _entity, isNew}, null);
> 
> 
> Davor Hrg
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15851594.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


AW: T5: determine button clicked in a beaneditor

Posted by Martin Kersten <Ma...@mercateo.com>.
Hi Davor, 

Thats a good point Davor. Generating your own events flattens
the logic. But for submit buttons I thought it to be an overhead.
Often I find that the kind of button only changes a small kind of
logic. 

I will give it a harder try. It is not that verbose as of a submit 
type.


Cheers,

Martin (Kersten)


-----Ursprüngliche Nachricht-----
Von: Davor Hrg [mailto:hrgdavor@gmail.com] 
Gesendet: Mittwoch, 5. März 2008 14:49
An: Tapestry users
Betreff: Re: AW: AW: T5: determine button clicked in a beaneditor

you can use BeanEditor inside a normal form, and add your own buttons, and then you can check onSelected for your own buttons easily


I for enitity editing have a component
and throw new events based on button clicked;

then capture them
onEntitySaved(id, entity, isNew)
onCancel()

this way outside component need not know about buttons inside..
but can rely on event names..

When I have parent enitity form that embeds child entity form I can then do:
onEntitySavedFromChildForm(id, child,isNew){
    if(isNew) child.setParent(parent);
}


to generate your own event:

    @Inject private ComponentResources _resources; ....
   _resources.triggerEvent("entitySaved", new Object[]{_entityId, _entity, isNew}, null);


Davor Hrg


On Wed, Mar 5, 2008 at 2:34 PM, Martin Kersten <Ma...@mercateo.com> wrote:
> Hi Angelo,
>
>    I guess the session.get(User.class, id) should happen in  
> onActivate or onSuccess (where I use it).
>
>  Just threat the onSuccess method as an atomic event handler  but 
> onActivate should work also (not that sure).
>
>  Just print all the hits of the event methods to console and  see 
> yourself. The order of the event should be:
>
>  1. onActivate
>  2. onSelectedXXX
>  3. onSuccess
>
>  I just use a schema like this in conjunction with a form
>  context:
>
>  onSuccess(int userId) {
>    User user = getUserById(id);
>    alterTheUserAccordingToForm(user);
>    storeUser(user);
>  }
>
>  Works very well.
>
>
>
>  Cheers,
>
>  Martin (Kersten)
>
>  -----Ursprüngliche Nachricht-----
>  Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
>  Gesendet: Mittwoch, 5. März 2008 11:32
>
> An: users@tapestry.apache.org
>  Betreff: Re: AW: AW: T5: determine button clicked in a beaneditor
>
>
>
>
>  hi martin,
>
>  yes, only to return a link:
>
>   void onSelectedFromUpdate() {
>
>             object = (Usr) session.get(Usr.class, id); // this is too late as a object has been created this time
>     }
>
>     void onSelectedFromBack() {
>         System.out.println("from back");
>
>     }
>
>     Link onSuccess() {
>         return backLink;
>     }
>
>
>
>
>  Martin Kersten-2 wrote:
>  >
>  > Hi Angelo,
>  >
>  >    Are you using the onSuccess event?
>  >
>  > Cheers,
>  >
>  > Martin (Kersten)
>  >
>  > -----Ursprüngliche Nachricht-----
>  > Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
>  > Gesendet: Mittwoch, 5. März 2008 10:48  > An: 
> users@tapestry.apache.org  > Betreff: Re: AW: T5: determine button 
> clicked in a beaneditor  >  >  > Hi Martin,  >  > The onSelected even 
> happens after the form fields have been submitted,  > my need is to 
> edit a Hibernate bean, what I'm doing now is: I  > persisted the 
> bean's id, in the onActivate even I re-read the bean, so  > that form 
> will update an existing bean, however, even the cancel  > button 
> triggers onActivate event as well. so moving the re-reading of  > bean 
> to onSelectedFromUpdate seems a solution, but it's too late at  > that 
> time as form has been submitted, any idea ? Thanks,  >  > A.C.
>  > p.s. will be better if we can have an event before the form is  > 
> submitted, that is onActivate, but we have no way to determine which  
> > button triggers the event there.
>  >
>  >
>  > Martin Kersten-2 wrote:
>  >>
>  >> Hi A.C.
>  >>
>  >>    I asked the very same question before but in conjunction with
>  >> normal t:form component. Since the bean-editor is based on that  
> >> t:form component it should apply to this scenario as well:
>  >>
>  >> Rule of Thumb: If you have a button you have an onSelected event!
>  >>
>  >> So in your case:
>  >>
>  >> <t:form>
>  >>  <input t:type="submit" t:id="done" value="Done"/>  <input  >> 
> t:type="submit" t:id="failed" value="Failed"/> </t:form>  >>  >> class 
> MyPage {
>  >>    final int DONE = 0;
>  >>    final int FAILED = 1;
>  >>
>  >>    int submitType = DONE;
>  >>
>  >>    boolean onSelectedFromDone() {
>  >>       submitType = DONE;
>  >>       return true;
>  >>    }
>  >>
>  >>
>  >>
>  >
>  > --
>  > View this message in context:
>  > 
> http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-t
>  > p15841944p15846642.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  >  
> >  >
>
>  --
>  View this message in context: 
> http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-t
> p15841944p15847228.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
>
>

---------------------------------------------------------------------
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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Davor Hrg <hr...@gmail.com>.
you can use BeanEditor inside a normal form,
and add your own buttons, and then you can
check onSelected for your own buttons easily


I for enitity editing have a component
and throw new events based on button clicked;

then capture them
onEntitySaved(id, entity, isNew)
onCancel()

this way outside component need not know about buttons inside..
but can rely on event names..

When I have parent enitity form that embeds child entity form
I can then do:
onEntitySavedFromChildForm(id, child,isNew){
    if(isNew) child.setParent(parent);
}


to generate your own event:

    @Inject private ComponentResources _resources;
....
   _resources.triggerEvent("entitySaved", new Object[]{_entityId,
_entity, isNew}, null);


Davor Hrg


On Wed, Mar 5, 2008 at 2:34 PM, Martin Kersten
<Ma...@mercateo.com> wrote:
> Hi Angelo,
>
>    I guess the session.get(User.class, id) should happen in
>  onActivate or onSuccess (where I use it).
>
>  Just threat the onSuccess method as an atomic event handler
>  but onActivate should work also (not that sure).
>
>  Just print all the hits of the event methods to console and
>  see yourself. The order of the event should be:
>
>  1. onActivate
>  2. onSelectedXXX
>  3. onSuccess
>
>  I just use a schema like this in conjunction with a form
>  context:
>
>  onSuccess(int userId) {
>    User user = getUserById(id);
>    alterTheUserAccordingToForm(user);
>    storeUser(user);
>  }
>
>  Works very well.
>
>
>
>  Cheers,
>
>  Martin (Kersten)
>
>  -----Ursprüngliche Nachricht-----
>  Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
>  Gesendet: Mittwoch, 5. März 2008 11:32
>
> An: users@tapestry.apache.org
>  Betreff: Re: AW: AW: T5: determine button clicked in a beaneditor
>
>
>
>
>  hi martin,
>
>  yes, only to return a link:
>
>   void onSelectedFromUpdate() {
>
>             object = (Usr) session.get(Usr.class, id); // this is too late as a object has been created this time
>     }
>
>     void onSelectedFromBack() {
>         System.out.println("from back");
>
>     }
>
>     Link onSuccess() {
>         return backLink;
>     }
>
>
>
>
>  Martin Kersten-2 wrote:
>  >
>  > Hi Angelo,
>  >
>  >    Are you using the onSuccess event?
>  >
>  > Cheers,
>  >
>  > Martin (Kersten)
>  >
>  > -----Ursprüngliche Nachricht-----
>  > Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
>  > Gesendet: Mittwoch, 5. März 2008 10:48
>  > An: users@tapestry.apache.org
>  > Betreff: Re: AW: T5: determine button clicked in a beaneditor
>  >
>  >
>  > Hi Martin,
>  >
>  > The onSelected even happens after the form fields have been submitted,
>  > my need is to edit a Hibernate bean, what I'm doing now is: I
>  > persisted the bean's id, in the onActivate even I re-read the bean, so
>  > that form will update an existing bean, however, even the cancel
>  > button triggers onActivate event as well. so moving the re-reading of
>  > bean to onSelectedFromUpdate seems a solution, but it's too late at
>  > that time as form has been submitted, any idea ? Thanks,
>  >
>  > A.C.
>  > p.s. will be better if we can have an event before the form is
>  > submitted, that is onActivate, but we have no way to determine which
>  > button triggers the event there.
>  >
>  >
>  > Martin Kersten-2 wrote:
>  >>
>  >> Hi A.C.
>  >>
>  >>    I asked the very same question before but in conjunction with
>  >> normal t:form component. Since the bean-editor is based on that
>  >> t:form component it should apply to this scenario as well:
>  >>
>  >> Rule of Thumb: If you have a button you have an onSelected event!
>  >>
>  >> So in your case:
>  >>
>  >> <t:form>
>  >>  <input t:type="submit" t:id="done" value="Done"/>  <input
>  >> t:type="submit" t:id="failed" value="Failed"/> </t:form>
>  >>
>  >> class MyPage {
>  >>    final int DONE = 0;
>  >>    final int FAILED = 1;
>  >>
>  >>    int submitType = DONE;
>  >>
>  >>    boolean onSelectedFromDone() {
>  >>       submitType = DONE;
>  >>       return true;
>  >>    }
>  >>
>  >>
>  >>
>  >
>  > --
>  > View this message in context:
>  > http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-t
>  > p15841944p15846642.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
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15847228.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
>
>

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


AW: AW: AW: AW: T5: determine button clicked in a beaneditor

Posted by Martin Kersten <Ma...@mercateo.com>.
Hi Angelo,

  I understand now what you mean. I guess I am out of luck then.
So in the end you need the information just a different time. Seams
that you are quite out of luck. You can pull the break and use
JavaScript to add additional information to startup.

Dravor gets a point (session.evict) but in general there should
be a more tapestry like solution when you start playing with more
then ok cancel buttons.

Another idea if you have a cancel button you can create a normal
action link and user your own css to style both the submit button
and the cancel link the same way. So with one you submit the form
with the link you cancel the whole workflow.

Just an additional idea.


Cheers,

Martin (Kersten)

-----Ursprüngliche Nachricht-----
Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
Gesendet: Mittwoch, 5. März 2008 15:18
An: users@tapestry.apache.org
Betreff: Re: AW: AW: AW: T5: determine button clicked in a beaneditor


Hi Martin,

Your case should work as you have alterTheUserAccordingToForm. I'm just taking advantage of Tapestry-Hibernate's feature to save coding, in the first request, an object will be retrieved to render the form, in submission the existing object was retrieved again then merge with the data in the form, this saves the function similar to your alterTheUserAccordingToForm, it works very well if we have only a submit button, getting complicated when a cancel button is added.

A.C.


Martin Kersten-2 wrote:
> 
> Hi Angelo,
> 
> onSuccess(int userId) {
>    User user = getUserById(id);
>    alterTheUserAccordingToForm(user);
>    storeUser(user);
> }
> 
> Works very well.
> 
> 
> 

--
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15850624.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: AW: AW: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Davor, Martin,

This is the elegant solution, so from the method suggested by Martin, I am
able to determine which button is clicked, then I just do a session.evict as
suggested by Davor in the onSelectedFromCancel, simple and works! thanks
guys. Davor has mentioned this event approach, I remember he mentioned
somewhere else too, I do like to see a complete example, it might trigger
some more ideas, thanks again,

A.C.


Davor Hrg wrote:
> 
> you can just call session.evict when cancel button is clicked..
> that single line works fine for me
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15851912.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: AW: AW: AW: T5: determine button clicked in a beaneditor

Posted by Davor Hrg <hr...@gmail.com>.
you can just call session.evict when cancel button is clicked..
that single line works fine for me

Davor Hrg

On Wed, Mar 5, 2008 at 3:18 PM, Angelo Chen <an...@yahoo.com.hk> wrote:
>
>  Hi Martin,
>
>  Your case should work as you have alterTheUserAccordingToForm. I'm just
>  taking advantage of Tapestry-Hibernate's feature to save coding, in the
>  first request, an object will be retrieved to render the form, in submission
>  the existing object was retrieved again then merge with the data in the
>  form, this saves the function similar to your alterTheUserAccordingToForm,
>  it works very well if we have only a submit button, getting complicated when
>  a cancel button is added.
>
>  A.C.
>
>
>
>  Martin Kersten-2 wrote:
>  >
>  > Hi Angelo,
>  >
>
> > onSuccess(int userId) {
>  >    User user = getUserById(id);
>  >    alterTheUserAccordingToForm(user);
>  >    storeUser(user);
>  > }
>  >
>  > Works very well.
>  >
>  >
>  >
>
>  --
>  View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15850624.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: AW: AW: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Martin,

Your case should work as you have alterTheUserAccordingToForm. I'm just
taking advantage of Tapestry-Hibernate's feature to save coding, in the
first request, an object will be retrieved to render the form, in submission
the existing object was retrieved again then merge with the data in the
form, this saves the function similar to your alterTheUserAccordingToForm,
it works very well if we have only a submit button, getting complicated when
a cancel button is added.

A.C.


Martin Kersten-2 wrote:
> 
> Hi Angelo,
> 
> onSuccess(int userId) {
>    User user = getUserById(id);
>    alterTheUserAccordingToForm(user);
>    storeUser(user);
> }
> 
> Works very well.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15850624.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


AW: AW: AW: T5: determine button clicked in a beaneditor

Posted by Martin Kersten <Ma...@mercateo.com>.
Hi Angelo,

   I guess the session.get(User.class, id) should happen in 
onActivate or onSuccess (where I use it).

Just threat the onSuccess method as an atomic event handler 
but onActivate should work also (not that sure).

Just print all the hits of the event methods to console and
see yourself. The order of the event should be:

1. onActivate
2. onSelectedXXX
3. onSuccess

I just use a schema like this in conjunction with a form 
context:

onSuccess(int userId) {
   User user = getUserById(id);
   alterTheUserAccordingToForm(user);
   storeUser(user);
}

Works very well.


Cheers,

Martin (Kersten)

-----Ursprüngliche Nachricht-----
Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
Gesendet: Mittwoch, 5. März 2008 11:32
An: users@tapestry.apache.org
Betreff: Re: AW: AW: T5: determine button clicked in a beaneditor


hi martin,

yes, only to return a link:

 void onSelectedFromUpdate() {
     
            object = (Usr) session.get(Usr.class, id); // this is too late as a object has been created this time
    }

    void onSelectedFromBack() {
        System.out.println("from back");

    }

    Link onSuccess() {
        return backLink;
    }




Martin Kersten-2 wrote:
> 
> Hi Angelo,
> 
>    Are you using the onSuccess event?
> 
> Cheers,
> 
> Martin (Kersten)
> 
> -----Ursprüngliche Nachricht-----
> Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk]
> Gesendet: Mittwoch, 5. März 2008 10:48
> An: users@tapestry.apache.org
> Betreff: Re: AW: T5: determine button clicked in a beaneditor
> 
> 
> Hi Martin,
> 
> The onSelected even happens after the form fields have been submitted, 
> my need is to edit a Hibernate bean, what I'm doing now is: I 
> persisted the bean's id, in the onActivate even I re-read the bean, so 
> that form will update an existing bean, however, even the cancel 
> button triggers onActivate event as well. so moving the re-reading of 
> bean to onSelectedFromUpdate seems a solution, but it's too late at 
> that time as form has been submitted, any idea ? Thanks,
> 
> A.C.
> p.s. will be better if we can have an event before the form is 
> submitted, that is onActivate, but we have no way to determine which 
> button triggers the event there.
> 
> 
> Martin Kersten-2 wrote:
>> 
>> Hi A.C.
>> 
>>    I asked the very same question before but in conjunction with 
>> normal t:form component. Since the bean-editor is based on that 
>> t:form component it should apply to this scenario as well:
>> 
>> Rule of Thumb: If you have a button you have an onSelected event!
>> 
>> So in your case:
>> 
>> <t:form>
>>  <input t:type="submit" t:id="done" value="Done"/>  <input 
>> t:type="submit" t:id="failed" value="Failed"/> </t:form>
>> 
>> class MyPage {
>>    final int DONE = 0;
>>    final int FAILED = 1;
>> 
>>    int submitType = DONE;
>> 
>>    boolean onSelectedFromDone() {
>>       submitType = DONE;
>>       return true;
>>    }
>> 
>> 
>> 
> 
> --
> View this message in context:
> http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-t
> p15841944p15846642.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
> 
> 
> 

--
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15847228.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: AW: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
hi martin,

yes, only to return a link:

 void onSelectedFromUpdate() {
     
            object = (Usr) session.get(Usr.class, id); // this is too late
as a object has been created this time
    }

    void onSelectedFromBack() {
        System.out.println("from back");

    }

    Link onSuccess() {
        return backLink;
    }




Martin Kersten-2 wrote:
> 
> Hi Angelo,
> 
>    Are you using the onSuccess event?
> 
> Cheers,
> 
> Martin (Kersten)
> 
> -----Ursprüngliche Nachricht-----
> Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
> Gesendet: Mittwoch, 5. März 2008 10:48
> An: users@tapestry.apache.org
> Betreff: Re: AW: T5: determine button clicked in a beaneditor
> 
> 
> Hi Martin,
> 
> The onSelected even happens after the form fields have been submitted, my
> need is to edit a Hibernate bean, what I'm doing now is: I persisted the
> bean's id, in the onActivate even I re-read the bean, so that form will
> update an existing bean, however, even the cancel button triggers
> onActivate event as well. so moving the re-reading of bean to
> onSelectedFromUpdate seems a solution, but it's too late at that time as
> form has been submitted, any idea ? Thanks,
> 
> A.C.
> p.s. will be better if we can have an event before the form is submitted,
> that is onActivate, but we have no way to determine which button triggers
> the event there.
> 
> 
> Martin Kersten-2 wrote:
>> 
>> Hi A.C.
>> 
>>    I asked the very same question before but in conjunction with 
>> normal t:form component. Since the bean-editor is based on that t:form 
>> component it should apply to this scenario as well:
>> 
>> Rule of Thumb: If you have a button you have an onSelected event!
>> 
>> So in your case:
>> 
>> <t:form>
>>  <input t:type="submit" t:id="done" value="Done"/>  <input 
>> t:type="submit" t:id="failed" value="Failed"/> </t:form>
>> 
>> class MyPage {
>>    final int DONE = 0;
>>    final int FAILED = 1;
>> 
>>    int submitType = DONE;
>> 
>>    boolean onSelectedFromDone() {
>>       submitType = DONE;
>>       return true;
>>    }
>> 
>> 
>> 
> 
> --
> View this message in context:
> http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15846642.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
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15847228.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


AW: AW: T5: determine button clicked in a beaneditor

Posted by Martin Kersten <Ma...@mercateo.com>.
Hi Angelo,

   Are you using the onSuccess event?

Cheers,

Martin (Kersten)

-----Ursprüngliche Nachricht-----
Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
Gesendet: Mittwoch, 5. März 2008 10:48
An: users@tapestry.apache.org
Betreff: Re: AW: T5: determine button clicked in a beaneditor


Hi Martin,

The onSelected even happens after the form fields have been submitted, my need is to edit a Hibernate bean, what I'm doing now is: I persisted the bean's id, in the onActivate even I re-read the bean, so that form will update an existing bean, however, even the cancel button triggers onActivate event as well. so moving the re-reading of bean to onSelectedFromUpdate seems a solution, but it's too late at that time as form has been submitted, any idea ? Thanks,

A.C.
p.s. will be better if we can have an event before the form is submitted, that is onActivate, but we have no way to determine which button triggers the event there.


Martin Kersten-2 wrote:
> 
> Hi A.C.
> 
>    I asked the very same question before but in conjunction with 
> normal t:form component. Since the bean-editor is based on that t:form 
> component it should apply to this scenario as well:
> 
> Rule of Thumb: If you have a button you have an onSelected event!
> 
> So in your case:
> 
> <t:form>
>  <input t:type="submit" t:id="done" value="Done"/>  <input 
> t:type="submit" t:id="failed" value="Failed"/> </t:form>
> 
> class MyPage {
>    final int DONE = 0;
>    final int FAILED = 1;
> 
>    int submitType = DONE;
> 
>    boolean onSelectedFromDone() {
>       submitType = DONE;
>       return true;
>    }
> 
> 
> 

--
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15846642.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: AW: T5: determine button clicked in a beaneditor

Posted by Angelo Chen <an...@yahoo.com.hk>.
Hi Martin,

The onSelected even happens after the form fields have been submitted, my
need is to edit a Hibernate bean, what I'm doing now is: I persisted the
bean's id, in the onActivate even I re-read the bean, so that form will
update an existing bean, however, even the cancel button triggers onActivate
event as well. so moving the re-reading of bean to onSelectedFromUpdate
seems a solution, but it's too late at that time as form has been submitted,
any idea ? Thanks,

A.C.
p.s. will be better if we can have an event before the form is submitted,
that is onActivate, but we have no way to determine which button triggers
the event there.


Martin Kersten-2 wrote:
> 
> Hi A.C.
> 
>    I asked the very same question before but in conjunction 
> with normal t:form component. Since the bean-editor is based on
> that t:form component it should apply to this scenario as well:
> 
> Rule of Thumb: If you have a button you have an onSelected event!
> 
> So in your case:
> 
> <t:form>
>  <input t:type="submit" t:id="done" value="Done"/>
>  <input t:type="submit" t:id="failed" value="Failed"/>
> </t:form>
> 
> class MyPage {
>    final int DONE = 0;
>    final int FAILED = 1;
> 
>    int submitType = DONE;
> 
>    boolean onSelectedFromDone() {
>       submitType = DONE;
>       return true;
>    }
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15846642.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


AW: T5: determine button clicked in a beaneditor

Posted by Martin Kersten <Ma...@mercateo.com>.
Hi A.C.

   I asked the very same question before but in conjunction 
with normal t:form component. Since the bean-editor is based on
that t:form component it should apply to this scenario as well:

Rule of Thumb: If you have a button you have an onSelected event!

So in your case:

<t:form>
 <input t:type="submit" t:id="done" value="Done"/>
 <input t:type="submit" t:id="failed" value="Failed"/>
</t:form>

class MyPage {
   final int DONE = 0;
   final int FAILED = 1;

   int submitType = DONE;

   boolean onSelectedFromDone() {
      submitType = DONE;
      return true;
   }

   boolean onSelectedFromFailed() {
      submitType = FAILED;
      return true;
   }

   onSuccess() {
       switch(submitType) {
           case DONE:
             ...
           case FAILED:
             ...
           default:
             throw new UnsupportedOperationException(
                "unknown submit type");
       }
   }
}

If this works for you, can you do me a favor? 
Check out: 
http://wiki.apache.org/tapestry/Tapestry5HowToUseForms

And add this multi button handling. I am to buzzy right
now but I can do it as well at weekend.


Cheers,

Martin (Kersten)


-----Ursprüngliche Nachricht-----
Von: Angelo Chen [mailto:angelochen960@yahoo.com.hk] 
Gesendet: Mittwoch, 5. März 2008 04:03
An: users@tapestry.apache.org
Betreff: T5: determine button clicked in a beaneditor


Hi,

How to determine which button is clicked in the following case:

<t:form>
  <t:beaneditor>
  </t:beaneditor>

  <input type="submit" class="t-beaneditor-submit" value="Update"
id="update"/>
  <input type="submit" value="Cancel" id="cancel"/>  </t:form>

Thanks,

A.C.
--
View this message in context: http://www.nabble.com/T5%3A-determine-button-clicked-in-a-beaneditor-tp15841944p15841944.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