0

how can i assign a string to the value of the output text from my controller? Thank you in advance.

example

public List<schedule__c> a = new List<schedule__c>();
public PageReference check() {

checkSched();      

return null;      
}
public void checkSched(){
    for(teacher__c teacher: [select id,name, First_name__c, Subject__c, Room_assignment__c from teacher__c  ])
    {
       if(teacher.Id == selectedtId)
       {

          string a = ('this is not available for' + teacher.name);

    }

}  


}
  • gelay -- you're killing yourself with variable naming issues - a is declared as a List<Schedule__c> outside of your method and as an error value in the method. Although these are in different scopes, you only confuse yourself and the community. There are lots of resources on this, see for example - salesforce.stackexchange.com/questions/890/… as well as endless non Apex examples such as iwombat.com/standards/…. – cropredy Feb 17 '16 at 2:47
3

You need to take a getter setter variable

public string strName {get; private set;}

And in your constructor or method

strName  = 'Test string';

And VF page

<apex:outputText value="{!strName}" />

And you need to use rerender attribute to get updated value of strName

  • @Ratun Paul.But there is rerender tag in OutputText.. – Deepak Agarwal Aug 22 '17 at 9:18
  • @DeepakAgarwal have you confused with rerender and rendered attribute ? – Ratan Paul Aug 22 '17 at 9:23
  • no there is rendered att but not rerender in output text.I am using same syntax but unable to get output text on vf page.. – Deepak Agarwal Aug 22 '17 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.