You need to sign in to do that
Don't have an account?
erikdozsa
Populate apex outputText field after picklist change
Dear all,
Could you please give me some example for the following case?
I have a picklist and based on the picked value I am doing some calculation in the background. I would like to display the calculated result in an outputText field right after I picked the value from the picklist.
How could I do that?
Thank you so much,
Use action support with the select list of the picklist and in the action of the actionsupport call an apex method. In the apex method just assign the selected picklist value in the value of the output text like this.
Controller
public String strInOutputText{get;set;}
public String selectedPkVal{get;set;}
public void callApex(){
strInOutputText = selectedPkVal;
}
Page
<apex:outputpanel id="Outputtext">
<apex:outputtext value="{!strInOutputText}"/>
</apex:outputpanel>
<apex:selectList value="{!selectedPkVal}">
<apex:actionsupport event="onchange" rerender="Outputtext" action="{!callApex}"/>
<apex:selectOption value="Your List Value"/>
</apex:selectList>
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
All Answers
Use action support with the select list of the picklist and in the action of the actionsupport call an apex method. In the apex method just assign the selected picklist value in the value of the output text like this.
Controller
public String strInOutputText{get;set;}
public String selectedPkVal{get;set;}
public void callApex(){
strInOutputText = selectedPkVal;
}
Page
<apex:outputpanel id="Outputtext">
<apex:outputtext value="{!strInOutputText}"/>
</apex:outputpanel>
<apex:selectList value="{!selectedPkVal}">
<apex:actionsupport event="onchange" rerender="Outputtext" action="{!callApex}"/>
<apex:selectOption value="Your List Value"/>
</apex:selectList>
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks
Hi, thanks so much, it is working fine now.
I have another question. I tried to add a label to the apex:outputtext like this:
<apex:outputtext value="{!strInOutputText}" label="User"/>
But the label did not show up. How could I do this?
Thanks,
The syntax is correct. Make sure that you have value in the variable strInOutputText. Then only the label will be displayed in the left of the value.
If the post helps you please throw KUDOS.
Thanks