function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Meer SalmanMeer Salman 

Calling function behind events

Hi..

 

Is it possible to call a function of extensions behind the event in a VisualForce Page?

 

I have the following page I want to put the getDescription() method on 'onselect' event of 

<apex:inputfield value="{!newLine.Code_Combination__c}" />

 

How can I achieve this??

 


 

<apex:page standardController="Fin_Journal__c" extensions="Fin_LineManager">
<apex:form >
<apex:pageBlock id="pb" mode="Edit">
    <apex:pageBlockButtons >
        <apex:commandButton value="Click" action="{!getDescription}" rerender="pb"/>
    </apex:pageBlockButtons>    
    <apex:PageBlockSection columns="1">
            <apex:inputfield value="{!newLine.Code_Combination__c}" />
            <apex:inputfield value="{!newLine.Description__c}"/>
    </apex:PageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Please help in this.
Regards,
Meer Salman
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

There's a couple of ways you can do this:

 

1. Input fields support the onselect event, so you can wrap your method in an actionfunction and invoke it.  I'd avoid using 'get' as the prefix for action methods, as VF views those as property getters. Assuming its named showDescription:

 

  

<apex:actionFunction action="{!showDescription}" name=showdesc" rerended="<some ids>"/>

 <apex:inputField value="{!newLine.Code_Combination__c}" onselect="showdesc()" />

 

 

2. Use an apex:actionsupport, this invokes the method directly from the component:

 

 <apex:inputField value="{!newLine.Code_Combination__c}">
<apex:actionSupport event="onselect" action="{!showDescription}" rerender="<some ids"/>
</apex:inputField> 

All Answers

bob_buzzardbob_buzzard

There's a couple of ways you can do this:

 

1. Input fields support the onselect event, so you can wrap your method in an actionfunction and invoke it.  I'd avoid using 'get' as the prefix for action methods, as VF views those as property getters. Assuming its named showDescription:

 

  

<apex:actionFunction action="{!showDescription}" name=showdesc" rerended="<some ids>"/>

 <apex:inputField value="{!newLine.Code_Combination__c}" onselect="showdesc()" />

 

 

2. Use an apex:actionsupport, this invokes the method directly from the component:

 

 <apex:inputField value="{!newLine.Code_Combination__c}">
<apex:actionSupport event="onselect" action="{!showDescription}" rerender="<some ids"/>
</apex:inputField> 
This was selected as the best answer
Meer SalmanMeer Salman

was just waiting for your reply :)

 

 

Thanks a lot.

 

Regards,

Meer Salman