• 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

Getting error message using JavaBean

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67749
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
If you create a "getter" that returns the map, it's easy to address maps:

 
Bear Bibeault
Sheriff
Posts: 67749
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
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
Sheriff
Posts: 67749
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
so in your example, your bean would change as follows:


Then in your JSP:


How easy is that?!
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for all the feedback.
 
Sunder Ganapathy
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic