Re: freemarker.template.TemplateModelException: Attribute with name not found

Daniel Dekany <[email protected]>
Newsgroups gmane.comp.web.freemarker.user
Message-ID <[email protected]>
Saturday, March 28, 2009, 12:42:28 PM, Amin Mohammed-Coleman wrote:

> Hi
>
> Thanks for getting back to me.  Much appreciated!  I am currently
> using tiles jsp tags through the freemarker jsp support.
>
> I have the
> followng definition in my web.xml:
>
>  <servlet>
>   <servlet-name>freemarker</servlet-name>
>  
> <servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class>
>   <init-param>
>    <param-name>TemplatePath</param-name>
>    <param-value>/</param-value>
>   </init-param>
>   <init-param>
>    <param-name>NoCache</param-name>
>    <param-value>true</param-value>
>   </init-param>
>   <init-param>
>    <param-name>ContentType</param-name>
>    <param-value>text/html</param-value>
>   </init-param>
>   <init-param>
>    <param-name>template_update_delay</param-name>
>    <param-value>0</param-value> <!-- 0 is for development only! Use higher value otherwise. -->
>   </init-param>
>   <init-param>
>    <param-name>default_encoding</param-name>
>    <param-value>ISO-8859-1</param-value>
>   </init-param>
>   <init-param>
>    <param-name>number_format</param-name>
>    <param-value>0.#####</param-value>
>   </init-param>
>   <load-on-startup>1</load-on-startup>
>  </servlet>
>    <servlet-mapping>
>         <servlet-name>freemarker</servlet-name>
>         <url-pattern>*.ftl</url-pattern>
>     </servlet-mapping>
>
> And my ftls have the following:
>
>
> <#assign tiles=JspTaglibs["http://tiles.apache.org/tags-tiles"] />.
>
> I am using freemarker 2.3.9.
>
> Are there freemarker tiles tags available from apache tiles?

You mean the non-JSP implementation? I seems I again jumped on shadow,
because that's not in Tiles 2.1.x branch, so I think that'not part of
any official Tiles release yet. So, then obviously you are using the
FreeMarker JSP support.


So... I guess the best would be if you debug this. Both when you use
JSP pages and FTL pages the same things should happen inside the Tiles
code, so the point where difference is leads to the culprit. I looked
at it for a moment, but the stuff seems to be quite complicated, so, I
have no clue what's could be that difference between real-JSP and
FreeMarer-JSP. Well, these are some the potentially interesting places
(at the first quick glance, mind you) where you might want to put
break-points:

This is where it sets the attribute:
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/RenderTag.java?view=markup

  attributeContext.putAttribute(nestedTag.getName(), attribute, nestedTag
                  .isCascade());
     |
     V
  attributeContext = container.startContext(pageContext);
     |
     V  
  container.startContext(pageContext)
     |
     V  
  container = JspUtil.getCurrentContainer(pageContext);

And this is where it reads back the attribute, which is, it seems,
mystically lost at that point:
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/taglib/AttributeTagSupport.java?revision=745006&view=markup

  attribute = attributeContext.getAttribute(name);
     |
     V  
  attributeContext = container.getAttributeContext(pageContext);
     |
     V  
  container = JspUtil.getCurrentContainer(pageContext);

If you look deeply into the "container" and "attributeContext"
variable values with the watch tab of your IDE, maybe there will be
some apparent difference when the pages are JSP-s VS when the pages
are FTL-s. I don't know, like with real-JSP the identity (memory
address) of the container objects are the same on both places, while
with FTL you get another instance for some reason... things like that.
BTW:

http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-jsp/src/main/java/org/apache/tiles/jsp/context/JspUtil.java?revision=745006&view=markup

          TilesContainer container = (TilesContainer) context.getAttribute(
                ServletUtil.CURRENT_CONTAINER_ATTRIBUTE_NAME,
                PageContext.REQUEST_SCOPE);

     |
     V  
                
http://svn.apache.org/viewvc/tiles/framework/branches/TILES_2_1_X/tiles-servlet/src/main/java/org/apache/tiles/servlet/context/ServletUtil.java?revision=745006&view=markup
                
    /**
     * Name of the attribute used to store the current used container.
     */
    public static final String CURRENT_CONTAINER_ATTRIBUTE_NAME =
        "org.apache.tiles.servlet.context.ServletTilesRequestContext.CURRENT_CONTAINER_KEY";

Another bug searching idea... What's if the top-level page is JSP and
the embedded on is FTL or the other way around? Then you can find out
if the problem is with the setting the attribute, or getting it (or
both).

> Thanks again!
>
> Amin
>
>
>
>
>
> On Sat, Mar 28, 2009 at 11:28 AM, Daniel Dekany <[email protected]> wrote:
> Saturday, March 28, 2009, 10:54:29 AM, Amin Mohammed-Coleman wrote:
>> Yep.  The it works with jsp.  It's only happening with freemarker,
>> I'm at the point of tearing my hair out and I don;t have much!
>
> Yeah, that's just an everyday thing for developers... BTW, I'm not the
> author of any of these software, so I'm not in charge more than you
> are. ;) But let's debug this stuff... I looked at the Tiles FreeMarker
> support on their SVN
> (http://svn.apache.org/viewvc/tiles/framework/trunk/tiles-freemarker/src/main/java/org/apache/tiles/freemarker/template/),
> and I see they have re-implemented the tags directly as FreeMarker
> directives, rather than wrapping the JSP tags using the FreeMarker JSP
> support. So that for one can cause differences... So, first of all,
> are you using those tags, or the JSP tags through FreeMarker JSP
> support?
>
>
>> Cheers
>> Amin
>>
>> 2009/3/28 Daniel Dekany <[email protected]>
>> Saturday, March 28, 2009, 9:08:21 AM, Amin Mohammed-Coleman wrote:
>>
>>> Hi
>>>
>>> I'm not sure if I follow. The personalContact is available outside the
>>> tags. It doesn't exist inside the tile definition.
>>
>> (Yeah, as I said in the earlier message, it was me who overlooked
>> something...)
>>
>> Did you try the same by using JSP-s instead of FTL-s? Does it work
>> that way?
>>
>>
>>> There must be a way to achieve this...
>>>
>>> Cheers
>>>
>>> Amin
>>>
>>>
>>> On 27 Mar 2009, at 23:49, Daniel Dekany <[email protected]> wrote:
>>>
>>>> Friday, March 27, 2009, 11:02:50 PM, amin1977 wrote:
>>>>
>>>>> Hi
>>>>>
>>>>> Sorry to bring this up again, however I was wondering if someone
>>>>> may be able
>>>>> to help with the below problem.  I have tried everything that I can
>>>>> think
>>>>> of.
>>>>
>>>> Well, the error message says that the JSP directive that you call has
>>>> no "personalContact" attribute. Are you sure it has it, exactly
>>>> written like that?
>>>>
>>>>>
>>>>> Cheers
>>>>> Amin
>>>>>
>>>>>
>>>>> amin1977 wrote:
>>>>>>
>>>>>> Hi
>>>>>>
>>>>>> I have a java object which I am passing into a tiles tag. For
>>>>>> example:
>>>>>>
>>>>>> I can print out pcobj outside of the tags
>>>>>>
>>>>>>
>>>>>> <@tiles.insertDefinition name="pagination.tile">
>>>>>>      <@tiles.putAttribute name="personalContact" value=pcobj />
>>>>>> </@tiles.insertDefinition>
>>>>>>
>>>>>>
>>>>>> in my pagination tile I am doing:
>>>>>>
>>>>>>
>>>>>> <@tiles.importAttribute name="personalContact" />
>>>>>>
>>>>>> EMAIL : ${personalContact.email} <br/>
>>>>>> FIRST NAME: ${personalContact.firstName} <br/>
>>>>>> LAST NAME: ${personalContact.lastName} <br/>
>>>>>>
>>>>>>
>>>>>> However I am getting the following
>>>>>>
>>>>>> Attribute with name 'personalContact' not found
>>>>>> The problematic instruction:
>>>>>> ----------
>>>>>> ==> user-directive tiles.importAttribute [on line 3, column 1 in
>>>>>> WEB-INF/freemarker/pagination.ftl]
>>>>>> ----------
>>>>>>
>>>>>> Java backtrace for programmers:
>>>>>> ----------
>>>>>> freemarker.template.TemplateModelException: Attribute with name
>>>>>> 'personalContact' not found
>>>>>>      at
>>>>>> freemarker.ext.jsp.TagTransformModel
>>>>>> $TagWriter.onStart(TagTransformModel.java:479)
>>>>>>      at freemarker.core.Environment.visit(Environment.java:230)
>>>>>>      at freemarker.core.UnifiedCall.accept(UnifiedCall.java:116)
>>>>>>      at freemarker.core.Environment.visit(Environment.java:196)
>>>>>>      at freemarker.core.MixedContent.accept(MixedContent.java:92)
>>>>>>      at freemarker.core.Environment.visit(Environment.java:196)
>>>>>>      at freemarker.core.Environment.process(Environment.java:176)
>>>>>>      at freemarker.template.Template.process(Template.java:232)
>>>>>>
>>>>>>
>>>>>> I would be grateful if anyone could advise me on what i'm doing
>>>>>> wrong..
>>>>>>
>>>>>> Cheers
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Best regards,
>>>> Daniel Dekany
>>>>
>>>
>>
>>
>> --
>> Best regards,
>>  Daniel Dekany
>>
>>
>>
>
>
> --
> Best regards,
>  Daniel Dekany

-- 
Best regards,
 Daniel Dekany


------------------------------------------------------------------------------
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.