componentWindow attribute

48 views
Skip to first unread message

ricardo...@incentro.com

unread,
May 12, 2015, 9:11:49 AM5/12/15
to hippo-c...@googlegroups.com
From my jsp template I want to access child containers to check the attributes that are set within the child containers. I do this with componentWindow

But whenever I try to use componentWindow.getAttribute("my-attribute") or componentWindow.getAttributeNames() nothing is returned while I know the attribute is on the request.


<hst:defineObjects/>
<div class="grid">
<c:if test="${not empty hstResponse.childContentNames}"> 
<c:forEach var="child" items="${hstResponse.childContentNames}">
<c:set var="componentWindow" value="${hstRequest.componentWindow}"/>
                         .....


</c:forEach>
</c:if>
</div>



Does anybody know how to make this work, or suggest another approach to access attributes from child containers.

Ard Schrijvers

unread,
May 15, 2015, 5:17:33 AM5/15/15
to hippo-c...@googlegroups.com
Hey Ricardo,

On Tue, May 12, 2015 at 3:11 PM, <ricardo...@incentro.com> wrote:
> From my jsp template I want to access child containers to check the
> attributes that are set within the child containers. I do this with
> componentWindow
>
> But whenever I try to use componentWindow.getAttribute("my-attribute") or
> componentWindow.getAttributeNames() nothing is returned while I know the
> attribute is on the request.
>
>
> <hst:defineObjects/>
> <div class="grid">
> <c:if test="${not empty hstResponse.childContentNames}">
> <c:forEach var="child" items="${hstResponse.childContentNames}">
> <c:set var="componentWindow" value="${hstRequest.componentWindow}"/>

hstRequest.componentWindow will return you the componentWindow of the
current component, and you seem to want to access attributes from the
child component windows.

Hence instead you have to loop through hstRequest.componentWindow.childWindowMap

Note however that you are on thin ice, because
hstRequest.componentWindow (aka HstRequestImpl#getComponentWindow) is
*not* an api method (not on HstRequest but on HstRequestImpl)

> .....
>
>
> </c:forEach>
> </c:if>
> </div>
>
>
>
> Does anybody know how to make this work, or suggest another approach to
> access attributes from child containers.

The HstRequestContext is shared between all components. Normally, the
request context is used to set / get attributes across components

Regards Ard

>
> --
> 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.



--
Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
Hippo USA, Inc.- 745 Atlantic Ave, Eight Floor, Boston MA 02111,
United states of America.

US +1 877 414 4776 (toll free)
Europe +31(0)20 522 4466
www.onehippo.com

ricardo...@incentro.com

unread,
May 18, 2015, 7:06:13 AM5/18/15
to hippo-c...@googlegroups.com
Hello Ard,

thank you for your answer. I already noticed the function is not an api method, but it's currently used in or project to access child component windows. If there is another way to do this I'd gladly like to know how.

The code I send in my post wasn't complete. You are correct I still need to loop through the child component windows. This works like expected. When I "found" the child component window I need, I try to get the attributes by using componentWindow.getAttribute("my-attribute") or componentWindow.getAttributeNames() but nothing is returned while I know there are attributes on the request for that child window component.

Even while looping through the window components, none of the window components seem to have attributes when I use componentWindow.getAttributeNames()


Op vrijdag 15 mei 2015 11:17:33 UTC+2 schreef a.schrijvers:

Ard Schrijvers

unread,
May 18, 2015, 7:18:33 AM5/18/15
to hippo-c...@googlegroups.com
On Mon, May 18, 2015 at 1:06 PM, <ricardo...@incentro.com> wrote:
> Hello Ard,
>
> thank you for your answer. I already noticed the function is not an api
> method, but it's currently used in or project to access child component
> windows. If there is another way to do this I'd gladly like to know how.
>
> The code I send in my post wasn't complete. You are correct I still need to
> loop through the child component windows. This works like expected. When I
> "found" the child component window I need, I try to get the attributes by
> using componentWindow.getAttribute("my-attribute") or
> componentWindow.getAttributeNames() but nothing is returned while I know
> there are attributes on the request for that child window component.

componentWindow.getAttribute(String) does not return attributes from
the HstRequest that belongs to that component window. You could try to
access request attributes via namespaced attribute on the plain http
servlet request. However, personally, I doubt whether you are on the
right track. If you want to share attributes between components, you
normally do this via the HstRequestContext, not the HstRequest. We
could even already dispose child HstRequest objects after its renderer
has been executed. We don't do it currently, and I don't think we will
in the future, but it is just to indicate you are on thin ice.

Either way, see the HstRequestImpl#setAttribute logic wrt
getFullNamespacePrefix how to access a namespaced attribute from the
backing http servlet request

Regards Ard

ricardo...@incentro.com

unread,
May 19, 2015, 3:32:04 AM5/19/15
to hippo-c...@googlegroups.com
Is it correct when I say you can access an attribute from a specific child component via the HstRequestContext?
If so... could you provide an example on how to this?

Op maandag 18 mei 2015 13:18:33 UTC+2 schreef a.schrijvers:

Ard Schrijvers

unread,
May 20, 2015, 4:38:48 AM5/20/15
to hippo-c...@googlegroups.com
On Tue, May 19, 2015 at 9:32 AM, <ricardo...@incentro.com> wrote:
> Is it correct when I say you can access an attribute from a specific child
> component via the HstRequestContext?
> If so... could you provide an example on how to this?

Any object you set on the HstRequestContext via setAttribute is
available by every other component via getAttribute.

Regards Ard

Woonsan Ko

unread,
May 20, 2015, 6:30:17 AM5/20/15
to hippo-c...@googlegroups.com


   
On May 20, 2015 4:38 AM, "Ard Schrijvers" <a.schr...@onehippo.com> wrote:
>
> On Tue, May 19, 2015 at 9:32 AM,  <ricardo...@incentro.com> wrote:
> > Is it correct when I say you can access an attribute from a specific child
> > component via the HstRequestContext?
> > If so... could you provide an example on how to this?
>
> Any object you set on the HstRequestContext via setAttribute is
> available by every other component via getAttribute.

Also please note that it depends on the execution order of components in hierarchy.
Plz see the section 5 here:
- http://www.onehippo.org/library/concepts/request-handling/hst-2-request-processing.html

So we can say it's always safe to set a hstRequestContext attribute in parent component and let child component use it in #doBeforeRender() phase.
But it's impossible the other way around, and it's not safe doing that in sibling childs as a result..

Regards,

Woonsan

Ard Schrijvers

unread,
May 20, 2015, 6:44:16 AM5/20/15
to hippo-c...@googlegroups.com
On Wed, May 20, 2015 at 12:30 PM, Woonsan Ko <w....@onehippo.com> wrote:
>
>
> On May 20, 2015 4:38 AM, "Ard Schrijvers" <a.schr...@onehippo.com> wrote:
>>
>> On Tue, May 19, 2015 at 9:32 AM, <ricardo...@incentro.com> wrote:
>> > Is it correct when I say you can access an attribute from a specific
>> > child
>> > component via the HstRequestContext?
>> > If so... could you provide an example on how to this?
>>
>> Any object you set on the HstRequestContext via setAttribute is
>> available by every other component via getAttribute.
>
> Also please note that it depends on the execution order of components in
> hierarchy.
> Plz see the section 5 here:
> -
> http://www.onehippo.org/library/concepts/request-handling/hst-2-request-processing.html
>
> So we can say it's always safe to set a hstRequestContext attribute in
> parent component and let child component use it in #doBeforeRender() phase.
> But it's impossible the other way around, and it's not safe doing that in
> sibling childs as a result..

This is correct in doBeforeRender phase but Ricardo was trying to
fetch the objects in 'render' phase (namely he mentioned his jsp
template) and during that phase, all component's their doBeforeRender
have finished.

Regards Ard

Woonsan Ko

unread,
May 20, 2015, 7:21:06 AM5/20/15
to hippo-c...@googlegroups.com
On 5/20/15 6:44 AM, Ard Schrijvers wrote:
> On Wed, May 20, 2015 at 12:30 PM, Woonsan Ko <w....@onehippo.com> wrote:
>>
>>
>> On May 20, 2015 4:38 AM, "Ard Schrijvers" <a.schr...@onehippo.com> wrote:
>>>
>>> On Tue, May 19, 2015 at 9:32 AM, <ricardo...@incentro.com> wrote:
>>>> Is it correct when I say you can access an attribute from a specific
>>>> child
>>>> component via the HstRequestContext?
>>>> If so... could you provide an example on how to this?
>>>
>>> Any object you set on the HstRequestContext via setAttribute is
>>> available by every other component via getAttribute.
>>
>> Also please note that it depends on the execution order of components in
>> hierarchy.
>> Plz see the section 5 here:
>> -
>> http://www.onehippo.org/library/concepts/request-handling/hst-2-request-processing.html
>>
>> So we can say it's always safe to set a hstRequestContext attribute in
>> parent component and let child component use it in #doBeforeRender() phase.
>> But it's impossible the other way around, and it's not safe doing that in
>> sibling childs as a result..
>
> This is correct in doBeforeRender phase but Ricardo was trying to
> fetch the objects in 'render' phase (namely he mentioned his jsp
> template) and during that phase, all component's their doBeforeRender
> have finished.

Yeah, I know that his initial example was presented in jsp templates. :)

@Ricardo, anyway, it's important to note the execution order when
setting/using hstRequestContext attributes.
HST Container invokes #doBeforeRender() of each component in
parent-to-child order. After that, it dispatches to each render template
in child-to-parent order.
You won't be able to read an attribute before setting in a pre-executed
location.

Regards,

Woonsan
w....@onehippo.com www.onehippo.com
Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
Amsterdam - Oosteinde 11, 1017 WT Amsterdam

ricardo...@incentro.com

unread,
May 21, 2015, 10:19:13 AM5/21/15
to hippo-c...@googlegroups.com
Hello thank you for the response.

The issue is the following: The project I work on uses a grid.jsp.
In this grid.jsp the hstResponse.childContentNames are iterated. The child names are "row1", "row2", etc.

The challange is to find out if the row has content or not. If there is no content the row should not be rendered.

Content within a row exisits of catalog items. Right now if one or more catlogitems are found (by iterating through childWindowMap) then the row will be rendered <div class="row">...</div>

The problem is that it is possible that the catalog item will not render content (html). This is possible because of missing content in the content bean.

This was a design choice. It is not allowed to remove the catalog item

Therefor I wanted to find out if there are certain attributes on the request per catalog item.

----- 

Since this isn't possible, we would like to try another approach. We want to store the hst:include in a variable to see if there is any content. But the project runs on 7.8.9 and this feature is only available in 7.10. Can't seem to find the page on onehippo.org about the hst:include anymore.

Is there a way to update the taglib to version 7.10 while making it work with 7.8.9?


Also if you have an idea on how to approach my issue differently any suggestion is welcome.




Op woensdag 20 mei 2015 13:21:06 UTC+2 schreef w.ko:

Woonsan Ko

unread,
May 21, 2015, 12:08:18 PM5/21/15
to hippo-c...@googlegroups.com
Hi,

So, you have already tried two different approaches:
(a) how to determine if a child catalog item component has rendered
content by attributes somehow,
(b) the new feature (https://issues.onehippo.com/browse/HSTTWO-2183)
available only in 10.

Regarding the approach (a), I initially thought that you could achieve
your goal easily with that, but it seems hard or almost impossible.
For example, if the child catalog item component was able to check the
status of contentBean and set hstRequestContext attribute to a flag
value with the its own componentWindow name as attribute name, then the
parent component could have been able to check the flag attributes by
iterated key from HstResponse#getChildContentNames().
HstResponse, unfortunately, doesn't have a method like
HstResponse#getContentName() as compared to
HstResponse#getChildContentNames() for child windows.
So, it seems hard or impossible to set a flag attribute by its own
window name.
I think it would be a simple/good improvement to add
HstResponse#getContentName() to return its own window name for this kind
of use case.
What do others think?

Regarding the approach (b), according to the SVN log, it doesn't seem to
be trivial to backport the feature to 7.8.

Therefore, personally, I would ask for a simple improvement with the
approach (a). So, if the child component could set a flag attribute by
HstResponse#getContentName() and the parent component can check the flag
to render or not, then you could have achieved the goal very easily.

Regards,

Woonsan
> <http://groups.google.com/group/hippo-community>.
> >>>>>>>> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>> --
> >>>>>>> Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
> >>>>>>> Hippo USA, Inc.- 745 Atlantic Ave, Eight Floor, Boston MA
> 02111,
> >>>>>>> United states of America.
> >>>>>>>
> >>>>>>> US +1 877 414 4776 (toll free)
> >>>>>>> Europe +31(0)20 522 4466
> >>>>>>> www.onehippo.com <http://www.onehippo.com>
> >>>>>>
> >>>>>> --
> >>>>>> 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
> <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
> <http://groups.google.com/group/hippo-community>.
> >>>>>> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
> >>>>>
> >>>>>
> >>>>>
> >>>>> --
> >>>>> Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
> >>>>> Hippo USA, Inc.- 745 Atlantic Ave, Eight Floor, Boston MA 02111,
> >>>>> United states of America.
> >>>>>
> >>>>> US +1 877 414 4776 (toll free)
> >>>>> Europe +31(0)20 522 4466
> >>>>> www.onehippo.com <http://www.onehippo.com>
> >>>>
> >>>> --
> >>>> 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 <javascript:>
> >>>> RSS:
> >>>>
> >>>>
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> <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 <javascript:>.
> <http://groups.google.com/group/hippo-community>.
> >>>> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
> >>>
> >>>
> >>>
> >>> --
> >>> Hippo Netherlands, Oosteinde 11, 1017 WT Amsterdam, Netherlands
> >>> Hippo USA, Inc.- 745 Atlantic Ave, Eight Floor, Boston MA 02111,
> >>> United states of America.
> >>>
> >>> US +1 877 414 4776 (toll free)
> >>> Europe +31(0)20 522 4466
> >>> www.onehippo.com <http://www.onehippo.com>
> >>>
> >>> --
> >>> 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
> <javascript:>
> >>> RSS:
> >>>
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> <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 <javascript:>.
> <http://groups.google.com/group/hippo-community>.
> >>> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
> >>
> >> --
> >> 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
> <javascript:>
> >> RSS:
> >>
> https://groups.google.com/group/hippo-community/feed/rss_v2_0_msgs.xml?num=50
> <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 <javascript:>.
> <http://groups.google.com/group/hippo-community>.
> >> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
> >
> >
> >
>
>
> --
> w....@onehippo.com <javascript:> www.onehippo.com
> <http://www.onehippo.com>
> Boston - 745 Atlantic Ave, 8th Floor, Boston MA 02111
> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
> US +1 877 414 4776 (toll free)
> Europe +31(0)20 522 4466
>
> --
> 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
> <mailto:hippo-communi...@googlegroups.com>.
Reply all
Reply to author
Forward
0 new messages