All pastes #917758 Raw Edit

Miscellany

public text v1 · immutable
#917758 ·published 2008-02-25 17:34 UTC
rendered paste body
<%--
***************************************************************************

  SeqHound Web Interface
  (Based on the Biomolecular Interaction Network Database)

  The Blueprint Initiative
  522 University Avenue, 9th Floor, Suite 900
  Toronto, Ontario, Canada, M5G 1W7

  Hogue Lab - University of Toronto Biochemistry Department
  Samuel Lunenfeld Research Institute, Mount Sinai Hospital

  Copyright Notice:

  Copyright 2003, 2004, 2005 Mount Sinai Hospital (MSH)

  This program is free software; you can redistribute it and/or 
  modify it under the terms of the GNU General Public License as 
  published by the Free Software Foundation; either version 2 of 
  the License, or any later version.

  This program is distributed in the hope that it will be useful, 
  but WITHOUT ANY WARRANTY; without even the implied warranty of 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 

  See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License 
  along with this program; if not, write to the
         Free Software Foundation, Inc., 
         59 Temple Place, Suite 330, Boston, MA  
         02111-1307  USA 
  or visit http://www.gnu.org/copyleft/gpl.html

************************************************************************* --%>
<%@ page import="java.io.*"%>
<%@ page import="java.lang.Integer"%>
<%@ page import="java.util.*"%>
<%@ page import="com.unleashedinformatics.jseqhound.framework.config.BINDDef"%>
<%@ page import="com.unleashedinformatics.jseqhound.framework.*"%>
<%@ page import="com.unleashedinformatics.jseqhound.framework.ui.*"%>
<%@ page import="com.unleashedinformatics.jseqhound.framework.formbeans.*"%>
<%@ page import="org.blueprint.common.*"%>
<%@ page import="com.unleashedinformatics.jseqhound.bbs.formbeans.BBSFormBean"%>
<%@ page import="com.unleashedinformatics.jseqhound.bbs.formbeans.BBSFormBean"%>
<%@ page import="com.unleashedinformatics.jseqhound.bbs.export.ExporterFactory" %>
<%
class BINDWebElements {
	private FormView viewmode;
	
	/*This is used to enable the comment input field during validation mode*/
	private boolean disable = false;

	BINDWebElements() {
		/*This allows for non BIND record views to use the WebElements*/
		this.viewmode = new FormView();
	}

	BINDWebElements(FormView viewmode) {
		this.viewmode = viewmode;
		this.disable = !viewmode.isEditable();
	}

	String checked(int value) {
		if (value > 0) {
			return " CHECKED ";
		}
		
		return "";
	}
	
	String checked(boolean value) {
		if (value) {
			return " CHECKED ";
		}
		
		return "";
	}


	void printOptionList(JspWriter out, FormBean fbean, SelectOption.OptionList olist, int proptype) throws IOException {
		SelectOption opt;
		
		if(olist==null) {
			out.println("<!--Null OptionList Given-->");
			return;
		}
		
		if(fbean==null) {
			out.println("<!--Null Form Bean Given-->");
			return;
		}
		
		for(int x = 0; x < olist.size(); x++) {
			opt = (SelectOption) olist.get(x);
			if (viewmode.isEditable()) {
				%><option value="<%=opt.getStrId()%>" <%if (fbean.checkSelection(opt.getStrId(), proptype)) out.print("selected");%>><%=opt.getName()%></option><%
			} else {
				if(fbean.checkSelection(opt.getStrId(), proptype)) {
					out.print(opt.getName());
				}
			}
		}
	}

	/**
	 * Emits a multi selection box.
	 * @param autoSubmit 
	 */
	void printMultiSelectBoxElement(JspWriter out, String name, int size, FormBean fbean, SelectOption.OptionList olist, int proptype) throws IOException 
	{		
%>				<select name="<%=name%>" class="textarea" size="<%=size%>" multiple>
					<%printOptionList(out, fbean, olist, proptype);%>
				</select>
<%
	}

	/**
	 * Emits a multi selection box.
	 * @param autoSubmit 
	 */
	void printMultiSelectBox(JspWriter out, String name, int size, FormBean fbean, SelectOption.OptionList olist, int proptype) throws IOException 
	{		
		if (viewmode.isEditable()) {
%>			<td align="left">
			<%printMultiSelectBoxElement(out, name, size, fbean, olist, proptype);%>
			</td>
<%		} else {
			%><td align="left" class="textboxview"><%printOptionList(out, fbean, olist, proptype);%></td><%
		}
	}


	void printSelectBox(JspWriter out, String name, boolean onChange, FormBean fbean, SelectOption.OptionList olist, int proptype, String extraAction) throws IOException 
    {		
	    printSelectBox(out, name, onChange, fbean, olist, proptype, extraAction, true); 
    }

	/**
	 * Emits a selection box.
	 * @param autoSubmit 
	 */
	void printSelectBoxElement(JspWriter out, String name, boolean onChange, FormBean fbean, SelectOption.OptionList olist, int proptype, String extraAction, boolean autoSubmit) throws IOException 
	{		
%>				<select name="<%=name%>" class="textbox" <%
					if (onChange) {
                        %> onChange="this.form.butval.value = 'change'; <%
							if (extraAction == null) {
								extraAction = "";
							}
							if (autoSubmit) {
								extraAction += "this.form.submit();";
							}
							out.print(extraAction); 
						%>"<%
					}%>>
				<%printOptionList(out, fbean, olist, proptype);%>
				</select>
<%
	}


	/**
	 * Emits a selection box.
	 * @param autoSubmit 
	 */
	void printSelectBox(JspWriter out, String name, boolean onChange, FormBean fbean, SelectOption.OptionList olist, int proptype, String extraAction, boolean autoSubmit) throws IOException 
	{		
		printSelectBox(out, name, onChange, fbean, olist, proptype, extraAction, autoSubmit, "left");
	}
	
    /**
     * Emits a selection box.
     * @param autoSubmit 
     */
    void printSelectBox(JspWriter out, String name, boolean onChange, FormBean fbean, SelectOption.OptionList olist, int proptype, String extraAction, boolean autoSubmit, String align) throws IOException 
    {       
        if (viewmode.isEditable()) {
%>          <td align="<%=align%>">
            <%printSelectBoxElement(out, name, onChange, fbean, olist, proptype, extraAction, autoSubmit);%>
            </td>
<%      } else {
            %><td align="<%=align%>" class="textboxview"><%printOptionList(out, fbean, olist, proptype);%></td><%
        }
    }

    /**
     * Emits a selection box that can show and error field based on proptype, mol, and ehandler
     * @param autoSubmit 
     */
    void printSelectBox(JspWriter out, String name, boolean onChange, FormBean fbean, SelectOption.OptionList olist, int proptype, String extraAction, boolean autoSubmit, String align, String mol, ApplicationErrorHandler ehandler) throws IOException 
    {   
        if (viewmode.isEditable()) {
	        String classStr = "";    
	        if(env.hasFieldError(proptype, mol, ehandler)) {
	            classStr = "class=\"fielderror\"";
	        }
%>          <td align="<%=align%>" <%=classStr%>>
            <%printSelectBoxElement(out, name, onChange, fbean, olist, proptype, extraAction, autoSubmit);%>
            </td>
<%      } else {
            %><td align="<%=align%>" class="textboxview"><%printOptionList(out, fbean, olist, proptype);%></td><%
        }
    }

	/**
	 * @param out
	 * @param text
	 * @param name
	 * @param onChange
	 * @param olist
	 * @param fbean
	 * @param prop
	 * @param mol
	 * @param ferr
	 * @param extraAction
	 *
	 * @throws IOException
	 *
	 * Defaults the HttpServletRequet to null and the final boolean (autoSubmit) to true, though,
	 * autosubmission only occurs if 'onChange' is also true.
	 *
	 * @see printSelectBoxRow(JspWriter, HttpServletRequest, String, String, boolean, SelectOption.OptionList,
	 *							FormBean, int, String, ApplicationErrorHandler, String, boolean)
	 */
	void printSelectBoxRow(JspWriter out, String text, String name, boolean onChange, SelectOption.OptionList olist, FormBean fbean, int prop, String mol, ApplicationErrorHandler ferr, String extraAction) throws IOException 
    {		
	    printSelectBoxRow(out, null, text, name, onChange, olist, fbean, prop, mol, ferr, extraAction, true); 
	}


	/**
	 * @param out
	 * @param request
	 * @param text
	 * @param name
	 * @param onChange
	 * @param olist
	 * @param fbean
	 * @param prop
	 * @param mol
	 * @param ferr
	 * @param extraAction
	 *
	 * @throws IOException 
	 *
	 * Defaults the final boolean (autoSubmit) to true, though, autosubmission only occurs if 'onChange' is
	 * also true.
	 *
	 * @see printSelectBoxRow(JspWriter, HttpServletRequest, String, String, boolean, SelectOption.OptionList,
	 *							FormBean, int, String, ApplicationErrorHandler, String, boolean)
	 */
	void printSelectBoxRow(JspWriter out, HttpServletRequest request, String text, String name, boolean onChange, SelectOption.OptionList olist, FormBean fbean, int prop, String mol, ApplicationErrorHandler ferr, String extraAction) throws IOException 
    {		
	    printSelectBoxRow(out, request, text, name, onChange, olist, fbean, prop, mol, ferr, extraAction, true); 
	}

	/**
	 *
	 * @param out
	 * @param text
	 * @param name
	 * @param onChange
	 * @param olist
	 * @param fbean
	 * @param prop
	 * @param mol
	 * @param ferr
	 * @param extraAction
	 * @param autoSubmit
	 *
	 * @throws IOException 
	 *
	 * Defaults the HttpServletRequet to null.
	 *
	 * @see printSelectBoxRow(JspWriter, HttpServletRequest, String, String, boolean, SelectOption.OptionList,
	 *							FormBean, int, String, ApplicationErrorHandler, String, boolean)
	 */
	void printSelectBoxRow(JspWriter out, String text, String name, boolean onChange, SelectOption.OptionList olist, FormBean fbean, int prop, String mol, ApplicationErrorHandler ferr, String extraAction, boolean autoSubmit) throws IOException 
    {		
    	printSelectBoxRow(out, null, text, name, onChange, olist, fbean, prop, mol, ferr, extraAction, autoSubmit);
	}

	/**
	 * @param out
	 * @param request
	 * @param text
	 * @param name
	 * @param onChange
	 * @param olist
	 * @param fbean
	 * @param prop
	 * @param mol
	 * @param ferr
	 * @param extraAction
	 * @param autoSubmit
	 *
	 * @throws IOException 
	 */
	void printSelectBoxRow(JspWriter out, HttpServletRequest request, String text, String name, boolean onChange, SelectOption.OptionList olist, FormBean fbean, int prop, String mol, ApplicationErrorHandler ferr, String extraAction, boolean autoSubmit) throws IOException 
    {		
		%><tr><%
		printFieldDescr(out, request, text, prop, mol, name, ferr);
		printSelectBox(out, name, onChange, fbean, olist, prop, extraAction, autoSubmit);
		%></tr><%
	}

	/**
	 * Creates a row with two <td> tags, one for the field description and the second for a select box. The
	 * select box is unique because it is just a selection of numbers, from listFloor ... listCeil
	 *
	 * @param listFloor The lowest option value in this select list
	 * @param listCeil The highest option value in this select list
	 * @param selectDefault If true, this function will highlight the currently selected option specified by
	 * 		  the value of the request parameter with the name fieldName.
	 */
	void printIntegerSelectBoxRow(JspWriter out, HttpServletRequest request, String fieldDesc, String fieldName, int listFloor, int listCeil, boolean selectDefault, ApplicationErrorHandler ferr) throws IOException
	{
%>		<tr>
			<%printFieldDescr(out, request, fieldDesc, -1, null, fieldName, ferr);%>
			<td>
				<select class="textbox" name="<%=fieldName%>" onChange="this.form.butval.value='change'; this.form.tabletype.value='<%=fieldName%>'; this.form.submit();">
					<%for (int i = listFloor; i <= listCeil; i++) {%>
						<option value="<%=(i)%>"><%=(i)%></option>
					<%}%>
				</select>
			</td>
		</tr>
<%
	}

	void printTableTitle(JspWriter out, HttpServletRequest request, String title, String extra, Button[] but) throws IOException {
		this.printTableTitle(out, request, title, extra, but, 0);
	}
	
	void printTableTitle(JspWriter out, String title, String extra, Button[] but) throws IOException {
		this.printTableTitle(out, null, title, extra, but, 0);
	}

	void printTableTitle(JspWriter out, String title, String extra, Button[] but, int depth) throws IOException {
		printTableTitle(out, null, title, extra, but, depth);
	}

	void printTableTitle(JspWriter out, HttpServletRequest request, String title, String extra, Button[] but, int depth) throws IOException {
		// Limit min depth value used by anchor jumping to zero
		int formDepth = depth;
		if (depth < 0) {
			formDepth = 0;
		}
		
		%><a name="<%=formDepth%>"></a><%
		
		if (request != null) {
			// Set depth attribute for comment mode so we can populate actionDepth parameter for field links
			request.setAttribute("depth", new Integer(formDepth));
		}
%>
		<table class="bindtable" cellspacing="0" cellpadding="0" border="0" <%if (extra != null) { out.println(extra); }%>>
			<tr>
				<td colspan="2">
					<table border="0" cellpadding="0" cellspacing="0" width="100%">
						<tr class="bindtitle">  
			    			<td background="images/table/title_bg.jpg" nowrap class="bindtitle"><img src="images/table/title_left.jpg" align="top">
<%
								out.print(title);
%>
							</td>
					    	<td background="images/table/title_bg.jpg" align="right">
<%
								if (but != null) {
									for (int i = 0; i < but.length; i++) {
										out.println("&nbsp;");
										printButton(out, but[i], depth);
									}
								}
%>
								<img src="images/table/title_right.jpg" align="top">
							</td>
						</tr>
					</table>
				</td>
			</tr>
<%
	}


	void printSpacerTable(JspWriter out, boolean debug) throws IOException {
%>
	<tr>
    	<td colspan="2">
		<table cellspacing="0" cellpadding="5" border="<%if(debug) {out.print("1");} else {out.print("0");}%>" width="100%"> <!--Spacer Table-->
<%
	}


	void printSpacerTable(JspWriter out) throws IOException {
		printSpacerTable(out, false);
	}


	void printCloseSpacerTable(JspWriter out) throws IOException {
%>
		</table> <!--Spacer Table-->		
	</td>
	</tr>
<%
	}


	void printCloseTable(JspWriter out) throws IOException {
%>
		</table> <!--Molecule Table-->
<%
	}


	void printTableSubTitle(JspWriter out, String subtitle) throws IOException {
%>
			<tr><td>
			<table class="bindsubtable" cellpadding="0" cellspacing="0" border="0" width="100%"> <!--Sub Table Title-->
				<tr><td align="left" colspan="2" height="9" valign="top" class="bindsubtitle"><%=subtitle%></td></tr>
				<tr><td>
					<table cellpadding="0" cellspacing="5" border="0" width="100%"> <!--Sub Table Body-->
<%
	}


	void printCloseSubTable(JspWriter out) throws IOException {
%>
					</table> <!--Sub Table Body-->
				</td></tr>
			</table> <!--Sub Table Title-->
			</td></tr>
<%
	}


	void printTextBoxRow(JspWriter out, HttpServletRequest request, String text, String name, int size, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
	%><tr><%
		printFieldDescr(out, request, text, prop, mol, name, ferr);
		printTextBox(out, name, value, size);
	%></tr><%
	}


	void printTextBoxRow(JspWriter out, String text, String name, int size, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
		printTextBoxRow(out, null, text, name, size, value, prop, mol, ferr);
	}


	void printTextAreaRow(JspWriter out, HttpServletRequest request, String text, String name, int width, int height, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
	%><tr><%
		printFieldDescr(out, request, text, prop, mol, name, ferr);
		printTextArea(out, name, value, width, height);
	%></tr><%
	}


	void printTextAreaRow(JspWriter out, String text, String name, int width, int height, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
		printTextAreaRow(out, null, text, name, width, height, value, prop, mol, ferr);
	}


	void printPasswordRow(JspWriter out, HttpServletRequest request, String text, String name, int size, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
	%><tr><%
		printFieldDescr(out, request, text, prop, mol, name, ferr);
		printPassword(out, name, value, size);
	%></tr><%
	}


	void printPasswordRow(JspWriter out, String text, String name, int size, String value, int prop, String mol, ApplicationErrorHandler ferr) throws IOException {
		printPasswordRow(out, null, text, name, size, value, prop, mol, ferr);
	}


	void printTextBoxElement(JspWriter out, String name, String value, int size) throws IOException {
%>
			<input type="textbox" class="textbox" name="<%=name%>" value="<%=HTMLString.encodeForForm(value)%>" <%if (size > 0) { out.println("size=\"" + size + "\""); }%>>
<%
	}


	void printTextBox(JspWriter out, String name, String value, int size) throws IOException {
		if (viewmode.isEditable()) {
%>
		<td align="left">
			<%printTextBoxElement(out, name, value, size);%>
		</td>
<%
		} else {
			%><td align="left" class="textboxview"><%=value%></td><%
		}
	}

	void printCheckBoxRow(String title, JspWriter out, String name, String value, boolean selected, String onClick) throws IOException {
%>
	<tr>
		<% printCheckBoxAlign(out, name, value, selected, onClick, "right"); %>
		<td class="field"><%=title%></td>
	</tr>
<%  }

	/**
	 * @param out
	 * @param name
	 * @param value		Initial value
	 * @param selected
	 * @param onClick
	 */
	void printCheckBox(JspWriter out, String name, String value, boolean selected, String onClick) throws IOException {
		printCheckBoxAlign(out, name, value, selected, onClick, "left");
	}

	void printCheckBoxAlign(JspWriter out, String name, String value, boolean selected, String onClick, String align) throws IOException {
%>		<td align="<%=align%>">
			<input
<%				if (!viewmode.isEditable()) {
					%> disabled <%
				}
				%>type="checkbox" name="<%=name%>" <%
				if (value !=null) {
					%> value="<%=value%>" <%
				}
				if(onClick!=null) {
					%> onClick="<%=onClick%>" <%
				}
				if(selected) {
					%> checked <%
				}
			%>>
		</td>
<%	}


	/**
	 *  Use this overloaded version if the radio button has no associated action.
	 */
	void printRadioButton(JspWriter out, String name, String value, FormBean formbean, int prop, int index) throws IOException {
		this.printRadioButton(out, null, name, value, formbean, prop, index, -1, false, null, null, null);
	}

	/**
	 *  Use this overloaded version if selecting a radio button should trigger an action (i.e. submission
	 *  of the form) without requesting confirmation from the user.
	 *
	 *  @param extraAction A string to be used as Javascript for setting any parameters just before form submission.
	 */
	void printRadioButton(JspWriter out, String form, String name, String value, FormBean formbean, int prop, int index, boolean blur, String action, String extraAction) throws IOException {
			%><input type="radio" name="<%=name%>" value="<%=value%>" onChange="<%if (extraAction != null) {%><%=extraAction%><%}%> this.form.butval.value='<%=action%>'; this.form.submit();" <%if ((formbean != null) && formbean.checkSelection(value, prop)) out.print("checked");%>><%
	}

	/**
	 *  Use this overloaded version if the radio button has an associated action (i.e. when selecting
	 *  the button some action should occur.
	 *
	 *  @param resetIndex	Will not be evaluated if (func == null)
	 *  @param func
	 *  @param args
	 *  @param action
	 *  (func, args, action) should be used together to specify a javascript function along with its args and
	 *  the 'butval' to set if func returns true. ResetIndex should also accompany these parameters
	 *  and is the index of the radio button to set if func returns false.
	 *  This function currently assumes that a change to a radio button selection should trigger a "confirm"
	 *  style message returning either true/false. In the false situation this requires a reset of the previously
	 *  selected value, the resetIndex.
	 *
	 */
	void printRadioButton(JspWriter out, String form, String name, String value, FormBean formbean, int prop, int index, int resetIndex, boolean blur, String func, String args, String action) throws IOException {
			%><input type="radio" name="<%=name%>" value="<%=value%>" <%if ((func != null) && (index != resetIndex)) { %>onChange="if (<%=func%>(<%=form%>, <%=args%>)) { this.form.butval.value='<%=action%>'; this.form.submit(); } else { this.form.<%=name%>[<%=resetIndex%>].checked=true; }"<%}  if ((formbean != null) && formbean.checkSelection(value, prop)) out.print("checked");%>><%
	}

	void printPassword(JspWriter out, String name, String value, int size) throws IOException {
%>
		<td align="left">
			<input type="password" class="textbox" name="<%=name%>" value="<%=value%>" <%if (size > 0) { out.println("size=\"" + size + "\""); }%>>
		</td>
<%
	}


	void printTextArea(JspWriter out, String name, String value, int width, int height) throws IOException {
        if (value == null) {
            value = "";
        }
		if (viewmode.isEditable() || !disable) {
%>
		<td align="left">
			<textarea class="textarea" name="<%=HTMLString.encodeForForm(name)%>" cols="<%=width%>" rows="<%=height%>"><%=value%></textarea>
		</td>
<%
		} else {
			//this (wrapping) needs to be changed to something more elegant
			%><td class="textareaview"><%=env.wrapString(value, 50)%></td><%
		}
	}


	void printFieldDescr(JspWriter out, HttpServletRequest request, String descr, ApplicationErrorHandler ehandler) throws IOException {
		printFieldDescr(out, request, descr, Defines.PROP_NULL, null, null, ehandler);
	}

	void printFieldDescr(JspWriter out, HttpServletRequest request, String descr, int prop, String mol, String fieldname, ApplicationErrorHandler ehandler) throws IOException {
		String strClass = "";
		
		if (viewmode.canValidate()) {
			strClass = "viewfield";
		} else {
			if ((prop != Defines.PROP_NULL) && (ehandler != null) && env.hasFieldError(prop, mol, ehandler)) {
				strClass = "fielderror";
			} else {
				strClass = "field";
			}
		}

		%><td align="right" class="<%=strClass%>"><%

		out.print(descr + "&nbsp;&nbsp;");
		%></td><%
	
	}


	void printFieldDescr(JspWriter out, String descr, int prop, String mol, String fieldname, ApplicationErrorHandler ehandler) throws IOException {
		this.printFieldDescr(out, null, descr, prop, mol, fieldname, ehandler);
	}


	void printArrayList(JspWriter out, String formname, FormBeanList list, ApplicationErrorHandler ferr, String dataname, String datatype, boolean[] features, int depth) throws IOException {
		printArrayList(out, null, formname, list, ferr, dataname, datatype, features[0], features[1], features[2], features[3], depth);
	}


	void printArrayList(JspWriter out, HttpServletRequest request, String formname, FormBeanList list, ApplicationErrorHandler ferr, String dataname, String datatype, boolean[] features, int depth) throws IOException {
		printArrayList(out, request, formname, list, ferr, dataname, datatype, features[0], features[1], features[2], features[3], depth);
	}

	void printArrayList(JspWriter out, HttpServletRequest request, String formname, FormBeanList list, ApplicationErrorHandler ferr, String dataname, String datatype, boolean add, boolean edit, boolean delete, boolean selection, int depth) throws IOException {
		printArrayList(out, request, formname, list, ferr, dataname, datatype, add, edit, delete, selection, depth, null, null, null);
	}

	/**
	 * @param specialConfirmList
	 * @param editConfirm	a String used for an edit button as a confirmation message. Should include a '?' if is a question.
	 *						If null, will be ignored and no confirmation will be associated with the edit button.
	 * @param deleteConfirm a String used for a delete button as a confirmation message. Should include a '?' if is a question.
	 *						If null, will be ignored.
	 *
	 * SpecialConfirmList, editConfirm and deleteConfirm are used together. All are expected to have value or all should be null.
	 * For the indexes in specialConfirmList that are true, those list elements will have the edit and deleteConfirm messages
	 * used for their respective buttons in place of the standard confirm message.
	 */
	void printArrayList(JspWriter out, HttpServletRequest request, String formname, FormBeanList list, ApplicationErrorHandler ferr, String dataname, String datatype, boolean add, boolean edit, boolean delete, boolean selection, int depth, boolean[] specialConfirmList, String editConfirm, String deleteConfirm) throws IOException {
		int addindex = list.getSize();
		if (addindex == -1) {
			addindex = 0;
		}
		
		String[] args_add =  { new String("'" + datatype + "'"), new String("'"+ addindex +"'") };
%>
		<tr>
    		<td colspan="2">
			<table cellpadding="0" cellspacing="5" border="0" width="100%">
<%
		/*No list*/
		if (list.isEmpty() || list.isDiffEmpty()) {
			if (add) {
				%><tr><td align="center"><span class="arrayListNum"><b>None have been added yet.<br>Please use the add icon to add a new <%=dataname%>.</b></span></td></tr><%
			} else {
				%><tr><td align="center"><span class="arrayListNum"><b>None have been added yet.</b></span></td></tr><%
			}
		}
		
		int beanCount = 0;
		for (int x = 0; x < list.getSize(); x++) {
			if (list.getBean(x) == null) {			
				// Skip placeholder
				continue;
			} else {
				// Count bean
				beanCount++;
			}
			
			String[] args_del = new String[3];
			String[] args_edit;
			String[] args_view =  { new String("'" + datatype + "'"), new String("'"+ x +"'") };

			if ((specialConfirmList != null) && (x < specialConfirmList.length) && specialConfirmList[x] && (deleteConfirm != null)) {
				args_del[0] = "'" + deleteConfirm + "'";
			} else {
				args_del[0] = "'Are you sure you would like to delete this " + dataname + "?'";
			}
			args_del[1] = "'" + datatype + "'";
			args_del[2] = "'"+ x +"'";
			
			if ((specialConfirmList != null) && (x < specialConfirmList.length) && specialConfirmList[x] && (editConfirm != null)) {
				args_edit = new String[3];
				args_edit[0] = "'" + editConfirm + "'";
				args_edit[1] = "'" + datatype + "'";
				args_edit[2] = "'" + x + "'";
			} else {
				args_edit = new String[2];
				args_edit[0] = "'" + datatype + "'";
				args_edit[1] = "'" + x + "'";
			}
			
			%><tr><%
			if (edit || delete || (!viewmode.isEditable() && !selection)) {
				%><td align="left" nowrap><%
					if (delete && viewmode.isEditable())
						printButton(out, CommonButtons.createDeleteButton(formname, "Delete " + dataname , "confirmIndexedSubmit", args_del), depth);
					if (edit && delete && viewmode.isEditable())
						out.print("&nbsp;");
					if (edit && viewmode.isEditable()) {
						if ((specialConfirmList != null) && (x < specialConfirmList.length) && specialConfirmList[x] && (editConfirm != null)) {
							// Edit should include confirmation message
							printButton(out, CommonButtons.createEditButton(formname, "Edit " + dataname, "confirmIndexedSubmit", args_edit), depth);
						} else {
							printButton(out, CommonButtons.createEditButton(formname, "Edit " + dataname , "submitIndexedBINDButton", args_edit), depth);
						}
					}
					if (!viewmode.isEditable() && !list.isReferenceList())
						printButton(out, CommonButtons.createViewButton(formname, "View " + dataname , "submitIndexedBINDButton", args_view), depth);
				%></td><%
			} else if (selection) {
				if (request.getParameterValues(datatype + "_selection") != null) {
					String [] selectList = request.getParameterValues(datatype + "_selection");
					
					for (int y = 0; y < selectList.length; y++) {
						if (selectList[y].equals(String.valueOf(x))) {
							printCheckBox(out, datatype + "_selection", String.valueOf(x), true, null);
							break;
						} else if (y == (selectList.length - 1)) {
							printCheckBox(out, datatype + "_selection", String.valueOf(x), false, null);
						}
					}
				} else {
					printCheckBox(out, datatype + "_selection", String.valueOf(x), false, null);
				}
			}
				
			if (list.isPlaceholderCounted()) {
				%><td width="99%">&nbsp;<span class="arrayListNum"><%=(x+1)%>.</span>&nbsp;&nbsp;<span class="arrayListItem"><%
			} else {
				%><td width="99%">&nbsp;<span class="arrayListNum"><%=beanCount%>.</span>&nbsp;&nbsp;<span class="arrayListItem"><%
			}
			
				out.println("<i>No Description Provided.</i>");
%>
				</span></td>
			</tr>
<%
		}
%>
			</table>
		</td>
		</tr>

		<%if (add && viewmode.isEditable()) {%>
			<tr><td align="right"><%printButton(out, CommonButtons.createAddButton(formname, "Add Another " + dataname, "submitIndexedBINDButton", args_add), depth);%></td></tr>
		<%
		}
	}


	void printButtonRow(JspWriter out, Button but) throws IOException {
		%><tr><td align="center"><%
			printButton(out, but);
		%></td></tr><%
		
	}


	void printButton(JspWriter out, Button but) throws IOException {
		printButton(out, but, -1);
	}


