• 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

Bean setters not invoked when no data entered in form fields

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bean setters not invoked when no data entered in form fields
=======================================

I began by coding the Emp JavaBean in the usual way. The hardcoded values are debugging.
The Problem :
If I enter data into the form fields then the JSP displays 9999 and DEFAULT. OK.
If I do not enter data into form fields or use the Delete key to remove existing data then
displayed : empNo is null
empName is null
I want my bean to validate that these mandatory fields are entered and I want to place
this logic inside my set methods.

Thank you for any help.

The JavaBean :



The Form :

The JSP :
 
Sheriff
Posts: 67747
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
You're submitting a form to a JSP? That's a rather 1999 thing to be doing. Best practice is to submit to a servlet controller.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I am not sure if this is going to solve your problem... try:




According to the theory, if the container cant find the bean, it will create it and execute what is inside of the body of jsp:useBean... am I right?
 
Bear Bibeault
Sheriff
Posts: 67747
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
I believe that that is the expected (if undesirable) behavior. Better to gather the data in a servlet where you have more control.
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed. If you check out the setProperty tag you will find out that
"If a parameter has an empty or null value, the corresponding bean property is not set. "

An empty string counts as "empty" for purposes of this tag, and so the setter is not called.
 
Jessid Leon Velez Gutierrez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:Indeed. If you check out the setProperty tag you will find out that
"If a parameter has an empty or null value, the corresponding bean property is not set. "

An empty string counts as "empty" for purposes of this tag, and so the setter is not called.



mmm now i understand. I did not know this.... thanks a lot for your answer
 
Graeme Byers
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Jessid.
For other replies , I know about Controller servlets but I was just following examples in Bergsten's JSP book.
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic