• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting error message using JavaBean

 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The relevant Bean code is as follows where errors is a hashtable.



If I use it returns the error message correctly.

If I change it to I get the following error.
:javax.el.PropertyNotFoundException: Property 'errorMsg' not found on type com.Login

How to overcome this problem.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EL strictly follows the JavaBean standard.
JavaBean Getters do not have arguments. And you cannot pass argument to EL.

If your bean property would look like this



then $handler.errors would return the property.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you create a "getter" that returns the map, it's easy to address maps:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember, the EL wasn't introduced just to be a one-to-one replacement for Java code in a JSP -- that would have been senseless.

Rather, the EL is specifically designed to help you do the things that you should be doing in JSP pages, and to prevent you from doing what you shouldn't.

It requires a little bit of a change in thinking. This is a good example of that. You don't want to expose general methods, but rather bean getters. And by having a getter that exposes a map, you can key into that map with ease.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64990
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so in your example, your bean would change as follows:


Then in your JSP:


How easy is that?!
 
hexin orsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think that is not preciseness:
public String getErrorMsg(String msg)
{
errorMsg =(String)errors.get(msg.trim());
return (errorMsg == null) ? "":errorMsg;
}
if parameter of getErrorMsg is null,there is NullPointerException that you using msg.trim() .if you are not sure msg is not null,so your code shoud change .
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for all the feedback.
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Bear. You mentioned "It requires a little bit of a change in thinking.".
You helped me to achieve. Thanks a lot once again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic