0

How can I get the value of my bean to display from my javascript file?

My bean - dBean.strIssueDate

In the $(document).ready(function() of my jsp, I set the following:

$('#content').data("strIssueDate", "<c:out value="${dBean.strIssueDate}"/>");

My problem is that the date is updated (and it's correctly updated in the database), but I would like to call the value from the javascript file.

The update begins with a checkbox on another jsp page, which updates the data value via a java file, and then triggers the function in the javascript file, which is where my alert is called.

My (incorrect) code in the javascript file (which is not between tags, but just a file consisting of only js:

alert("${dBean.strIssueDate}");

which shows on the alert as ${dBean.strIssueDate}

I've tried removing the double quotes, substituting for single quotes, swapping the $ for a #, but nothing seems to work.

7
  • 1
    Use this one... alert("#{dBean.strIssueDate}"); and for more info see this link, may be it will help you... ;) Commented Nov 16, 2014 at 1:50
  • Hi @Mischievous, tried that and no dice. Thanks though! Commented Nov 16, 2014 at 2:52
  • Only to understand: how are you sending the data from the back-end to the front-end? Commented Nov 16, 2014 at 4:44
  • Same a Almir, just for understanding : Is the javascript code inside your JSP between <script> tag or is it a separate javascript file ? When you say "updated", how do you expect the value will be updated in the view ? Commented Nov 16, 2014 at 9:05
  • Hi @AlmirCampos, the only place that I set the value in the front end, is using the dom: $('#content').data("strIssueDate", "<c:out value="${dBean.strIssueDate}"/>"); I tried setting it again in the js with $('#content').data("strIssueDate", strIssueDate); but that causes the application to hang. Commented Nov 16, 2014 at 12:42

1 Answer 1

0

Looks like you are using JQuery and have already set the date on the #content so what about this.

alert($("#content").data("strIssueDate"));
Sign up to request clarification or add additional context in comments.

1 Comment

Hi @jax, this comes up as undefined.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.