• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jsp:setProperty

 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

When is it permitted to use an expression/scriptlet inside a set property standard action ?
eg.
<jsp:setProperty name="someBean" property="someProperty" value=<%=request.getParameter("someParam")%>/>

My understanding is that it is permitted as long as the property we are trying to set is a string and the output of the expression/scriplet is also a string...
 
Manish Moorjani
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works as well, so I don't think there is any restriction on the type of object which can be set
<jsp:setProperty name="car" property="id" value="<%=Integer.parseInt(request.getParameter(\"userId\"))%>"/>
 
Vishnu Prakash
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Setting the "value" attribute using scriptlet code is NOT considered Best Practices. If you are using scriptlets in "value" attribute then automatic conversion from string to int handled by the container will NOT happen and result in compilation error.
 
vipul patel
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with vishnu. Better we use the naming convention and take advantage of great features of <jsp:useBean> tag.

Name the parameters in HTML form and properties of a bean same. and use the param attribute of <jsp:useBean> tag. Put param="*" and everything will just work fine.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic