Meaningless Drivel is fun!*
The moose likes Struts and the fly likes Problem in making Model class singleton Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem in making Model class singleton" Watch "Problem in making Model class singleton" New topic
Author

Problem in making Model class singleton

MaheshS Kumbhar
Ranch Hand

Joined: Sep 24, 2009
Posts: 188
I have following action class





I have following Employee model class





I have marked the no-argument constructor of Employee class as private as I want to make it singleton.
I have a form page asking username and password (with form field names emp.name and emp.password) that is mapped to Login.java Action. But when I submit form, I get an exception that saying it cannot create Employee object as its constructor is marked as private.
So how do I solve this problem still keeping the Employee object as singleton?


I am slow but sure
James Peter
Ranch Hand

Joined: Sep 15, 2010
Posts: 115
Hi,

I prefer to use modeldrivenaction.

http://www.vaannila.com/struts-2/struts-2-example/struts-2-model-driven-action-example-1.html

For Singleton please check below site

http://www.javadb.com/how-to-create-a-singleton-object
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8836
    
    7

MaheshS Kumbhar wrote:
So how do I solve this problem still keeping the Employee object as singleton?


Why would you do such a thing? Are you going to have an application where only one person ever logs in?
You should also be aware that the Singleton design pattern is considered evil.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem in making Model class singleton
 
Similar Threads
comparable program counstructor not found exception
persistence.xml file for MS SQL Server 2000
Getting transient variable values while deserializing
Can't write collection back to disk
Help with this code!