File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Getting error message using JavaBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Getting error message using JavaBean" Watch "Getting error message using JavaBean" New topic
Author

Getting error message using JavaBean

Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
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

Joined: Feb 23, 2009
Posts: 1183
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.


JDBCSupport - An easy to use, light-weight JDBC framework -
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

If you create a "getter" that returns the map, it's easy to address maps:


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61095
    
  66

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

Joined: Jan 10, 2002
Posts: 61095
    
  66

so in your example, your bean would change as follows:


Then in your JSP:


How easy is that?!
hexin orsen
Greenhorn

Joined: Aug 14, 2009
Posts: 4
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

Joined: Apr 01, 2003
Posts: 120
Thanks a lot for all the feedback.
Sunder Ganapathy
Ranch Hand

Joined: Apr 01, 2003
Posts: 120
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting error message using JavaBean