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
ana_sana_s 

actionSupport customcomponent

Hi Everyone,
How can I add actionSupport to a custom component?
Thanks in advance
ana
Ron HessRon Hess
what sort of action support were you looking for?

can you just add <apex : actionsupport to your component?
ana_sana_s
i have a component with an input text inside
i want to add actionsupport(when value in this input changes send the values in controller) to this field but from outside,when i m using the component.
thanks
ana_sana_s
and no,if i add actionsupport to the component i get errors.it doesn't recognize the actionsupport
Ron HessRon Hess
it works for me in this example, you may need <apex : form
Code:
<apex:component controller="exampleCon" >
  <!-- Begin Default Content REMOVE THIS -->
  <h1>Congratulations</h1>
  This is your new Component: clicks
  <!-- End Default Content REMOVE THIS -->
  
    <apex:form>
        <apex:outputpanel id="counter">
            <apex:outputText value="Click Me!: {!count}"/>
                <apex:actionSupport event="onclick" action="{!incrementCounter}" rerender="counter" status="counterStatus"/>
        </apex:outputpanel>
        <apex:actionStatus id="counterStatus" startText="(incrementing...)" stopText="(done)"/>
    </apex:form>


</apex:component>

 
Code:
public class exampleCon {
 Integer count = 0;
   
 public PageReference incrementCounter() {
  count++;
  return null;
 }
   
 public Integer getCount() {
  return count;
 }
}

 
Code:
<apex:page  >

  <c:clicks />
</apex:page>

 



JoshVHJoshVH
Would this work if your form was not actually in the component but in the page hosting the component like code below:

Code:
<apex:page>
   <apex:form>
      <c:mycomp/>
   </apex:form>
</apex:page>

To do this you would have to remove the form from the component code.  I tried this and my controller extension for the page is getting called instead of the controller for the component.  Is that because the form is in the page and not the component?  Thanks for the clarification.