Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@DefaultValue doesn't work with @FormParam

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • 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")
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • 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
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 7
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • 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
Java MySQL Database PHP
  • 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
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • 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
Java MySQL Database PHP
  • 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
Saloon Keeper
Pie
Posts: 2534
113
Android Chrome Eclipse IDE
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic