This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • 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
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

@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: 3293
297
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: 3293
297
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: 3293
297
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: 3293
297
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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!