Re: Need help!!
The main part in JSP:
here I am calling the javascript method and generating the Buttons:
<%
if ( null != userTypes )
{
UserTypes.UserType[] userTypeArray = userTypes.getUserTypes();
for ( int utIndex = 0; utIndex < userTypeArray.length; utIndex++ )
{
String text = userTypeArray[utIndex].getName();
System.out.println("The value of user types are: " + text + "\n\n");
int[] utfns = userTypeArray[utIndex].getFunctionIDs();
for(int j=0; j<utfns.length; j++)
{
System.out.println("The value of user types functions are: " + utfns[j] + "\n\n");
}
%>
<tr>
<td> </td>
<td align="center">
<input type="button" class="button_long" name="user.types" value="<%=text%>" onclick="handleUserTypeFunctions();" />
</td>
</tr>
<%
}
}
%>
***********************************************
The java class file:
/*
* Description:
*
* Encapuslates global settings for product.
*
* Copyright 2003-2004 by RF Technologies.
*
*/
package com.rft.base;
import org.w3c.dom.*;
public class UserTypes extends XMLObject
{
public static final String UserTypesRoot = "UserTypes";
public class UserType extends Object
{
public static final String UserTypeRoot = "UserType";
public static final String UserTypeName = "name";
public static final String UserTypeFunction = "function";
private String name; // Name of this user type
private int[] functionIDs; // Array of the default function IDs associated with this user type
private void init()
{
setName( "" );
setFunctionIDs( new int[0] );
}
public UserType()
{
super();
init();
}
public UserType( Node theNode )
{
super();
init();
if ( ( null != theNode ) && ( theNode.getNodeName().equals( UserTypeRoot ) ) )
{
setName( getNodeAttribute( theNode, UserTypeName ) );
int fIndex = 0;
int [] nodeFunctionIDs = new int[theNode.getChildNodes().getLength()];
for ( Node functionNode = theNode.getFirstChild(); functionNode != null; )
{
if ( UserTypeFunction == functionNode.getNodeName() )
{
nodeFunctionIDs[fIndex] = Integer.parseInt( functionNode.getFirstChild().getNodeValue() );
fIndex += 1;
functionNode = functionNode.getNextSibling();
}
}
setFunctionIDs( nodeFunctionIDs );
}
}
public String getName()
{
return name;
}
public int[] getFunctionIDs()
{
return functionIDs;
}
public void setName( String newName )
{
name = newName;
}
public void setFunctionIDs( int[] newFunctionIDs)
{
functionIDs = newFunctionIDs;
}
/**
* @return String
*/
public String toString()
{
StringBuffer theBuf = new StringBuffer();
theBuf.append( "Class: " + UserType.class.getName() );
theBuf.append( "\nName: " + name );
for ( int fidIndex = 0; fidIndex < functionIDs.length; fidIndex++ )
{
theBuf.append( "\nAssociated function ID: " + functionIDs[ fidIndex ] );
}
return theBuf.toString();
}
}
private static final String mySynchronizationFlag = "UserTypes";
private static UserTypes utInstance = null;
private UserType[] userTypes; // Array of pre-defined user types
private void init()
{
setUserTypes( new UserType[0] );
}
public UserTypes()
{
super();
init();
}
public UserTypes( Node theNode )
{
super();
init();
if ( ( null != theNode ) && ( theNode.getNodeName().equals( UserTypesRoot ) ) )
{
NodeList userTypeNodes = theNode.getChildNodes();
setUserTypes( new UserType[userTypeNodes.getLength()] );
for ( int nIndex = 0; nIndex < userTypeNodes.getLength(); nIndex++ )
{
if ( userTypeNodes.item( nIndex ).getNodeName().equals( UserType.UserTypeRoot ) )
{
userTypes[nIndex] = new UserType( userTypeNodes.item( nIndex ) );
}
}
}
}
public static void newInstance( UserTypes ut )
{
synchronized ( mySynchronizationFlag )
{
utInstance = ut;
}
}
public static UserTypes fetchInstance()
{
synchronized ( mySynchronizationFlag )
{
if ( null == utInstance )
{
utInstance = new XMLUserTypesBean().retrieveUserTypes();
}
}
return utInstance;
}
public UserType[] getUserTypes()
{
return userTypes;
}
public void setUserTypes( UserType[] types )
{
userTypes = types;
}
/**
* @return String
*/
public String toString()
{
StringBuffer theBuf = new StringBuffer();
theBuf.append( "Class: " + UserTypes.class.getName() );
for ( int utIndex = 0; utIndex < userTypes.length ; utIndex++ )
{
theBuf.append( "\n" + userTypes[utIndex].toString() );
}
return theBuf.toString();
}
}