• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
RabiDas Sharma
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!