• Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Scriptlet - Navigation

 
Robert Lofthouse
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there,

I'm creating a side nav on all my pages within a JSP (don't ask, I know all about MVC). Now, using a pure scriptlet how would I go about creating this:

Depending on the section name I need to display the correct pages for that section (based on a param from a URL). Now, as Java doesn't have brilliant support for multi-demensional arrays, I was wondering how I could possibly do this.

-----Section 1
----------- Page 1
----------------- fileName
----------------- text_desc
----------- Page 2
----------------- fileName
----------------- text_desc
-----Section 2
----------- Page 1
----------------- fileName
----------------- text_desc

It's such a simple task, which seems to have been made unnecessarily complicated.

Thanks
 
Scheepers de Bruin
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would suggest using something like the following:

Class PageInfo{
String filename;
String desc;
public String getFilename(){return filename;}
public String getDescription(){return desc;}
public PageInfo(String filename, desc){ this.filename=filename; this.desc=desc;}
}

Class Section{
java.util.ArrayList pages;
public void addPage(PageInfo page){ pages.add(page);}
public PageInfo getPage(int index){ return (PageInfo)pages.get(index);}
}

Class Menu{
java.util.ArrayList sections;
public void addSection(Section section){ sections.add(section);}
public Section getSection(int index){ return (Section)sections.get(index);}
}

You can generate an html menu in this way, suppose menu is an instantiated and populated Menu:

// suppose you want to show the second section:
int sectionToDisplay = 1;
for (int a=0; a<menu.getSection(sectionToDisplay).size(); a++){
%>
<html tags to format information>
<%=menu.getSection(sectionToDisplay).getPage(a).getFilename()%>
<html tags to format information>
<%=menu.getSection(sectionToDisplay).getPage(a).getDescription()%>
<html tags to format information>
%<}

If you prefer to use strings to refer to info (e.g. menu.getSection("home").getPage("aboutUs")), use java.util.HashMap to store the info in stead of ArrayLists. You will lose the order of the elements though.

[ September 27, 2005: Message edited by: Scheepers de Bruin ]
[ September 27, 2005: Message edited by: Scheepers de Bruin ]
 
srikanth singamsetty
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI you can go for tiles concept in struts to handle this
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!