Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in making Model class singleton

 
MaheshS Kumbhar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
James Peter
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 9280
10
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic