how to get current selected item in the main menu ?

View: New views
9 Messages — Rating Filter:   Alert me  

how to get current selected item in the main menu ?

by Jérémy Lal-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm redesigning the menu of atleap, and i don't know how to get
the current selected item in the main menu, so the item can be highlighted
much like items in the switchlocale block.
I wonder if it would be as simple as accessing some page attribute ?

The use would be for that kind of jsp in frontendMenuItem.jsp :

<c:set var="currentItemId" value="${???.itemId}" />
<c:choose>
        <c:when test="${currentItemId != itemId}">
                <a target="${target}" href="${url}" title="${escapedToolTipMsg}">${titleOut}</a>

        </c:when>

        <c:otherwise>

                <span>${titleOut}</span>

        </c:otherwise>

</c:choose>

Thanks for any help,

Jeremy.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by Jérémy Lal-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Note :
it would better be :
<c:set var="itemName" value="${item.name}" />
<c:set var="currentItemName" value="${???.name}" />
<c:when test="${currentItemName != itemName}">

Jérémy Lal a écrit :

> I'm redesigning the menu of atleap, and i don't know how to get
> the current selected item in the main menu, so the item can be highlighted
> much like items in the switchlocale block.
> I wonder if it would be as simple as accessing some page attribute ?
>
> The use would be for that kind of jsp in frontendMenuItem.jsp :
>
> <c:set var="currentItemId" value="${???.itemId}" />
> <c:choose>
>     <c:when test="${currentItemId != itemId}">
>         <a target="${target}" href="${url}"
> title="${escapedToolTipMsg}">${titleOut}</a>
>
>     </c:when>
>
>     <c:otherwise>
>
>         <span>${titleOut}</span>
>
>     </c:otherwise>
>
> </c:choose>
>
> Thanks for any help,
>
> Jeremy.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by Roman Puchkovskiy-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello.

Here's an example:


<%-- Preparations... --%>
<atleap:constants
className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor"
var="CANONICAL_URI" />
<c:set var="canonicalUri"
value="${requestScope[pageScope.CANONICAL_URI]}" />
<atleap:rewriteUrl action="${canonicalUri}" var="currentUrl" />

...

<%-- Iterating through the menu items... --%>
<atleap:iterator items="${menu.components}" var="item">
     <c:set var="currentItem" value="false"/>
     <c:if test="${currentUrl == item.url}">
         <c:set var="currentItem" value="true"/>
     </c:if>

     <%-- Now currentItem variable is true if this item points to
current page, rendering menu item... --%>

     ...

</atleap:iterator>


As you see, here we are using a variable from request which stores URI
of currently processed page in some canonical format. This format is so
that is we rewrite it using rewriteUrl it will be directly comparable
with menu item links.


Jérémy Lal пишет:

> I'm redesigning the menu of atleap, and i don't know how to get
> the current selected item in the main menu, so the item can be highlighted
> much like items in the switchlocale block.
> I wonder if it would be as simple as accessing some page attribute ?
>
> The use would be for that kind of jsp in frontendMenuItem.jsp :
>
> <c:set var="currentItemId" value="${???.itemId}" />
> <c:choose>
>     <c:when test="${currentItemId != itemId}">
>         <a target="${target}" href="${url}"
> title="${escapedToolTipMsg}">${titleOut}</a>
>
>     </c:when>
>
>     <c:otherwise>
>
>         <span>${titleOut}</span>
>
>     </c:otherwise>
>
> </c:choose>
>
> Thanks for any help,
>
> Jeremy.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
> .
>

--
   Roman Puchkovskiy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by Jérémy Lal-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks, that works for top pages,
but it breaks as soon as one navigates in the section, like
/atleap/rw/forum/topic2.fr.do
/atleap/rw/forum/forum/showForums.fr.do

I don't think it's possible to automate that page->section association based on url,
as it wouldn't work for contentpages like Home or About

If it doesn't already exists, should i add a "sectionName" variable for each Page,
so that when compared to item.name i can know in which section i am ?


Roman Puchkovskiy a écrit :

> Hello.
>
> Here's an example:
>
>
> <%-- Preparations... --%>
> <atleap:constants
> className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor"
> var="CANONICAL_URI" />
> <c:set var="canonicalUri"
> value="${requestScope[pageScope.CANONICAL_URI]}" />
> <atleap:rewriteUrl action="${canonicalUri}" var="currentUrl" />
>
> ...
>
> <%-- Iterating through the menu items... --%>
> <atleap:iterator items="${menu.components}" var="item">
>     <c:set var="currentItem" value="false"/>
>     <c:if test="${currentUrl == item.url}">
>         <c:set var="currentItem" value="true"/>
>     </c:if>
>
>     <%-- Now currentItem variable is true if this item points to current
> page, rendering menu item... --%>
>
>     ...
>
> </atleap:iterator>
>
>
> As you see, here we are using a variable from request which stores URI
> of currently processed page in some canonical format. This format is so
> that is we rewrite it using rewriteUrl it will be directly comparable
> with menu item links.
>
>
> Jérémy Lal пишет:
>> I'm redesigning the menu of atleap, and i don't know how to get
>> the current selected item in the main menu, so the item can be
>> highlighted
>> much like items in the switchlocale block.
>> I wonder if it would be as simple as accessing some page attribute ?
>>
>> The use would be for that kind of jsp in frontendMenuItem.jsp :
>>
>> <c:set var="currentItemId" value="${???.itemId}" />
>> <c:choose>
>>     <c:when test="${currentItemId != itemId}">
>>         <a target="${target}" href="${url}"
>> title="${escapedToolTipMsg}">${titleOut}</a>
>>
>>     </c:when>
>>
>>     <c:otherwise>
>>
>>         <span>${titleOut}</span>
>>
>>     </c:otherwise>
>>
>> </c:choose>
>>
>> Thanks for any help,
>>
>> Jeremy.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>> .
>>
>
> --
>   Roman Puchkovskiy
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by Roman Puchkovskiy-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Currently AtLeap does not support sections in this sense, so there's no
universal way to implement highlighting of menu items.

As for page-section association (for content pages): if you need to have
one-level section structure where content page belongs to some section,
it's not necessary to modify java sources to make such a thing: you
could create some field on a layout (which type is single-line) and
store in this field a name of menu item which represents 'this section'
for page based on this layout. So you could create a layout for some
section, create this field (setting value for default locale), and all
pages which are based on this layout will have similar section menu item
highlighting; to use 'section item name' value in the JSP you can just
use <atleap:content> tag.
This is not a very convinient way, though, because you will need to
maintain correspondence of menu item names to those stored in fields
manually.

If you need something beyond, you can implement required functionality
yourself.


Jérémy Lal пишет:

