In apex I have a method that return an wrapper object like this :

public class WrapperCalcul{
    public String nb;
    public String coutTot;

public static WrapperCalcul submitForm(String nb, String montant){
   WrapperCalcul wrapCalc = new WrapperCalcul();
    wrapCalc.nb = nb;
    wrapCalc.coutTot = montant;

    return wrapCalc;

I want to display the values of wrapCalc into a simple VF (one value in one field), how can I do that ?

  • is it important to use RemoteAction?
    – Ratan Paul
    Commented Jun 8, 2018 at 7:53
  • yes I call this method from JS (this is a one page form, that use JS to work). Is it annoying ?
    – dou
    Commented Jun 8, 2018 at 7:55

2 Answers 2


Can do something like,

<script type="text/javascript">
    function sampleJSRemoteFunction() {
        var nb; //get nb value
        var coutTot; //get couTot value

            nb, coutTot, 
            function(result, event){
                if (event.status) {
                    //handle the result. You can use js to populate these values in DOM.
                } else if (event.type === 'exception') {
                } else {
            {escape: true}

An Apex wrapper will be returned in the result object of the callback function stated within your Visualforce Remoting call. Refer the following link to understand what, the event and result object return - Handling Visualforce Remoting Response.

The sample code to access the Apex Wrapper class values and display them in on the Visualforce page is as below.

Visualforce Code

<apex:page id="pgDisplay" controller="DisplayRemotingDataSample" standardStylesheets="false">

    <script type="text/javascript">

       function getRemoteValues() {

                'Sample nb', //nb, 
                'Sample montant', //montant, 
                function(result, event){

                        console.log('Success: ' + result.nb);
                        document.getElementById('divNb').innerHTML = result.nb;
                        document.getElementById('divMontant').innerHTML = result.coutTot;
                    else if(event.type === 'exception'){
                        console.log('Callback failed ' + event.message);



    <!-- Clientside Controls with values returned through Visualforce Remoting -->
    <div id="divOutputClient">
        <div id="divNb"/>
        <div id="divMontant"/><br/>

    <input id="btnGetValue" onclick="getRemoteValues()" type="button" value="Submit" />


The above code passes 2 hard-coded string values to the Visualforce Remoting method as input params which are returned as a part of the Apex Wrapper. The result object returned within the callback is then used to display the values passed from the server within 2 div elements.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .