Sign in

E-mail *, (xx@domain.com)
Password *

Register | Forgot password

Active forums

Active Forums RSS September 03, 19:59
Style properties

August 31, 21:46
antrun not found

August 31, 14:12
WCB customprofile

August 31, 12:10
End of flow not doing its job

August 24, 12:37
Sort mediaItem by expiration date

 All Forums...


Page.getLevelPage(int)

The "WCB: JSP front-end design" forum contains threads on issues that are related to JSP front-end design while programming a WCB (WebManager Component Bundle). The Presentation & Element component contain JSPs that will be used for front-end rendering. Ask your questions related to these JSPs here. Some example topics: integration of AJAX, use of the taglibs, how to handle multiple websites, and so forth.

Answered
Not marked as answered yet

Forums  >  WCB: JSP Front-end design  >  Page.getLevelPage(int)


Author Page.getLevelPage(int)
noudse



Posts: 26

Posted: 08-04-2008 10:51

Hi,

In my presentation WCB I am building some pageparts for displaying the navigation on the website. I want the highest level to be displayed horizontally and the second highest level to be displayed vertically at another place of the HTML, so I cannot do some recursive solution.

No, I found out I can do ${page.level1Page} to get the highest level for my horizontal menu structure. I found out about a Page.getLevelPage(int) method, but how can I use this from my second level navigation pagepart?

/arnoud

markvc



Posts: 196

Posted: 08-04-2008 10:58 Solved

Hi Arnoud,

In the JSP expression language it is not possible to call a method that requires arguments, so you must use a scriptlet for this. Inside a scriptlet, you can use the Java syntax.

The code snippet below should help you build what you want:


<%@ page import="nl.gx.webmanager.cms.core.Page" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>

<c:set var="currentPage" value="${presentationcontext.page}" />
<c:set var="level1Page" value="${currentPage.level1Page}" />

<%-- c:set var="level2Page" ... --%>
<%
Page currentPage = (Page)pageContext.getAttribute("currentPage");
Page level2Page = currentPage.getLevelPage(2);
pageContext.setAttribute("level2Page", level2Page);
%>

<c:set var="subPages" value="${level2Page.current.subPagesWithCurrent}" />



Gr,
Mark

jetske


Posts: 1

Posted: 09-04-2008 14:22 Helpful

I'd strongly discourage using scriplets, especially when there are other, better solutions. One of them is writing your own taglib, or just using the following code:


<c:set var="currentPage" value="${presentationcontext.page}" />
<c:set var="myParents" value="${currentPage.parents}" />

<c:if test="${not empty level1Page.current}"
<c:set var="level2Pages" value="${level1Page.current.subPages}" />

<c:forEach var="level2page" items="${level2Pages}">
<c:if test="${not empty level2page.current}">
<c:if test="${wmfn:contains(level2page, myParents) || level2page == currentPage}">
<c:set var="activeLevel2Page" value="${level2page}" />
</c:if>
</c:if>
</c:forEach>

</c:if>
</c:if>

markvc



Posts: 196

Posted: 09-04-2008 14:52

Hi Jetske,

I agree in that using scriptlets should be discouraged in general. They can easily clutter your code and things are often cleaner when they're avoided.

However, when I compare your snippet to mine, your snippet is double the size and it's less clear what it's doing when you read it. I argue that this case is an exception to the general rule of avoiding scriptlets.

Gr,
Mark

noudse



Posts: 26

Posted: 11-04-2008 08:46

hi,

Thank you! Both solutions are working. Are you clear on what solution is the preferred one?

/arnoud

simon


Posts: 6

Posted: 11-04-2008 11:21

I have to agree with Mark here. The core problem is that the "scriptlets are bad" rule is a crude and inaccurate simplification of the more general rule of thumb: "Avoid mixing big chunks of processing code in your presentation code". It doesn't matter so much whether the code is JSP tags or scriptlet code. This thread here is a good example of how the "scriptlets are bad" rule is wrong. The solution presented here using a scriptlet is shorter and easier to understand and maintain. It's a clear winner in my opinion.

There are things which JSP tags are not good for, and this is one of them.

As for writing a taglib, it just another case of weighing up the cost (time + effort, extra code) of doing that against the gains (reusability, code organisation). Unless you plan to reuse that snippet of code later, I would probably just go for the cheapest solution instead of paying extra cost. You can pay the extra cost later to make a tablib if you really need to.

cheers,

--
Simon

patricka



Posts: 255

Posted: 18-04-2008 15:44

If I'm not mistaking, the "getLevelPage(int)" method is in the API, isn't it? I vaguely recall stumbling upon it. So calling it using a scriptlet shouldn't cause any future problems. I agree with Simon that using the scriptlet seems the more elegant of the two in this case.

I'll keep on telling my students "scriptlets are bad, mmkay?" though. Easier to memorize than "Avoid mixing big chunks of processing code in your presentation code, mmkay?".

Greetings,

Patrick

Back to top

New message: "Page.getLevelPage(int)"
Message:
bold boitalicd underline url quote code smile cool eek grin mad razz sad wink
 
© 2010 GX creative online development B.V.

Disclaimer

This website (GXdeveloperweb.com) may discuss or contain opinions, (sample) coding, software or other information that does not include GX official interfaces, instructions or guidelines and therefore is not supported by GX. Changes made based on this information are not supported.  GX will not be held liable for any damages caused by using or misusing the information, software, instructions, code or methods suggested on this website, and anyone using these methods does so at his/her own risk. GX offers no guarantees and assumes no responsibility or liability of any type with respect to the content of this website, including any liability resulting from incompatibility between the content of this website and the materials and services offered by GX. By using this website you will not hold, or seek to hold, GX responsible or liable with respect to the content of this website.