1

I have VF Component and component controller. I am trying to call action method incomponent controller from component and receiving unknown property error. Please see below,

Controller

public class ComponentNewController {

    public ComponentNewController()
    {

    }

    public CustomObj__c myRequest;

  public void setMyRequest (CustomObj__c s) {
    myRequest= s;        
  }

  public CustomObj__c getMyRequest() {
    return myRequest;
  }


    public void onClickAction()
    {
        if(myRequest.customfield__c)
        {
            myRequest.customfield__c = true;
        }
    }       

}

Component

<apex:component controller="ComponentNewController">

     <apex:attribute name="attr" description="Request object" type="CustomObj__c" assignTo="{!myRequest}"/> 


    <apex:outputPanel id="OuterPanel">
    <apex:pageBlockSection >

            <apex:pageBlockSectionItem >    
                <apex:outputLabel value="Escalate?"></apex:outputLabel>
                <apex:inputField value="{!attr.customfield__c}">                    
                      <actionSupport event="onchange" action="{!onClickAction}" rerender="OuterPanel" /> 
                </apex:inputField>                    
            </apex:pageBlockSectionItem>


            <apex:pageBlockSectionItem >
                    <apex:outputPanel >
                        <apex:outputLabel rendered="{!attr.customfield__c == true}" > Notes</apex:outputLabel>   
                    </apex:outputPanel>    
                   <apex:outputPanel >
                    <apex:inputField rendered="{!attr.customfield__c == true}" value="{!attr.Notes__c}" />    
                   </apex:outputPanel>                   
            </apex:pageBlockSectionItem>

    </apex:pageBlockSection>        
    </apex:outputPanel>
</apex:component>

When I try to save the file I receive error:

Unknown property: ComponentNewController.OnclickAction

If I comment below line - no error is shown

<actionSupport event="onchange" action="{!onClickAction}" rerender="OuterPanel" /> 

Can anyone explain why this error is shown ?

5
  • 2
    First thing to try is to change actionSupport to apex:actionSupport so Visualforce looks for the action attribute to reference a method not property.
    – Keith C
    Commented Jul 15, 2016 at 22:12
  • yes, my apex class has been saved successfully, do you see any issues with the class ?
    – apn
    Commented Jul 15, 2016 at 22:12
  • @KeithC Good catch and likely answer.
    – Adrian Larson
    Commented Jul 15, 2016 at 22:13
  • @KeithC - yes that fixed it. good catch. I am wondering how it allowed me to save the file without apex: ?
    – apn
    Commented Jul 15, 2016 at 22:15
  • 1
    You can add whatever HTML/XML you like into a Visualforce page as long as its well formed XML. But when {! ... } is used it is assumed to be a property i.e. a getter for the value is needed.
    – Keith C
    Commented Jul 15, 2016 at 22:17

1 Answer 1

1

Change actionSupport to apex:actionSupport so Visualforce looks for the action attribute to reference a method not a property.

You can add whatever HTML/XML you like into a Visualforce page as long as its well formed XML. But when {! ... } is used it is assumed to be a property i.e. a getter for the value is needed. Some attributes of apex:... tags instead expect the full name name of a (action) method that can optionally return a PageReference.

You must log in to answer this question.

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