Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Checking if the object is new in JSTL

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I am working on a Spring project where there are two controllers

AddOwnerForm.java & EditOwnerForm.java. Both the forwarding the flow to form.jsp

AddOwnerForm passes a new Owner object to jsp whereas EditOwnerForm fetches the Owner object from the db then passes it to the jsp.

Below is the JSP code.

Form.jsp



I don't understand this code snippet



A. How is the Jstl tag checking if the Owner object is new. Is "new" a keyword for JSTL?

B. Why are they using a PUT method for editing the owner why not POST?
 
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A: ${object['property']} is one way to access a property on an object in Expression Language, same as ${object.property}

B: Please, have a look at the question and the answer here: http://stackoverflow.com/questions/630453/put-vs-post-in-rest
 
Sheriff
Posts: 67651
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
The person who wrote this expression: test="${owner['new']}" needs to be chastised.

While it's technically correct, the long form to reference properties should not be used with a literal string in this way simply because it is unconventional, unexpected, and confusing. The OP's question reflects that. The expression should have been written as: test="${owner.new}"

Not following conventions is a sure way to make your code look like it was written by a novice.

Then it becomes much clearer that "new" is not some magic JSTL property, it's simply a property of the owner bean.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic