5

I am defining a apex property public String[] values{get; set;} and calling it in VF page

`<apex:selectCheckboxes value="{!values}">`
            <apex:selectOptions value="{!items}"/>
        </apex:selectCheckboxes>

But when I submit the selected values using <apex:commandButton value="Test" action="{!submit}" rerender="out" status="status"/> submit function in apex code is not called. Interestingly the same stuff works when I define individual get and set method for ‘values’ … something like …

public String[] getValues() {
        return values;
    }

    public void setValues(String[] values) {
        this.values = values;
    }

Also another interesting thing what I noticed was it works fine with <apex:selectList/>

<apex:selectList value="{!values}" multiSelect="true" size="4">
      <apex:selectOptions value="{!items}"/>

Is this a bug anybody aware off ?

If needed I shall post the entire code.

  • I faced the same problem – javanoob May 15 '15 at 22:38
  • 1
    I think this is a bug of a sort - looking through some of my code, I see I've used individual getters and setters as well. I can't remember having the issue, but I probably did. – Caspar Harmer May 16 '15 at 1:42
  • why aren't you declaring it as a list of Boolean: public Boolean[] values {get; set;} ? and I assume those reverse quotes in your code block are a copy-paste error – cropredy May 16 '15 at 17:50
  • Did you try as suggested by @crop1645? – the_phantom Jun 13 '15 at 14:37
0

You can use this getter setters in two ways one is your correct but the other one you have to intialize it in the constructor

public class xyz {

  public String[] values{get; set;}
  // my method of using getters and setters
  public WrapperAccountController(){
   values=new String[]{'a','b'};

  }
  //Your Method
  public String[] getValues() {
        return values;
    }

    public void setValues(String[] values) {
        this.values = values;
    }
}

I hope this helps you solve the problem.

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.