• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Marcus Green Notes , Question on c:set

 
Archana Annamaneni
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am reading Marcus Green notes for SCWCD as I am preparing for the exam.

I try to run sample code for <c:set> using target for Benas and Maps.Section 9.3

Here is the code



The JSP page is as follows





I am getting the following exception

javax.servlet.jsp.JspTagException: Invalid property in <set>: "MyField"
at org.apache.taglibs.standard.tag.common.core.SetSupport.doEndTag(SetSupport.java:188)
at org.apache.jsp.demo_jsp._jspx_meth_c_set_1(demo_jsp.java:147)
at org.apache.jsp.demo_jsp._jspService(demo_jsp.java:91)

Could someone please tell me what is going wrong


Thanks
Archana
 
Rufus Addis
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marcus' notes are IMHO a little confusing in this example, and I can see why you made a mistake.

In the DemoBean class the instance variable "MyField" should IMHO follow the naming conventions and have a lowercase leading letter - myField.

The getter and setter methods should / will automatically capitalize the variable in the method name i.e. getMyField setMyField .

Then in the jsp the <c:set...> will refer to the instance variable by it's uncapitalized name:

<c:set target="${demo}" property="myField" value="guru" />

In your example you've capitalized the property to match the instance variable (which is wrongly named). However the set tag handler can't then capitalize this to identify the appropriate setter method.

e.g. it can't turn MyField in the getMyField but it can turn myField in to getMyField

Confused?

Rufus.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rufus, please check your private messages.
 
Martin Vician
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Field name MyField has nothing to do with a property name of Javabean. It could have been something completely different like this:



And even then the name of the property would be myField, because it is derived from getter method.

So basically the only change needed here is this:



("MyField" changed to "myField")
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic