Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP setProperty  RSS feed

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, when we do the <jsp:setProperty> to a bean, all the parameters are converted to the proper types declared from within the bean and not just String? And when we assign values to a bean through request time expression, it is always String? What happens when it's not compatible?
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to make sure you pass the correct data type if you don't want to use string as the parameter arguments in your bean. An alternative is to make all your arguments as string type, then convert the string to the data type you desire in your bean methods. You must check the data type after you convert the string to its value. I like this way better. Hope this help.
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But when we assign values to beans at <jsp:setProperty> whether explicitly or by request parameters with "*", the values are automatically assigned the right data types?
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please help..
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use "*" to set the properties of your bean. However, some servers(JSWDK and JWS) does not do the auto conversion. You need to be awared of the null value and it is a very common situation if you use "*", manually check the null value will prevent the NullPointerException.
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<jsp:setProperty id="beanName" property="proName" value="i+1"> and <jsp:getProperty id="beanName" property="parameterName" /> deal with every value as a scalar; every value they receive is converted into a String. It is as the same as in servlet: request.getParameter("name") what you get is a String. Afterwards you need to convert as required in your code.
However, <jsp:setProperty id="beanName" property="*" />
matches name and as well as type with bean definition.
hope this help.

[This message has been edited by ruilin yang (edited July 02, 2001).]
 
ruilin yang
Ranch Hand
Posts: 334
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ruilin yang:
<jsp:setProperty id="beanName" property="proName" value="i+1"> and <jsp:getProperty id="beanName" propertyName="parameterName" /> deal with every value as a scalar; every value they receive is converted into a String. It is as the same as in servlet: request.getParameter("name") what you get is a String. Afterwards you need to convert as required in your code.
However, <jsp:setProperty id="beanName" property="*" />
matches name and as well as type with bean definition.
hope this help.

[This message has been edited by ruilin yang (edited July 02, 2001).]

 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What about
<%!int a=0;%>
<jsp:setProperty id="someBean" property="anIntProperty" value=a>
?
[This message has been edited by Cameron Park (edited July 02, 2001).]
 
SoonAnn Lim
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never pay attention to such example in my code before. However, according to the specification of the server, this should work. Shouldn't it?
 
Cameron Park
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My book said it should, but it is pretty vague that I got confused.
Thank you so very much.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!