BaTien Duong wrote:

Thanks Cedric. You save us a day! 3 more items to be sure:

1) Assuming we have *myAttribute* from *myBean* in user session
myBean.getLevel2().getMyAttribute(). To use myAttribute as a JSP Java
variable, we need:
//set an attribute for tile insert
<tiles:insert attribute="myAttribute" />
<tiles:put name="myAttribute" beanName="myBean"
beanScope="session" beanProperty="level2.myAttribute" />
</tiles:insert>


This declare a tile attribute initialized from your bean. This attribute can be used in the inserted tile only, not in the current page

        //declare a Java variable for JSP usage
        <tiles:useAttribute name="myAttribute" scope="request" />

This can be done in the inserted tile only. It declare a java variable and a bean in the "request" scope. A java variable is only visible inside the jsp page where it is declared. The bean is visible in its scope.


// myAttribute is now available for all sub tiles in the jsp <%= myAttribute ... %>

NO ! The java variable is not visible in sub tiles because they are other jsps. But the bean stored in the request scope is visible. so, you can retrieve it from the scope:
<bean:define .../>



2) Assuming now level2 is a HashMap and myAttributeName is the key corresponding to myAttribute value: myAttribute = (HashMap myBean.getLevel2()).get("myAttributeName") the beanProperty can be set: beanProperty="level2.myAttributeName"

I don't remember the exact syntax for accessing hashmap. It is the same syntax used in Struts tags.


3) Assuming as in (2) but myAttribute is now a property of level2Obj, which is the value of myAttributeName key: myAttribute = ( Level2Obj (HashMap myBean.getLevel2()).get("myAttributeName").getMyAttribute(), the beanProperty can be set: beanProperty="level2.myAttributeName.myAttribute"

It should work. In fact Tiles use the BeanUtils library. So, if this library support it, Tiles support it also.

Cedric


Thanks.



-----Original Message----- From: Cedric Dumoulin [mailto:[EMAIL PROTECTED] Sent: Monday, March 03, 2003 9:35 AM To: Struts Users Mailing List Subject: Re: Setting tiles attributes from a bean in different scopes



Hi,

BaTien Duong wrote:



Hello Cedric and the group:

Issue: need to retrieve properties of *myBean* in user session scope as
values for tiles attributes in request scope.



 You can't set the scope of a tiles attribute: a tiles attribute is
defined with <put> nested in an <insert>. A tile attribute is always in
the tiles scope (the tiles context). However, you can import
(<importAttribute>) a tile attribute in any jsp scope, or use
it (<useAttribute>) as java variable.
 So, I don't clearly see what you are trying to do ;-).



Solution from a scratch of my head:
        <jsp:useBean id="myBean" scope="session" />
        <tiles:useAttribute id="myAttribute" name="myAttribute" scope="request"
className="java.lang.String" />
        <tiles:put name="myAttribute" beanName="myBean" beanProperty="myAttribute"
/>




 This code is not valid because the <put> tag should be nested inside
an <insert> tag.



Questions:
        1) The bean and attribute are in different scopes. Can one set tile
attributes from session scope?



 You can set an attribute from a bean stored in any scope:
<tiles:insert ...>
 <tiles:put name="myAttribute" beanName="myBean" beanScope="session" />
</tiles:insert>
 This declare and set an attribute for the tile to be inserted. The
attribute is called "myAttribute", its value is taken from the bean
"myBean" which is in the "session" scope.



        2) Is there a faster way to assign an attribute at the time of
initialization in <useAttribute> tag so we do not need <jsp:useBean> and
<tiles:put> tags?



 <useAttribute .../> tag is used to declare a java variable inside the
jsp page. This variable is initialized from an attribute of the current
tiles. This attribute has been passed to the current tiles. A side
effect of this tag is to declare also a bean in one of the jsp scope.



        3) Assuming myAttribute is a nested level of myBean ( i.e.
getMyBean().getMyLevel2().getMyAttribute() ), is there an EL way similar to
JSTL?



 Remind that you can use the dot separator in the bean property name:
beanProperty="myLevel2.myAttribute"

Cedric



Thanks?


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]








---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]






---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to