Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

@DefaultValue doesn't work with @FormParam

 
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was just playing with FormParam annotation , I tried to use @DefaultValue annotation along with @FormParam to give some default value to form parameters.

But it doesn't works. Below is the code



If I don't type anything for name input field in HTML form, it doesn't take default value specified with the @FormParam("name")
 
Creator of Enthuware JWS+ V6
Posts: 3285
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This should work. What server are you using?
 
Mahtab Alam
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 7
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3285
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the annotation work with any of the other annotations: @PathParam, @QueryParam, @MatrixParam, @CookieParam, or @HeaderParam?

You can also try to use the GlassFish server instead (it has a Jersey implementation out of the box)
 
Mahtab Alam
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@DefaultValue works as expected with @QueryParam , @HeaderParam , @MatrixParam
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3285
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, and what happens if you don't POST the "name" field at all? Only post an empty form.
 
Mahtab Alam
Ranch Hand
Posts: 391
1
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I submit empty form @DefaultValue works. But why it doesn't work while submitting the name field empty
 
Frits Walraven
Creator of Enthuware JWS+ V6
Posts: 3285
296
Android Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

But why it doesn't work while submitting the name field empty


Because it contains a String (although empty), and therefore the default value won't be used in this case.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!