Hi ffred,

On Mon, Jan 16, 2012 at 3:46 PM, ffred <ffre...@gmail.com> wrote:

> In fact it does work but not the way i thought :/
> The @BindParameter inject directly the TextField pointed by the for
> parameter of the label !
> I imagine it's related to the way the label class is implemented.
>

Exactly as it is supposed to be. The "for" parameter in the Label component
is of type org.apache.tapestry5.Field, so getting the text field is
expected. The fact that the for attribute is used something like:
<t:label for="myField" /> <t:textField t:id="myField" />
maybe confuses you. "myField" is not the client id of the textField
(although the id value may be "myField"), "myField" in this case is the
t:id of the component or, the tapestry (server) id for the textField
component which is unique in the page.

You can see this in the Label source where the default binding for the
"for" @Parameter is COMPONENT.
  @Parameter(name = "for", required = true, allowNull = false,
defaultPrefix = BindingConstants.COMPONENT)
    private Field field;

See [1] for more details.


>
> I simply first did a :
> @BindParamater("for") private String myFor ;
> which results in a TextField.toString() thing.
>

Yes. It coerces TextField to a String.


>
> It ended a couple of debug later in a @BindParamater("for") private
> TextField myFor ;
>

That's it you got it.


> from which i believed i will be able to get the 'id' but it fails again :
> although the myFor was a true real TextField object a lot of its properties
> were null, event in the @cleanRender phase, and of course so was my id ...
>
> For now, I still haven't found any way of getting the value of this stupid
> attribute !
>

Wait. You need the client ID of the textField as I understand. But if you
create a mixin on the label and use the label before the textField which is
the "for" parameter, than the clientId of the textField is not yet
generated.

>From the source of org.apache.tapestry5.corelib.base.AbstractField which is
a base class for TextField you can see that the Id is generated in the
setupRender phase.

So use textField.getClientId() but only after you are sure the Id of the
textField is generated. How?
See the tapestrydoc for Heartbeat [2].

The Form that surrounds the label and the textField starts a Heartbeat in
the beginRender phase and ends it in the afterRender phase, so you can just
use @HeartbeatDeferred to execute a method in your mixin that needs
textField.getClientId().


[1]: Using Binding Expressions
http://tapestry.apache.org/component-parameters.html#ComponentParameters-UsingBindingExpressions
[2]: org.apache.tapestry5.services.Heartbeat
http://tapestry.apache.org/5.3/apidocs/org/apache/tapestry5/services/Heartbeat.html

Cheers,
Dragan Sahpaski


>
>
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/5-2-how-to-read-the-for-attribute-of-a-t-label-in-a-mixin-tp5136617p5148901.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
>
>

Reply via email to