• Post Reply Bookmark Topic Watch Topic
  • New Topic

Checking if the object is new in JSTL

 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • 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?
 
Albareto McKenzie
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65530
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!