2

I'm trying to do a simple selectList, and pass the value to controller when I click a button. Sounds simple (and it is), but I can't get this to work and I dont now why.

VF Page

<td>
      <apex:form >
          <apex:selectList value="{!state}" multiselect="false" size="1">
              <apex:selectOptions value="{!StateFilter}"/>
          </apex:selectList>
      </apex:form>
  </td>
  <p/>
  <td>
      <apex:form >
          <apex:commandButton value="Filtrar" action="{!MapFilter}"/>
      </apex:form>
  </td>

Controller

public String state {get;set;}

public String getState() {
            return state;
        }

    public void setState(String state) {
            this.state = state;
        }

    public PageReference MapFilter() {
        system.debug('----------------------->'+state);
        return null;
    }

I'm not sure I if I need the get/set methods, they are here because I dont now I to try more. The picklist shows fine on vfpage (that means that the values are passed right from controller to page I guess), but I cant get the page select list on controller.

In the Debug output i get null.

3

Remove getState() and setState() methods, because you use auto property

public String state {get;set;}

public PageReference MapFilter() {
    system.debug('----------------------->'+state);
    return null;
}

And wrap table in form tag

<apex:form >
    <td>
        <apex:selectList value="{!state}" multiselect="false" size="1">
            <apex:selectOptions value="{!StateFilter}"/>
        </apex:selectList>
    </td>
    <p/>
    <td>
        <apex:commandButton value="Filtrar" action="{!MapFilter}"/>
    </td>
</apex:form>
  • Removed, get the same null value on debug. – danielpm May 29 '15 at 9:20
  • 1
    Remove form tag and try again – Gres May 29 '15 at 9:21
  • Removed form tag and it works! God, how could I spent so much time trying to fix this, and the resolution is so simple. Much appreciated @Gres, thank you so much! – danielpm May 29 '15 at 9:24
  • 1
    @Gres Do you know where apex:form must be placed compared to apex:selectList? Is there any specific rules? – MuiBienCarlota Sep 22 '16 at 16:46
  • if i remove form it will selectlist cannot be without form. – unidha Dec 21 '16 at 8:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.