[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ganymede Help] setting a field value...

Date Thu, 16 May 2002 13:19:59 -0500
From Jonathan Abbey <jonabbey@arlut.utexas.edu>

On Tue, May 14, 2002 at 02:53:34PM -0400, Gaurav Bhargava wrote:
> Hi Jon,
> I am trying to set a value in a field in the finalizeSetValue() method
> It doesnt give me any error but it just doesnt set any value ....please 
> have a look at it.

Righto.

> public synchronized ReturnVal finalizeSetValue(DBField field, Object 
> value)  
>    {
>    	StringDBField strField;
>    	if (field.getID() == OWNER)
>     {  
>        System.out.println("I am here "); 	
>        strField = (StringDBField) getField(ROOMNUMBER);
> 	   strField.setValueLocal("Value set");
> 	   System.out.println("I am now here");
> 	}
> return null; // success!
> }

So you're wanting the ROOMNUMBER field to be changed whenever the
OWNER field is changed?

The thing is, you don't know for sure that the
strField.setValueLocal() call succeeded, because you're not checking
its return value.

What you want is something like this:

public synchronized ReturnVal finalizeSetValue(DBField field, Object value)  
{
  StringDBField strField;
  ReturnVal retVal = null;

  if (field.getID() == OWNER)
    {  
      System.out.println("I am here "); 	
      strField = (StringDBField) getField(ROOMNUMBER);
      retVal = strField.setValueLocal("Value set");
      System.out.println("I am now here");

      return retVal; // success or failure
    }

  return null;  // if we weren't changing the OWNER field, always approve
}

This way, if the strField.setValueLocal() call fails for some reason
(and there can be a lot of reasons why a field setValueLocal call will
fail, depending on the constraints placed on the field and on the
custom coding you've done elsewhere in this class), you'll pass the
error dialog along.

You could also do something like this:

public synchronized ReturnVal finalizeSetValue(DBField field, Object value)  
{
  StringDBField strField;
  ReturnVal retVal = null;

  if (field.getID() == OWNER)
    {  
      System.out.println("I am here "); 	
      strField = (StringDBField) getField(ROOMNUMBER);
      retVal = strField.setValueLocal("Value set");

      if (retVal != null && !retVal.didSucceed())
        {
          System.out.println("Error setting ROOMNUMBER field!");
          System.out.println(retVal.getDialogText());
        }

      System.out.println("I am now here");

      return null; // approve the operation even if setting the ROOMNUMBER failed
    }

  return null;  // if we weren't changing the OWNER field, always approve
}

> I also have a field called ipaddress on which i have to use the same 
> method setValueLocal() to set the value(the field is a IPDBField). Can 
> you tell me as to what parameter the method will accept.......like if a 
> setValueLocal() is used on a string field it takes  string as a 
> parameter....will it take a string???

When you're setting an IP address in an IPDBField, you need to have
value be an array of Byte objects, of length 4 if you're setting an
IPv4 address, or of length 16 if you're setting an IPv6 address.

> Thanks
> Gaurav

Hope this helps.

-- 
-------------------------------------------------------------------------------
Jonathan Abbey 				              jonabbey@arlut.utexas.edu
Applied Research Laboratories                 The University of Texas at Austin
Ganymede, a GPL'ed metadirectory for UNIX     http://www.arlut.utexas.edu/gash2

----------------------------------------------------------------------------
To make changes to your subscription to the Ganymede Help list, send
mail to majordomo@arlut.utexas.edu.

To unsubcribe, include the line

unsubscribe ganymede-help

in the body of your mail message

Visit the Ganymede web page at http://www.arlut.utexas.edu/gash2

----------------------------------------------------------------------------


  • Re: [Ganymede Help] setting a field value...
    • From: Jonathan Abbey <jonabbey@arlut.utexas.edu>