It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

Need help!!

Need help!!

Postby Santanu on Wed Apr 08, 2009 9:45 pm

I am not expert in JS. I am trying to write a JS function which will hadle below:

I have created button of different user Types. When the user hit each button the Available functions and the Assigned functions associated with the user are going to display in two different boxes.

I have successfully getting the User types and the associated values with each user type in the JSP page but I am not really sure how to implement the java script function to handle the above functionality.

Here is the code where I am getting the user types and their associated functions.

UserTypes userTypes = UserTypesHandler.cacheRetrieve( session );


if ( null != userTypes )

{

System.out.println("\nThe value of userTypes.getUserTypes().length is: " + userTypes.getUserTypes().length + "\n");

UserTypes.UserType[] userTypeArray = userTypes.getUserTypes();


for ( int utIndex = 0; utIndex < userTypeArray.length; utIndex++ )

{

System.out.println("\nThe value of userTypeArray[" + utIndex + "] is: " + userTypeArray[utIndex].toString() + "\n");

}

}
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm

Re: Need help!!

Postby Santanu on Wed Apr 08, 2009 9:53 pm

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>&nbsp;</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();
}
}
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm

Re: Need help!!

Postby Santanu on Wed Apr 08, 2009 9:54 pm

This is the code for action handler

/**
*
* @param request HttpServletRequest
* @param response HttpServletResponse
* @throws WardenException
*/
public void handleRequest( HttpServletRequest request, HttpServletResponse response ) throws WardenException
{
try
{
logger.info( "UserTypesHandler::handleRequest - Begin..." );
String action = request.getParameter( "wardenAction");
String nextPage = WardenProperties.getInstance().getTemplateForAction( action );
String redirectString = "/WardenConfig/" + nextPage;
HttpSession session = request.getSession( false );

if ( true == action.equals( "view.user.types" ) )
{
UserTypes ut = new XMLUserTypesBean().retrieveUserTypes();
session.setAttribute( "user.types", ut.getUserTypes() );
logger.info( "UserTypesHandler::handleRequest - ut = " + ut.toString() );
}
else
{
throw new WardenException( "Unknown action request "
+ action
+ " received by UserTypesHandler." );
}

response.sendRedirect( redirectString );
}
catch( Exception e )
{
throw new WardenException( "Exception was " + e.toString() );
}
}
}
Santanu
 
Posts: 16
Joined: Sat Aug 09, 2008 5:20 pm


Who is online

Users browsing this forum: No registered users and 8 guests

cron