jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes Deserialize and display an object's attributes in UI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Deserialize and display an object Watch "Deserialize and display an object New topic
Author

Deserialize and display an object's attributes in UI

Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Hello -

I am new to Java and am taking a class that I thought was to learn Java, but instead it's more of a class on how to design
Java apps using design patterns and n-tier architecture. Thus far, I'm managing to work my way through the class and trying to
learn Java coding at the same time, but it's proving difficult to do both at once. I am going to take the next few terms off of school and focus on learning the Java language, but need to get through this class for now.

Anyway, my project is a VERY basic contact manager app.

I'm working on the UI and a lookupClient (where Client is the contact) use case.

I've been working for days on this and am getting a little closer, but am getting frustrated and thought I'd see
if I can get some help.

For the lookupClient use case/method, what I want to do is this:

1) get User input (a first name and a last name) from the UI
2) check to see if a client.ser file with that input exists
3) if a client.ser file matching that input exists, then deserialize the client object and display its attributes
(first name, last name, street, home phone, mobile phone and children)
in the UI for the user to see
else display a message "Client not found"

I've included the code I have thus far for the UI and the lookupClient method.

Any help would be greatly appreciated.

Sorry in advance for all the code, but I didn't to leave something out that may be needed to help.

Thanks!!!

UI Code




ClientMgr code




IClientSvc Implementation Code



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
So what's missing to make this code work? In other words, what is and isn't working, and how does that deviate from what you think should and should not be working?


Ping & DNS - my free Android networking tools app
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Hello -

Thanks for the quick reply.

I updated the code to include the else..., but I don't have it right.





Here is what is happening:

* I run it and in the UI enter a Clients first name (Betty) and last name (Rubble)
(a serialized file BettyRubble.ser exists that was created from the Add Client Event
and contains first name, last name, home phone, mobile phone and children data)
* The UI displays Betty Rubble, but not the rest of her data.
* In the console, this displays
Begin lookupClient method
End lookupClient method


Am I correct that it is taking the input from the UI correctly and checking for the file and that
the problem is that I don't know how to tell it to display/return the attributes?
* If I enter the name of a Client that does not exist, nothing happens in the UI,
but the console displays "Client not found"

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
Here's the problem:
cm.lookupClient(c);

The method returns the Client object that was read from the file, but the code ignores it, instead using the "c" object (which contains only the data items you entered in the GUI). This should read
Client serializedClient = cm.lookupClient(c);

and then the following lines would use the serializedClient object.
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Hmmm, I tried that but got the same results.



Would I somehow need to change the return in the ClientMgr or the ClientSrv Implementation?

I really appreciate your help.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
You missed this part:
Ulf Dittmer wrote:and then the following lines would use the serializedClient object.

Currently your code does not make use of the serializedClient object.
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Sorry, I'm not getting this.

Is this what you mean?




If so, I ran it and got the same results.

I really appreciate you trying to help me
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42031
    
  64
There's also a problem in ClientMgr.lookupClient: it's returning the original object, instead of the one read from the file.
Lori Gardner-Wilson
Greenhorn

Joined: Jun 03, 2009
Posts: 11
Thanks! That gives me a place to start. I need to do some research on syntax for returning deserialized objects, and probably returning objects in general. I'll dig into that first.

Thanks again for your time and help. This is a great site for beginners.
 
GeeCON Prague 2014
 
subject: Deserialize and display an object's attributes in UI