• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
Sheriffs:
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Joe Ess
  • salvin francis
  • fred rosenberger

menu tag library

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am trying to creat tag library for the menu to make designers job easier. got a little problem. here is what I have now:

<table>
<menu:MainMenu>
<TR>
<TD>
<P class=menu><B><menu:MenuItem/></B></P>
</TD>
</TR>
</menu:MainMenu>
</TABLE>

See Where MenuItem is, I want my calss to loop this code including at <TR> ..... </TR> and only change the MenuItem. I know one of the options is to search and replace the body that is taken in, but I am looking for a better alternative because this will significantly slow things down, I think. I am sure you guy have a solution better than search and replace, any ideas
My current test classes look like this (of course this is just a test, all info will be pulled from the database:
public class MainMenu extends TagSupport {
private String[] array = null;
public String[] getArray() {
return array;
}
public void setArray(String[] newArray) {
this.array = newArray;
}
public int doStartTag() throws JspException {
this.array = new String[6];
this.array[0] = "Menu 1";
this.array[1] = "Menu 2";
this.array[2] = "Menu 3";
this.array[3] = "Menu 4";
this.array[4] = "Menu 5";
this.array[5] = "Menu 6";
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspException {
this.array = null;
return EVAL_PAGE;
}
}

and.................
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.*;
public class MenuItem extends BodyTagSupport {
private int arrayCounter = 0;
private String[] array = null;
public int doStartTag() throws JspException {
MainMenu parentTag = (MainMenu)this.findAncestorWithClass(this, MainMenu.class);
this.array = parentTag.getArray();
return EVAL_BODY_BUFFERED;
}
public int doAfterBody() throws JspException {
try {
JspWriter out = pageContext.getOut();
out.print(this.array[this.arrayCounter]);
}
catch (Exception ioException) {
System.err.println("IO Exception thrown in Child.doAfterBody():");
System.err.println(ioException.toString());
throw new JspException(ioException);
}
int repeatOrSkip = SKIP_BODY;
if (this.arrayCounter < (this.array.length - 1)) {
repeatOrSkip = EVAL_BODY_AGAIN;
this.arrayCounter++;
}
return repeatOrSkip;
}
public int doEndTag() throws JspException {
try {
this.getBodyContent().writeOut(pageContext.getOut());
}
catch (Exception ioException) {
System.err.println("IO Exception thrown in Child.doEndTag():");
System.err.println(ioException.toString());
throw new JspException(ioException);
}
return EVAL_PAGE;
}
}
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well its not an answer but what I did is Create a menu object and loaded it through xml in the application object
then at every screen i use a tag to create the html and jscript code
 
Fedor Smirnoff
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This wouldnt work for me because HTML code can be different every time, so I need the tag to process the code and insert menu items, but Thanks.
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
Sauce Labs - World's Largest Continuous Testing Cloud for Websites and Mobile Apps
https://coderanch.com/t/722574/Sauce-Labs-World-Largest-Continuous
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!