0

I am trying to make users picklist based on that some logic should happen.But action support is not calling method based on event="onchange".Please Find the below code

VisualForce code:

    <apex:page controller="test">
    <apex:form >
     <apex:outputpanel id="counter">
     <apex:outputText value="{!string1}"/>
     <apex:selectList size="1" value="{!selecteduser}" multiselect="false">    
          <apex:actionSupport event="Onchange" action="{!pageLoad}" reRender="t"/>    
          <apex:selectOptions value="{!UList}"/>         
          </apex:selectList>
         </apex:outputpanel>        
    </apex:form> 
    <apex:pageBlock >
    <apex:outputText value="{!string1}" id="t"></apex:outputText>

    </apex:pageBlock>

    </apex:page>

Apex class:

 public class test 
 {
     public string string1 {get;set;}
     public PageReference pageLoad() 
     {
         string1='Helloo Test';
         return null;
     }

    public List<User> UserTemp = new List<User>();
    public string selecteduser {get;set;}   

    public List<SelectOption> getUList()
    {           
        List <SelectOption> options =new list<SelectOption>();         
        for(User temp : [Select LastName,Id, FirstName, Email From User  ])
        {
            options.add(new SelectOption(temp.LastName, temp.LastName));
        }    
        return options; 
    }
}

1 Answer 1

3

Your actionSupport is not calling any defined controller method.

<apex:actionSupport event="Onchange" action="{!pageLoad}" reRender="t"/>  

The code above should fire when the onchange event occurs. This is probably happening, but you are calling a method called pageLoad which does not appear to exist on your controller.

Note some aspects of Visualforce are case sensitive - I doubt that the onchange event is, but it would be prudent to change your event="Onchange" to event="onchange" in case that is a source of error. There is not much written about case sensitivity in Visualforce that I can see, but here is some (unfortunately old) information.

If you want to refresh the page, you must make some sort of controller method to get called - I can see that you don't need to do much in this method, just get the page to reload, so you could definitely create a method like this:

public PageReference pageLoad(){
    return null;
}

This will refresh the page (or just the component you want to refresh in your rerender attribute.

The key is: Simplify your code to just this functionality. Verify it works. Then add back. Do this before coming back with questions, as it's important to verify that this functionality is working.

Good luck!

EDIT based on crop's comment.

2
  • I have updated my controller still its not working.
    – user5633
    Apr 28, 2015 at 9:15
  • n.b. @CaspNZ, re: case sensitivity; I can confirm that actionSupport event="onChange" does nothing; actionSupport event="onchange" works - that is, these event names are case sensitive
    – cropredy
    Jun 13, 2015 at 0:31

You must log in to answer this question.

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