Right Menu

From Fxp Wiki

Jump to: navigation, search

Contents

Variation

Le menu de droite change quand on passe d'un catégorie à l'autre en se servant des menus (barre du haut, ou menu de gauche)

The right menu changes when you change category using the menus (top nav bar or left menu)

switch.jsp

Les liens du menu de gauche ou de la barre du haut vous aménent à un page qui fixe la valeur d'un cookie, et qui vous reconduit là ou vous pensier aller directement. La page s'affiche, et insére le menu correspondant à la valeur du cookie.

The links of left menu and top bar send you to a page charged to record the category value in a cookie, and brings you to the destination you thought you were going directly. The page displays and insert the menu correponding to the value of the cookie.

links / lien

jsp menus

BEWARE : The menus need to be written directly inside a .jsp page (viewtemplate.jsp or leftmenu.jsp, because of the variable in the menu). If you don't use the "baseURL" variable, you can make the links in any page.

Arguments

  • setset : the name of the corresponding category menu (the name of the page to display in the right menu for this category).
  • name : name of the cookie (because switch.jsp is also used to record the value of the "language / style" cookie). Here it is "wikicat".
  • myreferer : the destination of the link.

Wiki.jsp%3Fpage%3DCategoryXml">

Xml

ViewTemplate.jsp

Code pour afficher le menu

Code to display the menu

Three possibilities:

If your distribution contains "httpUtil" do only:

<% String CatMenu = HttpUtil.retrieveCookieValue(request, "wikicat") ; try { if (CatMenu != null) { %>

        

<% } else { } } catch(Exception e) { // Exception handler code here }

%>

If your distribution DOESN'T contains HttpUtil and you don't want to loose time compiling it:

Try to put this in your viewtemplate.jsp <% Cookie cookieCounter = null; String cookieName = "wikicat"; int cookieFound = 0; String myString=""; String tempString=""; int count=0;

try { // Code which can throw can exception Cookie[[] cookies = request.getCookies(); if (cookies != null) { for(int i=0; i

if(cookieFound == 1) { myString = cookieCounter.getValue(); tempString = myString; } else { tempString = ""; }

}

} catch(Exception e) { // Exception handler code here }

%>

<% String CatMenu = tempString ; try { if (CatMenu != null) { %>

        

<% } else { } } catch(Exception e) { // Exception handler code here }

%>

If your distribution doesn't contains HttpUtil: (if you don't know how to compile, FORGET IT) you must also do this:

  • add:

<%@ page import="ecyrd.HttpUtil" %> At the top of viewtemplate.jsp;

  • add this in ViewTemplate where you want the menu diplayed.

<% String CatMenu = HttpUtil.retrieveCookieValue(request, "wikicat") ; try { if (CatMenu != null) { %>

        

<% } else { } } catch(Exception e) { // Exception handler code here }

%>

  • create a folder named "ecyrd" in JSPWiki/WEB-INF/classes/ (create classes if it doesn't exist)
  • create a file named HttpUtil.java in the "ecyrd" folder, with this content:

package ecyrd;

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.Cookie;

/**

*  Contains useful utilities for some common HTTP tasks.
*
*  @author Janne Jalkanen
*  @since 2.1.61.
*/

public class HttpUtil {

   /**
    *  Attempts to retrieve the given cookie value from the request.
    *  Returns the string value (which may or may not be decoded
    *  correctly, depending on browser!), or null if the cookie is
    *  not found.
    *
    *  @param request The current request
    *  @param cookieName The name of the cookie to fetch.
    *  @return Value of the cookie, or null, if there is no such cookie.
    */
   public static String retrieveCookieValue( HttpServletRequest request, String 
   cookieName )
   {
       Cookie[[] cookies = request.getCookies();
       if( cookies != null )
       {
           for( int i = 0; i < cookies.length; i++ )
           {
               if( cookies[i]].getName().equals( cookieName ) )
               {
                   return( cookiesi.getValue() );
               }
           }
       }
       return( null );
   }

}

  • compile it
  • restart your wiki
     ; 
Personal tools