aspose file tools*
The moose likes Beginning Java and the fly likes Variable value not being carried Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Variable value not being carried" Watch "Variable value not being carried" New topic
Author

Variable value not being carried

Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18
Really strange problem:



I have checked that 'temp' carries the correct value. However, no matter which method I use to set the variable it doesn't seem to stick. When I call the validate() function the value is NULL even though it has been set before.

The validate() function just some some validation on the variable 'suppliedInput'

Any ideas would be greatly appreciated.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

What does validate() look like?
Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18
Some simple length checking on the value that is set previously:




However, when the method is run the value is NULL.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Robin Heard wrote:Some simple length checking on the value that is set previously:




However, when the method is run the value is NULL.


What value is null?

Show the entire method body, and signature.

Put in print statements to show i, additionalDetailValidations.get(i), and additionalDetailValidations.get(i).additionalDetailValidationValue).

It's very hard to debug something that's shown in incomplete pieces, rather than an SSCCE.
Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18


The 'order' object is the same for both. Could it be to do with the fact that getAllItems() returns an array and then getAdditionalRequirementsType() also returns an array and I'm setting a value within that. It seems like the 'order' object isn't holding the variable the next time it is accessed.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2316
    
  49
Please supply the information Jeff has already asked for.

Could it be to do with the fact that getAllItems() returns an array and then getAdditionalRequirementsType() also returns an array and I'm setting a value within that

They can't be returning arrays or you would have [] to access an element in the array, I guess they are returning ArrayLists.

Add the following line to the line directly after the one where you set suppliedInput = temp and tell us what the output is.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

You've got too much going on on one line, you're not printing out intermediate values, and I still don't see an SSCCE or the body of the validation method. In short, you're not making it easy for anybody to help you.
Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18






[Server:server-one] 05:39:10,424 INFO [stdout] (http--0.0.0.0-80-5) Retrieving request parameter for 0: 123456789123456789123211231
[Server:server-one] 05:39:10,454 INFO [stdout] (http--0.0.0.0-80-5) In: 123456789123456789123211231
[Server:server-one] 05:39:10,455 INFO [stdout] (http--0.0.0.0-80-5) Out: 123456789123456789123211231
[Server:server-one] 05:39:10,528 INFO [stdout] (http--0.0.0.0-80-5) temp = 123456789123456789123211231, supplied Input 0 = null
[Server:server-one] 05:39:10,572 INFO [stdout] (http--0.0.0.0-80-5) Is: null but should: 20


Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2316
    
  49
Try changing:


to

Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18
The problem that would give me is that the value is not maintained in the 'order' object which is saved to a session.
Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18
It does work though when I change the code. Why does it not remember the variable being set when setting the value in the 'order' object?
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4181
    
  21

My guess is that somewhere in this mess:

You create new AdditionalDetail instances - i.e. each time order.getAllItems().get(i).getAdditionalRequirementsType(order.getrequestType()).get(t) gets called, given the same order, i, and t a new and unique AdditionalDetail object is created (probably a whole new list of them) and the created objects are never stored or reused. So each time you call that method the suppliedInput would be completely different. But that is a guess because you never do what Jeff asks you to do.


Steve
Robin Heard
Greenhorn

Joined: Sep 18, 2009
Posts: 18
Thanks Steve, getAdditionalRequirementsType() was reading from the DB and overwriting the value.
 
wood burning stoves
 
subject: Variable value not being carried