This week's giveaway is in the Threads forum.
We're giving away four copies of Java Concurrency Live Lessons and have Doug Schmidt on-line!
See this thread for details.
Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing bean value in jsp page  RSS feed

 
Rajeev Mutalik
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to get the value from a bean and pass it across to a javascript. I am getting the error, the variable ptName is undefined. Can someone help me on this. Here is my code snippet.

<bean:define id="ptName" name="point" property="name"/>
<c:set var="searc" value="'" />
<c:set var="repl" value="`" />
<c:set var="ptName" value="${fn:replace(ptName, searc, repl)}"/>
<a href="javascript: parent.editPoint(parent.PointEditForm, '<bean:write name='point' property='id'/>', '<bean:write name='point' property='sortOrder'/>', ptName, '<bean:write name="point" property="info"/>', '<bean:write name='point' property='type.id'/>', '<bean:write name='point' property='sendMail'/>', '<bean:write name="point" property="mail"/>', '<bean:write name='point' property='CustList'/>', '<bean:write name='point' property='myId'/>', '<bean:write name='point' property='origin'/>' );">
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is <bean:define>? It is not a standard JSP action. If you are using a framework or set of custom tags, you need to let us know which one.
 
Mark Senior Liu
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You confused javascript variable with java variable.

ptName you defined is a page scope java variable.

You can use it like this in javascript:

'${ptName}'
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Senior Liu wrote:You can use it like this in javascript:

'${ptName}'

To be accurate, that doesn't really "use it" in JavaScript, it writes out the value into the response, which then becomes the markup of the page.
 
Rajeev Mutalik
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Mark and Bear.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!