> Thanks, that works for top pages,
> but it breaks as soon as one navigates in the section, like
> /atleap/rw/forum/topic2.fr.do
> /atleap/rw/forum/forum/showForums.fr.do
>
> I don't think it's possible to automate that page->section association
> based on url,
> as it wouldn't work for contentpages like Home or About
>
> If it doesn't already exists, should i add a "sectionName" variable for
> each Page,
> so that when compared to item.name i can know in which section i am ?
>
>
> Roman Puchkovskiy a écrit :
>> Hello.
>>
>> Here's an example:
>>
>>
>> <%-- Preparations... --%>
>> <atleap:constants
>> className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor"
>> var="CANONICAL_URI" />
>> <c:set var="canonicalUri"
>> value="${requestScope[pageScope.CANONICAL_URI]}" />
>> <atleap:rewriteUrl action="${canonicalUri}" var="currentUrl" />
>>
>> ...
>>
>> <%-- Iterating through the menu items... --%>
>> <atleap:iterator items="${menu.components}" var="item">
>>     <c:set var="currentItem" value="false"/>
>>     <c:if test="${currentUrl == item.url}">
>>         <c:set var="currentItem" value="true"/>
>>     </c:if>
>>
>>     <%-- Now currentItem variable is true if this item points to
>> current page, rendering menu item... --%>
>>
>>     ...
>>
>> </atleap:iterator>
>>
>>
>> As you see, here we are using a variable from request which stores URI
>> of currently processed page in some canonical format. This format is
>> so that is we rewrite it using rewriteUrl it will be directly
>> comparable with menu item links.
>>
>>
>> Jérémy Lal пишет:
>>> I'm redesigning the menu of atleap, and i don't know how to get
>>> the current selected item in the main menu, so the item can be
>>> highlighted
>>> much like items in the switchlocale block.
>>> I wonder if it would be as simple as accessing some page attribute ?
>>>
>>> The use would be for that kind of jsp in frontendMenuItem.jsp :
>>>
>>> <c:set var="currentItemId" value="${???.itemId}" />
>>> <c:choose>
>>>     <c:when test="${currentItemId != itemId}">
>>>         <a target="${target}" href="${url}"
>>> title="${escapedToolTipMsg}">${titleOut}</a>
>>>
>>>     </c:when>
>>>
>>>     <c:otherwise>
>>>
>>>         <span>${titleOut}</span>
>>>
>>>     </c:otherwise>
>>>
>>> </c:choose>
>>>
>>> Thanks for any help,
>>>
>>> Jeremy.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@...
>>> For additional commands, e-mail: users-help@...
>>>
>>> .
>>>
>>
>> --
>>   Roman Puchkovskiy
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-mail: users-help@...
>>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@...
> For additional commands, e-mail: users-help@...
>
>

--
   Roman Puchkovskiy

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by Jérémy Lal-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for your advice, i end up doing just that, it's sufficient for my purpose.



Roman Puchkovskiy a écrit :

> Currently AtLeap does not support sections in this sense, so there's no
> universal way to implement highlighting of menu items.
>
> As for page-section association (for content pages): if you need to have
> one-level section structure where content page belongs to some section,
> it's not necessary to modify java sources to make such a thing: you
> could create some field on a layout (which type is single-line) and
> store in this field a name of menu item which represents 'this section'
> for page based on this layout. So you could create a layout for some
> section, create this field (setting value for default locale), and all
> pages which are based on this layout will have similar section menu item
> highlighting; to use 'section item name' value in the JSP you can just
> use <atleap:content> tag.
> This is not a very convinient way, though, because you will need to
> maintain correspondence of menu item names to those stored in fields
> manually.
>
> If you need something beyond, you can implement required functionality
> yourself.
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by daimonion :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I have spent some time on that subject lately and I found (I hope :) simple modification(s) to Atleap source which can help. First of all the solution is very much the same as suggested by Roman Puchkovskiy with small modyfication in MenuComponent.java which will give you some tools to get not only currently slected item but also all items which are ancestors of that item.

MenuComponent.java - add this method

/**
     * Returns list of all parent components in following order: this component, first parent, parent of parent ... root is excluded
     * @return list of items in preorder
     */
    public List getMenuPath() {
        List result = new ArrayList();
        result.add(this);
        MenuComponent parent = this.getParent();
       
        while (parent != null){
        if (parent.getParent() != null) result.add(parent);
        parent = parent.getParent();
        }      
       
        Collections.reverse(result);
        return result;
    }

Now to get currently selected item you must add some code in frontendMenu.jsp:

<atleap:constants className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor" var="CANONICAL_URI" />
<c:set var="canonicalUri" value="${requestScope[pageScope.CANONICAL_URI]}" />
<atleap:rewriteUrl action="${canonicalUri}" var="currentUrl" />

<atleap:iterator items="${frontendMenu.componentsAsPlainList}" var="tempItem">
        <c:if test="${currentUrl == tempItem.url}">
                <c:set var="currentItem" value="${tempItem}" scope="request"/>
                <c:set var="currentItemPath" value="${tempItem.menuPath}" scope="request"/>
        </c:if>        
</atleap:iterator>

Now if you want to highlight currently selected menu item just compare currentItem with item you are rendering.

