• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to get Back Bean updated property value in javascript function

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I need help to get updated bean property in javascript function. This function I am calling from <a4j: commandbutton> this button is having actionListner, which is updatin bean property based on some User selection. When this action is completed then I am calling javascript function in oncomplete. But that javascript function is not taking updated bean value, it is always taking first value. Please help me, I can't use hidden text as there are some drop downs which User will selct and then hit commandbutton which will update bean property.

<div align="center">
<a4j:commandButton
value="#{msgs.notification_searchNotificationReportLbl}"
id="searchNotificationRptBtn" styleClass="controlButtonActive"
actionListener="#{dashboardCtrl.loadOTVsubmit}"
oncomplete="drawChart();"


/>
</div>

<script type="text/javascript">
//bc udefined error solution
Array.prototype.reduce = undefined;
// Load the Visualization API and the piechart package.
google.load('visualization', '1.0', {
'packages' : [ 'corechart' ]
});

// Set a callback to run when the Google Visualization API is loaded.
google.setOnLoadCallback(drawChart);

// Callback that creates and populates a data table,
// instantiates the pie chart, passes in the data and
// draws it.
function drawChart() {
// Alert
alert("In Drawchart function"+#{pieChartMBean.pieChartData});
// Create the data table.
var data = google.visualization.arrayToDataTable([
[ 'Country', 'Area(square km)' ],
#{pieChartMBean.pieChartData}
]);

// Set chart options
var options = {
'title' : 'Overall Transaction Volume',
is3D : true,
pieSliceText : 'label',
tooltip : {
showColorCode : true
},
'width' : 900,
'height' : 500
};

// Instantiate and draw our chart, passing in some options.
var chart = new google.visualization.PieChart(document
.getElementById('chart_div'));
chart.draw(data, options);
}
 
Saloon Keeper
Posts: 27861
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I do not recommend using actionListeners. They have a purpose, but it is so specialized that I cannot recall a single webapp I've ever done in JSF that required one. An action method is POJO, and thus less platform-specific.

Besides, when using RichFaces 4, the a4j tags are supplanted by JSF2 f:ajax tags, and the f:ajax listener is a completely different construct than an actionListener, and sends a completely different parameter. So avoid confusion.

The reason why your updated data isn't being seen is because you didn't tell the View to refresh its data after the ajax process. Use the reRender a4j:commandButton attribute to indicate what elements of the View should be re-rendered (updated) after the ajax call is done.


 
Shikha bajpai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Holloway wrote:I do not recommend using actionListeners. They have a purpose, but it is so specialized that I cannot recall a single webapp I've ever done in JSF that required one. An action method is POJO, and thus less platform-specific.

Besides, when using RichFaces 4, the a4j tags are supplanted by JSF2 f:ajax tags, and the f:ajax listener is a completely different construct than an actionListener, and sends a completely different parameter. So avoid confusion.

The reason why your updated data isn't being seen is because you didn't tell the View to refresh its data after the ajax process. Use the reRender a4j:commandButton attribute to indicate what elements of the View should be re-rendered (updated) after the ajax call is done.




Hi Tim, Thanks for your answer, but problem here is that what to reRender. loadOTVsubmit method will update one bean property, this updated bean property is passed to Javascript function which is using value of this to update Google chart. So I am not getting wht to reRender here in this case.


Please help to understand re can I put reRender="data" in below code.

<h:commandButton
value="#{msgs.notification_searchNotificationReportLbl}"
id="searchNotificationRptBtn" styleClass="controlButtonActive"
actionListener="#{dashboardCtrl.loadOTVsubmit}">
<a4j:jsFunction name="createEventpie" data="#{pieChartMBean.pieData}" oncomplete="drawChartsub(data);">
</a4j:jsFunction>
</h:commandButton>
 
Tim Holloway
Saloon Keeper
Posts: 27861
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There's a "Code" button on our message editor. You can use this to insert special tags into the text you are editing that will preserve the formatting of structured text such as Java and XML and make it easier to read.

It's not intuitively obvious, but the reason that your data isn't being updated is because EL expressions are not dynamic. They're expanded to produce client-side text. So an expression like:



is not stored in the client as such. Instead, when the page is initially rendered, the renderer evaluates the EL expression "#{pieChartMBean.pieChartData}" and renders the results into the page that's actually sent back to the client (do a View Page Source in your browser and you'll see).

So in order to update that data, you have to re-render the part of the View (web page) that that expression is defined in. At which time the renderer will render an expansion of the updated data.

Normally when I have stuff like that, the data expression is part of a container of some sort (for example, an HTML div bound to a Google Maps control) and therefore I'd simply re-render the div, updating the data, map, and everything. You have free-floating code, so i'm less certain how I'd handle that.
 
Shikha bajpai
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Will above work..
 
Tim Holloway
Saloon Keeper
Posts: 27861
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No.

reRender takes a list of JSF element IDs. If you put EL expressions in that list, the EL will be evaluated and substituted into the reRender text.

For example, if PieChartMBean's getPieData() method returned "Mary had a little lamb", then your code would be equivalent to:



And it would get annoyed because you probably don't have element tags with IDs of "Mary", "had", "a", "little", or "lamb".
 
I love a woman who dresses in stainless steel ... and carries tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic