• 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

why we use default constructor in Bean class to avoid useBean class attribute "..." is invalid.

 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everyone,
why is it necessary to have default constructor in bean classes if i'm using Expression language or jsp standard tags.??


In my sevlet I'm calling parameterised constructor and if i don't use expression language then jsp page is working fine.
If I use directive like<@ page import="model.User"> And
If I retrieve User object from request using scriplet<%User user=request.getAttribute("user");%>
then it works fine.

If i use EL/jsp standard tag then If i don't use default constructor in m bean class even though i'm not invoking it
then i'm getting The value for the useBean class attribute "..." is invalid.

why??


thanks in advance
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The EL and JSTL rely upon beans actually being beans. If a class does not have a nullary constructor ("default" constructor is not the correct term), then it is breaking the rules and it is not a bean. So you cannot expect things to work correctly when you break the rules.

It's as simple as that. Follow the rules.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, you aren't actually using the <asp:useBean> tag in a non-scriptlet JSP, are you? :shock:

 
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic