Attributes set in component inaccessible in template

29 views
Skip to first unread message

Winfield Trail

unread,
Mar 25, 2015, 10:57:22 AM3/25/15
to hippo-c...@googlegroups.com
I've been putting together a template in Hippo and have run into an odd problem. After creating a component and bean for my new document type, and setting the content attribute, I cannot access that object from the JSP template.

At first I thought my getters were broken, but it appears I can't pass anything to the template, even string literals.

In the component:
request.setAttribute("test", "i'm a seahorse");

In the template:
 <h2>${test}</h2>

As rendered in the browser:
<h2></h2>

Does anyone have insight? I popped the request variable open in the debugger and it didn't appear to have had the "test" variable applied anywhere. Maybe this is a quirk of the debugger, but since I can't interact with the attribute in any way from my JSP document, I sort of think it's right.

William Borg Barthet

unread,
Mar 25, 2015, 11:04:13 AM3/25/15
to hippo-c...@googlegroups.com
Hi Winfield,

this should work. Are you sure you are hitting the component code? Could it be that what you are running is out of sync with what you are seeing in the code?

You should be able to verify this by setting a breakpoint on the setAttribute line and make sure you hit it when you request the page. Make sure you recompile and check that your page configuration is pointing to the right class.

William

--
Hippo Community Group: The place for all discussions and announcements about Hippo CMS (and HST, repository etc. etc.)
 
To post to this group, send email to hippo-c...@googlegroups.com
RSS: https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
---
You received this message because you are subscribed to the Google Groups "Hippo Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hippo-communi...@googlegroups.com.
Visit this group at http://groups.google.com/group/hippo-community.
For more options, visit https://groups.google.com/d/optout.



--
Amsterdam - Oosteinde 11, 1017 WT Amsterdam
Boston - 745 Atlantic Avenue, Boston, MA 02111
 
US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

marijan milicevic

unread,
Mar 25, 2015, 12:31:03 PM3/25/15
to hippo-c...@googlegroups.com
On Wed, Mar 25, 2015 at 4:04 PM, William Borg Barthet <w.borg...@onehippo.com> wrote:
Hi Winfield,

this should work. Are you sure you are hitting the component code? Could it be that what you are running is out of sync with what you are seeing in the code?


this should work but *only* if template is processed by that component [1],
so, the question here is: is your component pointing to template through hst:template property [2]?
cheers
marijan

Winfield Trail

unread,
Mar 26, 2015, 7:40:51 AM3/26/15
to hippo-c...@googlegroups.com
Thanks for the feedback, gents:

this should work. Are you sure you are hitting the component code? Could it be that what you are running is out of sync with what you are seeing in the code?

The component code is definitely running, because any debug logging I put in the component gets printed to console and breakpoints set there freeze execution before the page is rendered. Perhaps it's possible that more than one component is executing, but that would seem to imply that there are multiple request objects as well.

I attempted to log the value of my string attribute, title, inside the JSP:

[INFO] [talledLocalContainer] An error occurred at line: 4 in the jsp file: /WEB-INF/jsp/SampleCaps.jsp
[INFO] [talledLocalContainer] title cannot be resolved to a variable
[INFO] [talledLocalContainer] 1: <%@ include file="/WEB-INF/jspf/htmlTags.jspf" %>
[INFO] [talledLocalContainer] 2: <%--@elvariable id="document" type="com.eastbanctech.paintnite.beans.SampleCapsDocument"--%>
[INFO] [talledLocalContainer] 3: 
[INFO] [talledLocalContainer] 4: <% System.out.println((String) title); %>

So the template really does seem to be totally unaware of my attributes. Is there a way to check the relativecontentpath/pathinfo from the template without passing that information in from the component?

so, the question here is: is your component pointing to template through hst:template property [2]?

Yes:


​ 

Drink Creatively,

Winfield Trail
Lead Programmer/The Batman
Boston HQ
(603) 558-0052


 

You received this message because you are subscribed to a topic in the Google Groups "Hippo Community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/hippo-community/ZmWCJ1IPe9w/unsubscribe.
To unsubscribe from this group and all its topics, send an email to hippo-communi...@googlegroups.com.

Bert Leunis

unread,
Mar 26, 2015, 7:53:55 AM3/26/15
to hippo-c...@googlegroups.com
Hi,
On Thu, Mar 26, 2015 at 12:40 PM, Winfield Trail <winf...@paintnite.com> wrote:
Thanks for the feedback, gents:

this should work. Are you sure you are hitting the component code? Could it be that what you are running is out of sync with what you are seeing in the code?

The component code is definitely running, because any debug logging I put in the component gets printed to console and breakpoints set there freeze execution before the page is rendered. Perhaps it's possible that more than one component is executing, but that would seem to imply that there are multiple request objects as well.

I attempted to log the value of my string attribute, title, inside the JSP:

[INFO] [talledLocalContainer] An error occurred at line: 4 in the jsp file: /WEB-INF/jsp/SampleCaps.jsp
[INFO] [talledLocalContainer] title cannot be resolved to a variable
[INFO] [talledLocalContainer] 1: <%@ include file="/WEB-INF/jspf/htmlTags.jspf" %>
[INFO] [talledLocalContainer] 2: <%--@elvariable id="document" type="com.eastbanctech.paintnite.beans.SampleCapsDocument"--%>
[INFO] [talledLocalContainer] 3: 
[INFO] [talledLocalContainer] 4: <% System.out.println((String) title); %>
Where do you expect that title data to come from? Either you would have set it in the java component, like

request.setAttribute("title", "i'm a seahorse");
 
or you expect the title field from your document to show up. In that case you need to write ${document.title} in the template.


So the template really does seem to be totally unaware of my attributes. Is there a way to check the relativecontentpath/pathinfo from the template without passing that information in from the component?

so, the question here is: is your component pointing to template through hst:template property [2]?

Yes:


​ 
The screenshot shows that on the selected hst:component node you defined your java class. There is no hst:template property defined that points to the jsp that should be used for this hst:component. It may be defined in the reference component (abstractpages/base). But I am guessing that the template and class should be defined on the SampleCaps/main childnode.

If you have working pages in your site (eventslist, eventspage?) compare the setup of those page configurations with your SampleCaps and spot the differences.

Winfield Trail

unread,
Mar 26, 2015, 8:29:14 AM3/26/15
to hippo-c...@googlegroups.com
Bert, I may be confused here, because you excerpted the code where I set the title attribute exactly that way:

request.setAttribute("test", "i'm a seahorse");

Additionally, the SampleCaps/main childnode has the hst:template property set to:

/hst:hst/hst:configurations/paintnite/hst:templates/SampleCaps

Aaaaand here's where I realized my mistake: hst:componentclassname was a property of hst:pages/SampleCaps, not hst:pages/SampleCaps/main. Facepalm forever.

So, this does lead me to a couple questions:
  1. Since the component was being invoked in both cases, why is it that adding attributes to request is only effective when the component is called for the SampleCaps/main child node?
  2. Is the request object not a singleton?

Drink Creatively,

Winfield Trail
Lead Programmer/The Batman
Boston HQ
(603) 558-0052


 

Bert Leunis

unread,
Mar 26, 2015, 8:40:50 AM3/26/15
to hippo-c...@googlegroups.com
On Thu, Mar 26, 2015 at 1:29 PM, Winfield Trail <winf...@paintnite.com> wrote:
Bert, I may be confused here, because you excerpted the code where I set the title attribute exactly that way:

request.setAttribute("test", "i'm a seahorse");
Oh yes, I forgot to update the snippet, I ment to write:

request.setAttribute("title", "i'm a seahorse");

 
Additionally, the SampleCaps/main childnode has the hst:template property set to:

/hst:hst/hst:configurations/paintnite/hst:templates/SampleCaps

Aaaaand here's where I realized my mistake: hst:componentclassname was a property of hst:pages/SampleCaps, not hst:pages/SampleCaps/main. Facepalm forever.

So, this does lead me to a couple questions:
  1. Since the component was being invoked in both cases, why is it that adding attributes to request is only effective when the component is called for the SampleCaps/main child node?
Request attributes are namespaced per component. Component A and B can both set request.attribute("document", xxx) without overriding each others attributes.
  1. Is the request object not a singleton?
Per request you have one request object that is the same for the whole request. It is not a singleton in the sense that is used in multiple requests, like the HST components.
If you want to use attributes on the request level, use the hst request context for that.  For example like: RequestContextProvider.get().setAttribute("x", ...)

Winfield Trail

unread,
Mar 26, 2015, 8:44:20 AM3/26/15
to hippo-c...@googlegroups.com
Ah, I see - in hindsight since most documents have a "title" attribute, not namespacing them would cause collisions when rendering multiple documents (which is almost always the case in Hippo.)

Thanks. :)

Drink Creatively,

Winfield Trail
Lead Programmer/The Batman
Boston HQ
(603) 558-0052


 

Reply all
Reply to author
Forward
0 new messages