• Post Reply Bookmark Topic Watch Topic
  • New Topic

Custom tags

 
vasu maj
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am in the process of refactoring a working JSP to use custom tags. There is a lot of java code which needs to be taken out of the JSP. After setting up the system for using tags( creating TLDs and while writing the tag handlers) I am at a loss as to how I can distribute the java code into different methods of the tag handler class and where to put the HTML which is in between those chunks of java code. For example here is a part of the JSP ....
<%
if(paging) {
String pagingURL=null;
Element synRows = root.getChild("SynRows");
if (synRows != null)
pagingURL = synRows.getAttributeValue("URL");
if (pagingURL==null || pagingURL.trim().equals(""))
pagingURL = portalURL + "?FUNC=BaseController/";
else
pagingURL = pagingURL.substring(0, pagingURL.lastIndexOf("/")+1);
if (view.getUseRefetchedRS())
pagingURL += "getAllRecords";
else
pagingURL += "changeRecordCountPerPage";



// System.out.println(",,,,,,,,get to synRow,,,,,,");
int rows[] = {10,25,50,100,250,500,1000,2500};

for(int i = 0; i < rows.length; i++){
if(totalRecords>rows[i]) {
%>
<option value="<%=rows[i]%>"
<%
if (rows[i]==numRows) {
rowsSelected=true;
%>
selected>
<%
}
else {
%>
>
<%
}
%>
<%=rows[i]%>
</option>
<%
} }

if(totalRecords<2501){ %>
<option value="<%=totalRecords%>"
<%
if (rowsSelected==false) {
%>
selected>
<%
}
else{
%>
>
<%
}
%>
If I put the first few lines ofjava code above into my doStartTag and the first few lines of HTML code into the body of the tag( giving body-content as JSP), I still have some more java code and then more HTML to take care of. Where should it go? In the doEndTag? I can have only some java code there ( till I get to the next HTML code segment). What about the rest of the code? Also if I am setting some of the variables in the doStartTag, are they available to my JSP ( to use them in my HTML for printing accordingly?)
Thanking in advance for any guidance from experienced custom tag users....
Vasu
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!