[SalesForce] value don’t pass to controller

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.

Best Answer

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>