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.

sharcfinz
  • 465
  • 1
  • 6
  • 24
  • 1
    Use this one... `alert("#{dBean.strIssueDate}");` and for more info see [this link](http://stackoverflow.com/questions/14966205/getting-backing-bean-value-with-javascript), may be it will help you... ;) – bud-e Nov 16 '14 at 01:50
  • Hi @Mischievous, tried that and no dice. Thanks though! – sharcfinz Nov 16 '14 at 02:52
  • Only to understand: how are you sending the data from the back-end to the front-end? – Almir Campos Nov 16 '14 at 04:44
  • Same a Almir, just for understanding : Is the javascript code inside your JSP between ` – Patouche Nov 16 '14 at 09:05
  • Hi @AlmirCampos, the only place that I set the value in the front end, is using the dom: $('#content').data("strIssueDate", ""); I tried setting it again in the js with $('#content').data("strIssueDate", strIssueDate); but that causes the application to hang. – sharcfinz Nov 16 '14 at 12:42
  • Hi @Patouche, I've added more detail in my description. Does that help? The javascript file is a separate javascript file. The original date value that is shown (via the mapping from the DOM), will be replaced with the alert value that I'm trying to get. I can see via an output from the java file that the value has been set, but I just can't seem to access the updated value in the js. – sharcfinz Nov 16 '14 at 12:46
  • It looks like that the jsp page that is updating the code is calling the jQuery library and that the one has the code 'alert("${dBean.strIssueDate}");' isn't (you're using jQuery, right?). Did you try to add the jQuery on the second jsp? – Almir Campos Nov 16 '14 at 18:18

1 Answers1

0

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

alert($("#content").data("strIssueDate"));
jax
  • 37,735
  • 57
  • 182
  • 278