You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Arno Haase <ar...@haase-consulting.com> on 2013/01/15 15:54:13 UTC

Conditional rendering of HTML attribute

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

the following example is extremely simplified, but the underlying
problem is real.

I have a custom component with an optional parameter 'x'. If the
parameter is present, I want to render

<div myAttribute="${x}" t:id="abc">Hello</div>

otherwise I want the same thing but without the HTML attribute:

<div t:id="abc">Hello</div>



For technical reasons (I use a third-party JS framework) I do not want
to render an empty attribute but really remove the attribute from the
HTML output.

Using <t:if> with <p:else> requires the rendered <div> to have a
different t:id for both cases. I know why Tapestry introduces that
constraint, but it complicates stuff significantly in my situation.

So - any ideas or suggestions?

Thanks in advance

- - Arno

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with undefined - http://www.enigmail.net/

iEYEARECAAYFAlD1bZUACgkQbmZsMyUPuXR+rgCgzLVTUGUMQPT285dvEOS6sPUk
bNwAnjr9A+qpsmW/D3YcUoye85Dc0qLE
=BluL
-----END PGP SIGNATURE-----

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


Re: Conditional rendering of HTML attribute

Posted by Arno Haase <ar...@haase-consulting.com>.
That was exactly what I needed, works like a charm. Thanks!

Am 15.01.2013 17:48, schrieb Lance Java:
> Tapestry will only render an attribute that is not null. But you
> need to be aware of the following: 1. For foo="${x}" the value will
> be the empty string if getX() is null 2. For foo="prop:x" the value
> will be null if getX() is null
> 
> So it's best not to use ${x} for attribute values.
> 
> 
> 
> -- View this message in context:
> http://tapestry.1045711.n5.nabble.com/Conditional-rendering-of-HTML-attribute-tp5719323p5719330.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: Conditional rendering of HTML attribute

Posted by Lance Java <la...@googlemail.com>.
Tapestry will only render an attribute that is not null. But you need to be
aware of the following:
1. For foo="${x}" the value will be the empty string if getX() is null
2. For foo="prop:x" the value will be null if getX() is null

So it's best not to use ${x} for attribute values.



--
View this message in context: http://tapestry.1045711.n5.nabble.com/Conditional-rendering-of-HTML-attribute-tp5719323p5719330.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: Conditional rendering of HTML attribute

Posted by Thiago H de Paula Figueiredo <th...@gmail.com>.
On Tue, 15 Jan 2013 12:54:13 -0200, Arno Haase  
<ar...@haase-consulting.com> wrote:

> Hi,

Hi!

> So - any ideas or suggestions?

Write a mixin that writes or not the attribute depending on a mixin  
parameter.

-- 
Thiago H. de Paula Figueiredo

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