You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Markus Joschko <ma...@gmail.com> on 2008/08/27 22:53:42 UTC

Best action/event to setup a model?

Hi,
I am currently struggling to find the best way to setup a model for a
beandisplay from within a component.
As I have an ajax call included, the method should not only be called
during the render phase, but also during the action phase.

I looked at the form component (which fires a prepare event at
render&action requests) and it fires the event during

beginRender() and
onAction(EventContext ctx).

I can mimic this behavior in my page but it feels somehow wrong to
have these both methods just to setup the model.
I tried
@BeginRender
@OnEvent(value="action")
void setupModel()

however this method is never called during the action phase. I also
tried to put the EventContext parameter in the signature but that
doesn't help.
Can't I put two annotations on the same method? Is there any
difference between the naming convention and the annotation?

But hopefully there is an easier way to do this which I haven't found so far.

Thanks,
 Markus

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


Re: Best action/event to setup a model?

Posted by 9902468 <vi...@cerion.fi>.
And if you are performance oriented you use

    @Retain
    private BeanModel model;
    {
        model = beanModelSource.create(ProjectProposal.class, true,
messages);
        model.add("organization");
        model.add("financier");
        model.add("priorization", null);
    } 
    
    public BeanModel getModel(){
        return model;
    }

This way the model is generated _once_ and kept in the field through _all_
requests. Can be used as long as the model is the same for each and every
request. (And it usually is.)


Thiago H. de Paula Figueiredo wrote:
> 
> Em Thu, 28 Aug 2008 07:03:43 -0300, Markus Joschko
> <ma...@gmail.com> escreveu:
> 
>> Not sure if I get this. Wouldn't that make it quite hard to get hold
>> of the BeanModelSource service?
> 
> Sorry, I'm not following you.
> 
> I always do something like this:
> 
> @Inject
> private BeanModelSource beanModelSource;
> 
> @Inject
> private ComponentResources componentResources;
> 
> public BeanModel getBeanModel() {
> 	BeanModel model = beanModelSource.create(YourClass.class, false,
> componentResources);
> 	...
> 	return model;
> }
> 
> Thiago
> 
> ---------------------------------------------------------------------
> 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/Best-action-event-to-setup-a-model--tp19189515p19214055.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: Best action/event to setup a model?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 28 Aug 2008 17:11:09 -0300, Markus Joschko  
<ma...@gmail.com> escreveu:

> Thanks, I was completely focused on finding an event type to do this,
> so I have overseen that simple possibility.

Sometimes, Tapestry is so simple that people overlook the simplest choice.  
Nice! :)

Thiago

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


Re: Best action/event to setup a model?

Posted by Markus Joschko <ma...@gmail.com>.
Thanks, I was completely focused on finding an event type to do this,
so I have overseen that simple possibility.

On Thu, Aug 28, 2008 at 9:53 PM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> Em Thu, 28 Aug 2008 07:03:43 -0300, Markus Joschko
> <ma...@gmail.com> escreveu:
>
>> Not sure if I get this. Wouldn't that make it quite hard to get hold
>> of the BeanModelSource service?
>
> Sorry, I'm not following you.
>
> I always do something like this:
>
> @Inject
> private BeanModelSource beanModelSource;
>
> @Inject
> private ComponentResources componentResources;
>
> public BeanModel getBeanModel() {
>        BeanModel model = beanModelSource.create(YourClass.class, false,
> componentResources);
>        ...
>        return model;
> }
>
> Thiago
>
> ---------------------------------------------------------------------
> 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: Best action/event to setup a model?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Thu, 28 Aug 2008 07:03:43 -0300, Markus Joschko
<ma...@gmail.com> escreveu:

> Not sure if I get this. Wouldn't that make it quite hard to get hold
> of the BeanModelSource service?

Sorry, I'm not following you.

I always do something like this:

@Inject
private BeanModelSource beanModelSource;

@Inject
private ComponentResources componentResources;

public BeanModel getBeanModel() {
	BeanModel model = beanModelSource.create(YourClass.class, false,
componentResources);
	...
	return model;
}

Thiago

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


Re: Best action/event to setup a model?

Posted by Markus Joschko <ma...@gmail.com>.
Not sure if I get this. Wouldn't that make it quite hard to get hold
of the BeanModelSource service?

On Thu, Aug 28, 2008 at 11:34 AM, Thiago H. de Paula Figueiredo
<th...@gmail.com> wrote:
> Em Wed, 27 Aug 2008 17:53:42 -0300, Markus Joschko
> <ma...@gmail.com> escreveu:
>
>> Hi,
>> I am currently struggling to find the best way to setup a model for a
>> beandisplay from within a component.
>
> My 2 cents: in your BeanModel getBeanModel() method.
>
> Thiago
>
> ---------------------------------------------------------------------
> 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: Best action/event to setup a model?

Posted by "Thiago H. de Paula Figueiredo" <th...@gmail.com>.
Em Wed, 27 Aug 2008 17:53:42 -0300, Markus Joschko  
<ma...@gmail.com> escreveu:

> Hi,
> I am currently struggling to find the best way to setup a model for a
> beandisplay from within a component.

My 2 cents: in your BeanModel getBeanModel() method.

Thiago

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


Re: Best action/event to setup a model?

Posted by "Filip S. Adamsen" <fs...@fsadev.com>.
Hi Markus,

Is the BeanDisplay component inside a form? In that case,

   @OnEvent("prepare")
   void setupModel() { ... }

should be called whenever the form is preparing to be rendered or submitted.

Is there any reason you can't setup your model once and just reference 
it from there? Just curious.

-Filip

On 2008-08-27 22:53, Markus Joschko wrote:
> Hi,
> I am currently struggling to find the best way to setup a model for a
> beandisplay from within a component.
> As I have an ajax call included, the method should not only be called
> during the render phase, but also during the action phase.
> 
> I looked at the form component (which fires a prepare event at
> render&action requests) and it fires the event during
> 
> beginRender() and
> onAction(EventContext ctx).
> 
> I can mimic this behavior in my page but it feels somehow wrong to
> have these both methods just to setup the model.
> I tried
> @BeginRender
> @OnEvent(value="action")
> void setupModel()
> 
> however this method is never called during the action phase. I also
> tried to put the EventContext parameter in the signature but that
> doesn't help.
> Can't I put two annotations on the same method? Is there any
> difference between the naming convention and the annotation?
> 
> But hopefully there is an easier way to do this which I haven't found so far.
> 
> Thanks,
>  Markus
> 
> ---------------------------------------------------------------------
> 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