If you want to highlight some items which are ancestors of that item (for example you have selected menuItem on second level but you want still to highlight any level parent of that item as selected) just chceck if that item is on currentItemPath list:

<c:set var="currentItemSelected" value="false"/>
<atleap:iterator items="${currentItemPath}" var="ancestor">
        <c:if test="${ancestor == item}">
                <c:set var="currentItemSelected" value="true"/>
        </c:if>
</atleap:iterator>

...

<c:choose>
        <c:when test="${currentItemSelected}">
                <!-- some highlighted graphic or html of menu item -->
        </c:when>
        <c:otherwise>
                <!-- some ordinary graphic or html of menu item -->
        </c:otherwise>
</c:choose>

Working example: http://www.touk.pl

Hope this help little bit :)

Re: how to get current selected item in the main menu ?

by Roman Puchkovskiy-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi.

I think, the suggested method is useful as users ask questions about
menu identifying from time to time in this mailing list. So wi'll add it
in next AtLeap release (actually, it's in CVS already).
Thanks for contribution.

Roman Puchkovskiy

daimonion ?????:

> I have spent some time on that subject lately and I found (I hope :) simple
> modification(s) to Atleap source which can help. First of all the solution
> is very much the same as suggested by Roman Puchkovskiy with small
> modyfication in MenuComponent.java which will give you some tools to get not
> only currently slected item but also all items which are ancestors of that
> item.
>
> MenuComponent.java - add this method
>
> /**
>      * Returns list of all parent components in following order: this
> component, first parent, parent of parent ... root is excluded
>      * @return list of items in preorder
>      */
>     public List getMenuPath() {
>         List result = new ArrayList();
>         result.add(this);
>         MenuComponent parent = this.getParent();
>        
>         while (parent != null){
>         if (parent.getParent() != null) result.add(parent);
>         parent = parent.getParent();
>         }      
>        
>         Collections.reverse(result);
>         return result;
>     }
>
> Now to get currently selected item you must add some code in
> frontendMenu.jsp:
>
> <atleap:constants
> className="com.blandware.atleap.webapp.struts.ContentTilesRequestProcessor"
> var="CANONICAL_URI" />
> <c:set var="canonicalUri" value="${requestScope[pageScope.CANONICAL_URI]}"
> />
> <atleap:rewriteUrl action="${canonicalUri}" var="currentUrl" />
>
> <atleap:iterator items="${frontendMenu.componentsAsPlainList}"
> var="tempItem">
> <c:if test="${currentUrl == tempItem.url}">
> <c:set var="currentItem" value="${tempItem}" scope="request"/>
> <c:set var="currentItemPath" value="${tempItem.menuPath}"
> scope="request"/>
> </c:if>        
> </atleap:iterator>
>
> Now if you want to highlight currently selected menu item just compare
> currentItem with item you are rendering.
>
> If you want to highlight some items which are ancestors of that item (for
> example you have selected menuItem on second level but you want still to
> highlight any level parent of that item as selected) just chceck if that
> item is on currentItemPath list:
>
> <c:set var="currentItemSelected" value="false"/>
> <atleap:iterator items="${currentItemPath}" var="ancestor">
> <c:if test="${ancestor == item}">
> <c:set var="currentItemSelected" value="true"/>
> </c:if>
> </atleap:iterator>
>
> ....
>
> <c:choose>
> <c:when test="${currentItemSelected}">
> <!-- some highlighted graphic or html of menu item -->
> </c:when>
> <c:otherwise>
> <!-- some ordinary graphic or html of menu item -->
> </c:otherwise>
> </c:choose>
>
> Working example: http://www.touk.pl
>
> Hope this help little bit :)


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: how to get current selected item in the main menu ?

by daimonion :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Roman Puchkovskiy-2 wrote:
Hi.

I think, the suggested method is useful as users ask questions about
menu identifying from time to time in this mailing list. So wi'll add it
in next AtLeap release (actually, it's in CVS already).
Thanks for contribution.

Roman Puchkovskiy

daimonion ?????:
Thanks too. I hope it will help a bit.