	void printButton(JspWriter out, Button but, int depth) throws IOException{
		if(but.getFormName()!=null)  {
			printButton(out, but.getFormName(), but.getImageName(), but.getImagePath(), but.getDescription(), but.getFunctionName(), but.getArguments(), depth);
		} else {
			if(but.getPg()>0) {
				printButton(out, but.getPg(), but.getImageName(), but.getImagePath(), but.getDescription(), but.getQueryString());
			} else {
				printButton(out, but.getImageName(), but.getImagePath(), but.getDescription(), but.getFunctionName(), but.getArguments());
			}
		}
	}


	/**
	 * For areas of the code (like the Login screen) that use printButton but aren't affected by 'depth' issues present in the BSS.
	 */
	void printButton(JspWriter out, String form, String name, String path, String descr) throws IOException{
		printButton(out, form, name, path, descr, null, null, -1);
	}

	/**
	 * Creates a button without an associated extra javascript function.
	 */
	void printButton(JspWriter out, String form, String name, String path, String descr, int depth) throws IOException{
		printButton(out, form, name, path, descr, null, null, depth);
	}

	/**
	 * For cases when a 'special' image is necessary (eg. "Add Experimental Form" or "Edit Experimental Form" within BSS)
	 * as opposed to the standard buttons ('add', 'edit', ...), BUT the underlying action name need not be tied
	 * to the image name.
	 */
 	void printButton(JspWriter out, String form, String actionName, String imageName, String path, String descr, String func, String args, int depth) throws IOException{
		%><a href="javascript: submitBINDButton(document.<%=form%>, '<%=actionName%>', '<%=depth%>');" title="<%=descr%>" <%if (func != null) { %>onClick=" return <%=func%>(<%=form%>, <%=args%>);"<%} else {%> onclick="return checkSubmitState(this.href, this.target)" <%}%> onMouseOver="MM_nbGroup('over','<%=imageName%>','images/<%=path%>but_v_<%=imageName%>.jpg','',1); window.status='<%=descr%>'; return true;" onMouseOut="MM_nbGroup('out'); window.status=''; return true;"><img src="images/<%=path%>but_u_<%=imageName%>.jpg" name="<%=imageName%>" border="0" align="absmiddle"></a><%
	}

	void printButton(JspWriter out, String form, String name, String path, String descr, String func, String args, int depth) throws IOException{
		%><a href="javascript: submitBINDButton(document.<%=form%>, '<%=name%>', '<%=depth%>');" title="<%=descr%>" <%if (func != null) { %>onClick=" return <%=func%>(<%=form%>, <%=args%>);"<%} else {%> onclick="return checkSubmitState(this.href, this.target)" <%}%> onMouseOver="MM_nbGroup('over','<%=name%>','images/<%=path%>but_v_<%=name%>.jpg','',1); window.status='<%=descr%>'; return true;" onMouseOut="MM_nbGroup('out'); window.status=''; return true;"><img src="images/<%=path%>but_u_<%=name%>.jpg" name="<%=name%>" border="0" align="absmiddle"></a><%
	}
	
	
	void printButton(JspWriter out, int pg, String imageName, String imagePath, String description, String queryString) throws IOException {
		%><a onclick="return checkSubmitState(this.href, this.target)" href="Action?pg=<%out.print(pg); if(queryString!=null) { out.print("&" + queryString); }%>" title="<%=description%>" onMouseOver="MM_nbGroup('over','<%=imageName%>','images/<%=imagePath%>but_v_<%=imageName%>.jpg','',1); window.status='<%=description%>'; return true;" onMouseOut="MM_nbGroup('out'); window.status=''; return true;"><img src="images/<%=imagePath%>but_u_<%=imageName%>.jpg" name="<%=imageName%>" border="0" align="absmiddle"></a><%
	}

	void printButton(JspWriter out, String imageName, String imagePath, String description, String func, String args) throws IOException {
		%><a href="javascript: <%=func%>(<%=args%>);" title="<%=description%>" onMouseOver="MM_nbGroup('over','<%=imageName%>','images/<%=imagePath%>but_v_<%=imageName%>.jpg','',1); window.status='<%=description%>'; return true;" onMouseOut="MM_nbGroup('out'); window.status=''; return true;"><img src="images/<%=imagePath%>but_u_<%=imageName%>.jpg" name="<%=imageName%>" border="0" align="absmiddle"></a><%
	}

	void printCalendarButton(JspWriter out, Button but, String formElementName, boolean enablePast) throws IOException {
		printCalendarButton(out, but.getFormName(), formElementName, but.getImageName(), but.getImagePath(), but.getImageFile(), but.getDescription(), but.getOnClickEvent(), enablePast);
  	}

	void printCalendarButton(JspWriter out, String formName, String formElementName, String imageName, String imagePath, String imageFile, String description, String onClick, boolean enablePast) throws IOException {

  		%><a href="javascript: showCalendar(document.<%=imageName%>,document.<%=formName%>,document.<%=formName%>.<%=formElementName%>,'dd/mm/yyyy',null,<%if(enablePast) {out.print("1");} else {out.print("null");}%>,-1,-1);" onClick="<%if(onClick!=null) {out.print(onClick + ";"); }%> document.<%=formName%>.butval.value='changeDate';" onMouseOver="MM_nbGroup('over','<%=imageName%>','<%=imagePath%>but_v_<%=imageFile%>','',1);" onMouseOut="MM_nbGroup('out');"><img src="<%=imagePath%>but_u_<%=imageFile%>" title="<%=description%>" border="0" valign="bottom" name="<%=imageName%>"/></a><%
  	}

	void printSaveCancelRow(JspWriter out, String[] args_save, String[] args_cancel) throws IOException{
%>
	<tr>
		<td align="center">
			<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td align="center" valign="middle"><%printButton(out, CommonButtons.createSaveFormButton("Save Changes", "submitIndexedBINDButton", args_save), 0);%></td>
				<td align="center" valign="middle"><%printButton(out, CommonButtons.createCancelFormButton("Discard Changes", "confirmIndexedSubmit", args_cancel), 0);%></td>
			</tr>
			</table>
		</td>
	</tr>
<%
	}


	void printPagination(JspWriter out, int pages, int current, String parameterName, String query) throws IOException {
		int maxpages = 10;
		int min = 1;
		int max = pages;

		if (pages == 1) {
			return;
		}
		
		if (pages > maxpages) {
			min = current - 3;
			if (min < 1) { min = 1; }
			
			max = current + 3;
			if (max > pages) { max = pages; }
		}
%>
		<table cellspacing="0" cellpadding="3" border="0">
		<tr>
<%
			if (current != 1) {
				%><td align="center"><a href="index.jsp?<%=parameterName%>=<%=(current-1)%>&<%=query%>"><img src="images/common/arrow_l.jpg" align="absmiddle" border="0"></a></td><%
			}
			
			if (min != 1) {
				%><td align="center"><a href="index.jsp?<%=parameterName%>=1&<%=query%>">1</a></td><%
				%><td align="center"><div class="cpgnation" style="font-weight: normal;">--</div></td><%
			}

			for (int x = min; x <= max; x++) {
				if (x == current) {
					%><td align="center"><div class="cpgnation"><%=x%></div></td><%
				} else {
					%><td align="center"><a href="index.jsp?<%=parameterName%>=<%=x%>&<%=query%>"><%=x%></a></td><%
				}
			}

			if (max != pages) {
				%><td align="center"><div class="cpgnation" style="font-weight: normal;">--</div></td><%
				%><td align="center"><a href="index.jsp?<%=parameterName%>=<%=pages%>&<%=query%>"><%=pages%></a></td><%
			}
			
			if (current != pages) {
				%><td align="center"><a href="index.jsp?<%=parameterName%>=<%=(current+1)%>&<%=query%>"><img src="images/common/arrow_r.jpg" align="absmiddle" border="0"></a></td><%				
			}
%>
		</tr>
		</table>
<%
	}

	/**
	 * Prints the pagination tool along with a "jump to page" widget
	 * @param formName 			Unique name of the form to use when building the widget
	 */
	void printPagination(JspWriter out, int pages, int current, String parameterName, String query, String formName) throws IOException {
		printPagination(out, pages, current, parameterName, query);

		if (pages == 1) {
			return;
		}
%>
		
		<center>
			<form name="<%= formName %>" onsubmit="
				window.location = 
					'index.jsp?<%=parameterName%>=' + document.<%=formName%>.page.value 
					+ '&<%=query%>';
				return false;">
				<table cellspacing="0" cellpadding="3" border="0">
					<tr>
			            <td align="right" class="field">
			        		Skip To Page:
			        	</td>
			        	<%printTextBox(out, "page", String.valueOf(current), 4); %>
						<td>
							<%  printButton(out, formName, "go", "bbs/buttons/", "Jump to page", "openLocation", "'index.jsp?" + parameterName + "=' + document." + formName + ".page.value + '&" + query + "'", -1); %>					
						</td>
		        	</tr>
				</table>
			</form>
		</center>
<%
	}
	
	/**
	 * Prints a form input element of type image, using image rollovers.  
	 * NOTE: This function is not used (but maybe used in the future). Please see printButton().
	 * @param out		  output stream
	 * @param buttonName  name of this element.  This is also used to determine the image names to use
	 * @param descr		  description of this button to show the user
	 * @param path		  path to the images used for this button
	 */
	void printFormImageButton (JspWriter out, String buttonName, String descr, String path) throws IOException
	{
%>
		<input 
			type="image" 
			name="<%= buttonName %>" 
			title="<%= descr %>" 
			onmouseover="this.src = 'images/<%=path%>/but_v_<%=buttonName%>.jpg'; window.status='<%=descr%>'; return true;" 
			onmouseout="this.src = 'images/<%=path%>/but_u_<%=buttonName%>.jpg'; window.status=''; return true;" 
			src="images/<%=path%>but_u_<%=buttonName%>.jpg"
			border="0"
			align="absmiddle">
<%	
	}
	void printFocus(JspWriter out, String form, String element) throws IOException {
%>
		<script type="text/javascript">
			document.<%=form%>.<%=element%>.focus();
		</script>
<%
	}

	void jumpToAnchor(JspWriter out, String anchorName) throws IOException {
%>
		<script type="text/javascript">
			location.hash = "<%=anchorName%>";
		</script>		
<%	
	}

	void printBackLink(JspWriter out, HttpServletRequest request, String linkText) throws IOException {
		// This method requires a backpg parameter in the request URL
		String backPg = (String) request.getParameter("backpg");

		if (backPg != null) {
			String backLink = "Action?pg=" + backPg;
			%><a href="<%=backLink%>"><%=linkText%></a><%
		}
	}


	void checkMessage(JspWriter out, HttpServletRequest request) throws IOException {
		ApplicationErrorHandler ehandler = env.getErrorHandler(request);
		
		if (ehandler != null) {
			ApplicationError err = ehandler.getApplicationError();
			if (err != null) {
				if (err.getUFMessage()!=null && !err.getUFMessage().equals("")) {
					out.println("<a name=\"error\"></a>");
					out.println("<center><font class=\"errortext\">" + err.getUFMessage() + "</font></center>");
					jumpToAnchor(out, "error");
				}
			}
		}
	}

	void printBrowseViewOptionList(JspWriter out, HttpServletRequest request, FormBean fbean, String formName) throws IOException {
		String extraAction = "document." + formName + "." + Defines.PARAM_BROWSE_VIEW_STYLE + ".value = this.value; document." + formName + ".butval.value = 'search'; document." + formName + ".submit();";
%>
        <form name="f_browseview" action="Action" method="post" class="inlineform">
            <table cellpadding="0" cellspacing="0" border="0">
				<%printSelectBoxRow(out, "View:", Defines.PARAM_BROWSE_VIEW_STYLE, true, CommonOptionLists.getBrowseViewStyles(), fbean, Defines.BPROP_BROWSE_VIEW_STYLE, null, null, extraAction, false);%>
			</table>
            <input type="hidden" name="butval" value="">			
		</form>
<%
	}

    /**
     * Emits the export option list in a form named 'f_export'. 
     * @param fbean the <code>FormBean</code> used to render the selection box
     * @param textQuery the query specifying the results to export
     * @param filename (optional) the name prefix of the file that the user will receive
     */
	void printExportOptionList(JspWriter out, FormBean fbean, SelectOption.OptionList optionList, String textQuery, String filename, Boolean isArchive) throws IOException 
    {		
		BBSFormBean searchFormBean = null;
		if(fbean instanceof BBSFormBean)
			searchFormBean = (BBSFormBean)fbean;
		
        String exportJS;
        
        if(searchFormBean == null) {
        	exportJS = "if (document.f_export.type.value == '" + Defines.NO_EXPORT_METHOD + "' ) return;" + 
            	"document.f_export.submit();" + 
            	"document.f_export.type.value = '" + Defines.NO_EXPORT_METHOD + "';";
         } else {
         	exportJS = "if (document.f_export.type.value == '" + Defines.NO_EXPORT_METHOD + "' ) return;" + 
         		"if(!checkExportLimit(document.f_export.type.value,"+searchFormBean.getTotalRecords() +")) return;" + 
            	"document.f_export.submit();" + 
            	"document.f_export.type.value = '" + Defines.NO_EXPORT_METHOD + "';";        
         }
         
        %>

		<SCRIPT>
		function getExportLimit(format) {
		<%
		/*
		out.println("if(format == " + ExporterFactory.XML_BIND_SUBMIT + ") { return " + ExporterFactory.getLimit(ExporterFactory.XML_BIND_SUBMIT) + ";}");
		out.println("if(format == " + ExporterFactory.ASN1_BIND_SUBMIT + ") { return " + ExporterFactory.getLimit(ExporterFactory.ASN1_BIND_SUBMIT) + ";}");
		out.println("if(format == " + ExporterFactory.FLAT + ") { return " + ExporterFactory.getLimit(ExporterFactory.FLAT) + ";}");
		*/
		out.println("return -1;}");
		%>

		function checkExportLimit(format,size) {
			limit = getExportLimit(format);
			if(limit == -1) {
				return true;
			}
			if(size <= limit) {
				return true;
			}
			alert('This system will only allow a maximum export of ' + limit + ' records for the specified format.\nPlease use either http://www.bind.ca or ftp://ftp.blueprint.org');
			return false;
		}
		</SCRIPT>

        <form name="f_export" action="Action" method="post" class="inlineform">
            <table cellpadding="0" cellspacing="0" border="0">
                <% printSelectBoxRow(out, "Export&nbsp;Results:", "type", true, optionList, fbean, Defines.BPROP_EXPORT_METHOD, null, null, exportJS, false); %>
            
	            <% if (filename != null) { %>
		            <input type="hidden" name="filename" value="<%= filename %>">
	            <% } %>
            	
            	<%if(isArchive !=null && isArchive.booleanValue()==true) {%>
            		<input type="hidden" name="isArchive" value="<%=isArchive.booleanValue()%>">
            	<%}%>
	            <input type="hidden" name="query" value="<%= textQuery %>">
	            <input type="hidden" name="pg" value="7105">
	            <input type="hidden" name="butval" value="export">
            </table>
         </form>

        <%
    }
    
    void printMultiRecordExportOptionList(JspWriter out, FormBean fbean, String textQuery, String filename) throws IOException 
    {
    	printExportOptionList(out, fbean, CommonOptionLists.getMultiRecordExportOptions(), textQuery, filename, null);
    }
    
    void printSingleRecordExportOptionList(JspWriter out, FormBean fbean, String textQuery, String filename, Boolean isArchive) throws IOException 
    {
    	printExportOptionList(out, fbean, CommonOptionLists.getSingleRecordExportOptions(), textQuery, filename, isArchive);
    }
    
	void printTitleAlt(JspWriter out, String titlealt) throws IOException
	{
	%>
		title="<%=titlealt%>" alt="<%=titlealt%>"
	<%
	}
	
	void printHiddenField(JspWriter out, String name, String value) throws IOException
	{
	%>
		<input type="hidden" name="<%=name%>" value="<%=value%>">
	<%
	}
	
	void printIdExportSelectBox(JspWriter out, BBSFormBean browseBean, SelectOption.OptionList exportList) throws IOException {
		printSelectBoxRow(out, "Export as:", "exportFormat", true, exportList, browseBean, Defines.BPROP_EXPORT_METHOD, null, null, "this.form.butval.value = 'export'; ");
	}

	void printSubmitOnEnterField(JspWriter out, String name, String inputType, String size, String action) throws IOException {
		%><input class="textbox" name="<%=name%>" type="<%=inputType%>" size="<%=size%>" onKeyPress="this.form.butval.value = '<%=action%>'; return submitenter(this, event);"><%
	}
	
	void printSubmitOnEnterField(JspWriter out, String name, String inputType, String size, String action, String value) throws IOException {
		%><input class="textbox" name="<%=name%>" type="<%=inputType%>" size="<%=size%>" value="<%=HTMLString.encodeForForm(value)%>" onKeyPress="this.form.butval.value = '<%=action%>'; return submitenter(this, event);"><%
	}	

	void printSubmitOnEnterBox(JspWriter out, String name, String inputType, String size, String action, String value) throws IOException {
		%>
		<td class="field">
			<% printSubmitOnEnterField(out, name, inputType, size, action, value); %>
		</td>	
		<%
	}	
	
	void printSubmitOnEnterFieldRow(JspWriter out, String label, String name, String inputType, String size, String action) throws IOException {
%>
		<tr>
			<td class="field"><%=label%></td>
			<td class="field"><%printSubmitOnEnterField(out, name, inputType, size, action);%></td>
		</tr>
<%
	}
	
	void printSubmitOnEnterFieldRow(JspWriter out, String label, String name, String inputType, String size, String action, String value) throws IOException {
%>
		<tr>
			<td class="field"><%=label%></td>
			<td class="field"><%printSubmitOnEnterField(out, name, inputType, size, action, value);%></td>
		</tr>
<%
	}
}
%>