Hi Nicolas,
big thanks for your response. It explained me a lot.

I'm

Nicolas LE BAS pisze:
I'm not sure what you mean by "changing" a tiles definition.
Changing its attributes, adding, deleting.



Basically a tiles definition is a singleton object, shared by all threads in the server, like a Servlet. Modifying this objet in an ActionListener, i.e. for the purpose of fulfilling a single request, doesn't sound safe.
Yep, i didn't know this. I thought that Tiles stores a copy of definition for a single, particular request.

But why should you want to do this on a per-request basis? I cannot think of any use case right now...
I'll explain what I was testing when I downloaded Tiles

layout page (I will omit taglib imports etc.)

<f:view>
   <html>
       <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
           <title>JSP Page</title>
       </head>
       <body>
           <tiles:insertAttribute name="part1" />
       </body>
   </html>
</f:view>

simple tile with action

<h1><h:outputText value="hello" /></h1>
<h:form>
   <h:commandLink action="#{MyBean.doWork}">Do Work</h:commandLink>
</h:form>

Tiles definition:

<tiles-definitions>
    <definition name="def" template="/layout.jsp">
       <put-attribute name="part1" value="/part.jsp" />
   </definition>
</tiles-definitions>

and one and only one page:

start.jsp
<tiles:insertDefinition name="def">
   <tiles:putAttribute name="part1" value="/tile.jsp"/>
</tiles:insertDefinition>

and for example in MyBean method doWork i don't want to return any outcome and display new page but simply modify (for example add a new attribute) definition "def" and then redisplay the page start.jsp.


Additionally, adopting a more philosophical point of view, I believe your MVC2 controller should not be aware of the structure of its view. You should not have to modify the backing bean if you decide to render the view using Plain Old JSP or Facelets instead of Tiles, or if you want to redesign your Tiles Definition (put the menu on the top of the page, when it was on the left).
That's true. I'm new in all this jsf and mvc concepts, so I was a little confused.
I don't want to use Facelets - Tiles are more clear for me.

Therefore I believe that referencing Tiles in an ActionListener or Backing Bean is not a good programming practice. It would be better to reference a request attribute (or even better: a Backing Bean property) both in the ActionListener and the Tiles Definition. It would keep both technologies unaware of each other, and I believe things would evolve more smoothly afterwards.

What do you think ?
This is the best solution and this is a way I'll go.

Thanks a lot for your hints!

Regards

Reply via email to