You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Martin Dietze <di...@fh-wedel.de> on 2007/07/02 12:34:46 UTC

Set component parameters from page class

Hi,

 I'd like to set some component paramameters ("disabled" for
inputs) from within my page classes. As far as I've seen so far
the usual way to do this would be to put a "name=${prop:value}"
attribute into my template. Can this also be done by using a
simple setter in my Java code? This would improv the templates'
readability a lot!

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Perl ist der gegl�ckte Versuch, einen braindump direkt ausf�hrbar zu
machen.  -- Lutz Donnerhacke in dasr

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


Re: Set component parameters from page class

Posted by Martin Dietze <di...@fh-wedel.de>.
On Mon, July 02, 2007, Massimo Lusetti wrote:

> > I'd like to set some component paramameters ("disabled" for
> >inputs) from within my page classes. As far as I've seen so far
> >the usual way to do this would be to put a "name=${prop:value}"
> >attribute into my template. Can this also be done by using a
> >simple setter in my Java code? This would improv the templates'
> >readability a lot!
> 
> Search through the archives for and old thread from the early days of
> T5, maybe you will find some hints.

Have you got any hint regarding title / keywords? I did a
search before I posted, but I did not find anyting appropriate,
maybe I just did not look for the right thing...

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Albert Camus wrote that the only serious question is whether to kill yourself
or not.  Tom Robbins wrote that the only serious question is whether time has
a beginning and an end.  Camus clearly got up on the wrong side of bed, and
Robbins must have forgotten to set the alarm.  -- Tom Robbins

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


Re: Set component parameters from page class

Posted by Massimo Lusetti <ml...@gmail.com>.
On 7/2/07, Martin Dietze <di...@fh-wedel.de> wrote:

> Hi,
>
>  I'd like to set some component paramameters ("disabled" for
> inputs) from within my page classes. As far as I've seen so far
> the usual way to do this would be to put a "name=${prop:value}"
> attribute into my template. Can this also be done by using a
> simple setter in my Java code? This would improv the templates'
> readability a lot!

Search through the archives for and old thread from the early days of
T5, maybe you will find some hints.

-- 
Massimo
http://meridio.blogspot.com

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


Re: Set component parameters from page class

Posted by Martin Dietze <di...@fh-wedel.de>.
On Mon, July 02, 2007, Francois Armand wrote:

>    @Component(parameters="disabled=prop:isdisabled")
>    private TextField textField;
>   
>    public boolean getIsdisabled() {
>        return disabled;
>    }
>    @SetupRender
>    void setup() {
>       if(should de disabled) {
>        disabled = true;
>       } else {
>          disabled = false;
>       }
>    }

This helped, thank you! 

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Steht ein Bratscher vor 'ner Kneipe.

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


Re: Set component parameters from page class

Posted by Francois Armand <fa...@linagora.com>.
Martin Dietze wrote:
> Yes, this is how I found it in the documentation. However I'd
> like to be able to do something like:
>
> | @Component(id="myInput")
> | private TextField _myInput;
>
> [...]
>
> | _myInput.setDisabled(true);
>   
You can use parameter expansion in Java code :

8<-----------------------
    @Component(parameters="disabled=prop:isdisabled")
    private TextField textField;
   
    public boolean getIsdisabled() {
        return disabled;
    }
    @SetupRender
    void setup() {
       if(should de disabled) {
        disabled = true;
       } else {
          disabled = false;
       }
    }
   
8<-------------------------

Francois

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


Re: Set component parameters from page class

Posted by Martin Dietze <di...@fh-wedel.de>.
On Mon, July 02, 2007, Francois Armand wrote:

> I'm not sure I have correctly understood your concern, so excuse me if I 
> answer to something else ;)
> When you have a component with parameter, you have two way to specify it 
> the actual parameter value :
> - in the template, with "paramname=bindingtype:value" ;
> - in the java code, thanks to "@Component(parameters =..." tag.

Yes, this is how I found it in the documentation. However I'd
like to be able to do something like:

| @Component(id="myInput")
| private TextField _myInput;

[...]

| _myInput.setDisabled(true);

Why this? I try to create encapsulate frequently-needed units
from my templates as components. E.g. you may want to use the
same HTML template (plus page class) for creating a user as
well as for modifying a user. Depending on the application
there may be some differences between the two applications of
the component, i.e. when modifying a user some properties are
read-only. 

Of course I can accomplish this with the code you posted, but 
this requires me to add the appropriate "parameters" annotation,
"paramname=bindingtype:value" plus a getter and setter for each
input I want to handle. Since the code already is pretty lengthy
anyway this will make it even messier.  

Doing this by a single setter per input at beginRender() would
be much simpler and readable.

Cheers,

Martin

-- 
----------- / http://herbert.the-little-red-haired-girl.org / -------------
=+= 
Was ist der Unterschied zwischen einer Bratsche und einer Waschmaschine?
Die Waschmaschine vibriert, kommt erst am Ende ins Schleudern, und was 
rauskommt, ist sauber.

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


Re: Set component parameters from page class

Posted by Francois Armand <fa...@linagora.com>.
Martin Dietze wrote:
> Hi,
>
>  I'd like to set some component paramameters ("disabled" for
> inputs) from within my page classes. As far as I've seen so far
> the usual way to do this would be to put a "name=${prop:value}"
> attribute into my template. Can this also be done by using a
> simple setter in my Java code? This would improv the templates'
> readability a lot!
I'm not sure I have correctly understood your concern, so excuse me if I 
answer to something else ;)
When you have a component with parameter, you have two way to specify it 
the actual parameter value :
- in the template, with "paramname=bindingtype:value" ;
- in the java code, thanks to "@Component(parameters =..." tag.

You can find documentation here :
http://tapestry.apache.org/tapestry5/tapestry-core/guide/component-classes.html
http://tapestry.apache.org/tapestry5/tapestry-core/guide/parameters.html

Francois

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