0

I have been setting a public string from apex controller's constructor at the end. I can see that value in debug log. But when I pass that to Apex page it shows null.

Can someone please let me know where i do wrong?

public String abc {get;set;}

This is what I declare.

My Constructor:

public Vaultdoc(){

...................

while (parser2.nextToken() != null) {  
    if (parser2.getCurrentToken() == JSONToken.FIELD_NAME) {
        String fieldName = parser2.getText();
        parser2.nextToken();
        if (fieldName == 'responseStatus') {
            //accesstoken = parser.getText();
            system.debug('responseStatus Text() => ' + parser2.getText());
        } else if (fieldName == 'document_id__v') {
            //expiresIn = parser.getIntegerValue();
            DocumentID = parser2.getText();
            system.debug('DocumentID Text() => ' + parser2.getText());
        } else if (fieldName == 'token__v') {
            //expiresIn = parser.getIntegerValue();
            tokenId= parser2.getText();
            system.debug('token__v Text() => ' + parser2.getText());
        } 
    }
} 

System.debug('TokenID@'+tokenId);
System.debug('DocumentID@'+DocumentID);

}

After parsing a JSON response of httprequest POST, my constructor prints TokenID@XXXXXXXXX fine but in VF Page it is null.

In VF Page I have only an output text.

<apex:outputText value="Token@{!tokenId}" /> 
4
  • There's nothing wrong with that code. You'll want to edit in some more details.
    – sfdcfox
    Aug 23, 2017 at 16:32
  • Why do you think something is wrong? Are you getting an error message? What is the expected behavior here? What behavior do you observe?
    – Adrian Larson
    Aug 23, 2017 at 17:07
  • 2
    Also, there is almost never a good reason to roll your own JSON parsing. Just use serialize/deserialize.
    – Adrian Larson
    Aug 23, 2017 at 17:08
  • When I fetch in page I am not getting the token. It is null
    – user59759
    Aug 23, 2017 at 18:55

1 Answer 1

1

You have not declared the "tokenId" as a get-set property to be binded with the apex page.

You should declare it as

public String tokenId {get;set;}
1
  • Yes that simply worked, I am sorry my debug was having issue Aug 24, 2017 at 8:44

You must log in to answer this question.

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