• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in making Model class singleton

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic