You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Lukasz Lenart <lu...@apache.org> on 2016/09/06 17:31:35 UTC

Tiles & I18N

Hi,

I'm working on solution to add support for directly fetching I18N keys
from Struts properties instead of using multiple tiles.xml
definitions. It will be possible to define a key directly in tiles.xml
as follow

<definition name="home" extends="logged-in">
  <put-attribute name="title" expression="S2:home.title"/>
  <put-attribute name="body" value="/WEB-INF/tiles/home.jsp"/>
</definition>

and S2:home.title will be first evaluated as a key in resource bundle
and then as a value from ValueStack. Does it make sense?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Lukasz Lenart <lu...@apache.org>.
2016-09-06 23:21 GMT+02:00 Ken McWilliams <ke...@gmail.com>:
> It's been some time but I'm pretty sure I was able to access the ValueStack
> from within tiles definitions using the OGNL prefix. I didn't do any I18N
> stuff from it...
>
> Taking a look at WW-4685, the request makes sense but it does not entirely
> remove the need to tiles internationalization. In the case of right to left
> languages it isn't just a matter of replacing bits of text but there could
> be good reason to use a different layout entirely. Anyways with WW-4685
> implemented it would be better all round.
>
> I have a feeling that the use-case in WW-4685 could be made to work along
> the lines of: "OGNL:magicAccessor(''home.title)"
>
> This is from memory and it was quite some time ago, if the current
> struts2-tiles plugin does not allow for the OGNL EL prefix in tiles then
> this is really a must.

It is supported but I don't know how to construct an expression as the
Root is set to Tiles' JspRequest, so maybe it is possible to access
Struts' ValueStack but I don't know how.

> If the resource bundles are searched first, there could be name collisions?
> Perhaps each prefix should just do one thing? "OGNL:" for value stack and
> "I18N:" for the resource bundles?

I thought about the same, what if I define two prefixes:
- S2 to access values on ValueStack, e.g. S2:propertyOnAction
- I18N to resolve expression as a key from resource bundles, e.g.
I18N:key.from.bundle


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Ken McWilliams <ke...@gmail.com>.
It's been some time but I'm pretty sure I was able to access the ValueStack
from within tiles definitions using the OGNL prefix. I didn't do any I18N
stuff from it...

Taking a look at WW-4685, the request makes sense but it does not entirely
remove the need to tiles internationalization. In the case of right to left
languages it isn't just a matter of replacing bits of text but there could
be good reason to use a different layout entirely. Anyways with WW-4685
implemented it would be better all round.

I have a feeling that the use-case in WW-4685 could be made to work along
the lines of: "OGNL:magicAccessor(''home.title)"

This is from memory and it was quite some time ago, if the current
struts2-tiles plugin does not allow for the OGNL EL prefix in tiles then
this is really a must.

If the resource bundles are searched first, there could be name collisions?
Perhaps each prefix should just do one thing? "OGNL:" for value stack and
"I18N:" for the resource bundles?


On Tue, Sep 6, 2016 at 1:25 PM, Lukasz Lenart <lu...@apache.org>
wrote:

> https://issues.apache.org/jira/browse/WW-4685
>
> 2016-09-06 20:59 GMT+02:00 Lukasz Lenart <lu...@apache.org>:
> > 2016-09-06 20:20 GMT+02:00 Ken McWilliams <ke...@gmail.com>:
> >> It makes sense. Is there a way to currently access the i18n values using
> >> the OGNL prefix?
> >
> > Nope, with OGNL prefix you can only access Tiles related attributes
> > (as far I understand)
> >
> >
> > Regards
> > --
> > Łukasz
> > + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>


-- 
Sent from my C64 using a 300 baud modem

Re: Tiles & I18N

Posted by Lukasz Lenart <lu...@apache.org>.
https://issues.apache.org/jira/browse/WW-4685

2016-09-06 20:59 GMT+02:00 Lukasz Lenart <lu...@apache.org>:
> 2016-09-06 20:20 GMT+02:00 Ken McWilliams <ke...@gmail.com>:
>> It makes sense. Is there a way to currently access the i18n values using
>> the OGNL prefix?
>
> Nope, with OGNL prefix you can only access Tiles related attributes
> (as far I understand)
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Lukasz Lenart <lu...@apache.org>.
2016-09-06 20:20 GMT+02:00 Ken McWilliams <ke...@gmail.com>:
> It makes sense. Is there a way to currently access the i18n values using
> the OGNL prefix?

Nope, with OGNL prefix you can only access Tiles related attributes
(as far I understand)


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Ken McWilliams <ke...@gmail.com>.
It makes sense. Is there a way to currently access the i18n values using
the OGNL prefix?

On Tue, Sep 6, 2016 at 11:31 AM, Lukasz Lenart <lu...@apache.org>
wrote:

> Hi,
>
> I'm working on solution to add support for directly fetching I18N keys
> from Struts properties instead of using multiple tiles.xml
> definitions. It will be possible to define a key directly in tiles.xml
> as follow
>
> <definition name="home" extends="logged-in">
>   <put-attribute name="title" expression="S2:home.title"/>
>   <put-attribute name="body" value="/WEB-INF/tiles/home.jsp"/>
> </definition>
>
> and S2:home.title will be first evaluated as a key in resource bundle
> and then as a value from ValueStack. Does it make sense?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>


-- 
Sent from my C64 using a 300 baud modem

Re: Tiles & I18N

Posted by Lukasz Lenart <lu...@apache.org>.
2016-09-07 21:47 GMT+02:00 Ken McWilliams <ke...@gmail.com>:
> @Lukasz I'm not sure about the OGNL access... I'm pretty confident that it
> worked without any input on my part. But I probably was only accessing
> simply properties on the actions. So while I did apply the OGNL prefix, it
> might have been getting the values from the JSP wrapper (probably wrong
> term), like using plain EL in a JSP? I think the OGNL in tiles has it's own
> implementation/engine, so while OGNL expression would work maybe it wasn't
> getting the data from where I thought... in any case it did work at the
> time ;)

It's the same OGNL and the same engine, problem is OgnlContext which
is used as a sandbox to run OGNL expressions. In Tiles the root is set
to JspRequest but OGNL searches down the tree to find a value, so
maybe that's why it worked for you.


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Ken McWilliams <ke...@gmail.com>.
@Greg Huber
It should be possible to use the struts2 conventions to establish titles,
as I have tiles even for the header block (keeps JSPs, CSS constant where
it should be constant) it is then required to set the page title
programmatically. Also tiles supports multiple types of expressions with a
prefix so in a few cases you'll want to push in content from struts
(consider a wiki where the whole body is fetched from a db) I find myself
relying on the REGEX
 prefix such that struts conventions are extended though to the formatting.
That is, parts of the matched action are used to locate the page body, just
as you would expect from conventions but that the page is also templated as
per tiles.

@Lukasz I'm not sure about the OGNL access... I'm pretty confident that it
worked without any input on my part. But I probably was only accessing
simply properties on the actions. So while I did apply the OGNL prefix, it
might have been getting the values from the JSP wrapper (probably wrong
term), like using plain EL in a JSP? I think the OGNL in tiles has it's own
implementation/engine, so while OGNL expression would work maybe it wasn't
getting the data from where I thought... in any case it did work at the
time ;)

On Wed, Sep 7, 2016 at 1:24 AM, Lukasz Lenart <lu...@apache.org>
wrote:

> 2016-09-07 9:19 GMT+02:00 Greg Huber <gr...@gmail.com>:
> > aren't tiles definitions more layout oriented and more static in nature?
> > Where would you actually use the "title" attribute?
> >
> > <tiles:insertAttribute name="title" />
>
> As a page <title> tag and/or as a page header e.g.
> <h1><tiles:insertAttribute name="title" /></h1> - it's useful when
> these tags are placed in the main layout.jsp
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>


-- 
Sent from my C64 using a 300 baud modem

Re: Tiles & I18N

Posted by Lukasz Lenart <lu...@apache.org>.
2016-09-07 9:19 GMT+02:00 Greg Huber <gr...@gmail.com>:
> aren't tiles definitions more layout oriented and more static in nature?
> Where would you actually use the "title" attribute?
>
> <tiles:insertAttribute name="title" />

As a page <title> tag and/or as a page header e.g.
<h1><tiles:insertAttribute name="title" /></h1> - it's useful when
these tags are placed in the main layout.jsp


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Re: Tiles & I18N

Posted by Greg Huber <gr...@gmail.com>.
aren't tiles definitions more layout oriented and more static in nature?
Where would you actually use the "title" attribute?

<tiles:insertAttribute name="title" />






On 6 September 2016 at 18:31, Lukasz Lenart <lu...@apache.org> wrote:

> Hi,
>
> I'm working on solution to add support for directly fetching I18N keys
> from Struts properties instead of using multiple tiles.xml
> definitions. It will be possible to define a key directly in tiles.xml
> as follow
>
> <definition name="home" extends="logged-in">
>   <put-attribute name="title" expression="S2:home.title"/>
>   <put-attribute name="body" value="/WEB-INF/tiles/home.jsp"/>
> </definition>
>
> and S2:home.title will be first evaluated as a key in resource bundle
> and then as a value from ValueStack. Does it make sense?
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
>