Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing bean value in jsp page

 
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: 65542
110
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: 65542
110
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.
 
I was born with webbed fish toes. This tiny ad is my only friend:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!