You need to sign in to do that
Don't have an account?
Luke@PCA
apex:selectManyCheckbox + apex:repeat?
Had a play with Visual Force as our app is all in clunky S-Controls at the moment and I'm very impressed with it so far, however have not found a way to get around the follow problem.
We want to have a way of selecting which countries apply using check boxes but the following code will not work:
<apex:selectManyCheckbox value="{!CountrySelection}" id="selectCheckbox" layout="pageDirection">
<apex:repeat value="{!Countries}" var="Country">
<apex:selectItem itemValue="{!Country}" itemLabel="{!Country}"/>
</apex:repeat>
</apex:selectManyCheckbox>
Custom Control Code:
public String[] getCountries() {
return new String[]{'GBR','USA','CAN','IRL'};
}
public List<String> getCountrySelection() {
List<String> countrylist = new List<String>();
countrylist.add('GBR');
countrylist.add('USA');
return countrylist;
}
Within the <apex:repeat> tags it is possible to output the country names with an <apex:outputText value="{!Country}/> and also possible to make an <apex:selectItem> using an API reference to a string outside of the repeat tags but cant seem to find a way to loop through countries and make an <apex:selectItem> for each.
Anyone else had problems with this?
We want to have a way of selecting which countries apply using check boxes but the following code will not work:
<apex:selectManyCheckbox value="{!CountrySelection}" id="selectCheckbox" layout="pageDirection">
<apex:repeat value="{!Countries}" var="Country">
<apex:selectItem itemValue="{!Country}" itemLabel="{!Country}"/>
</apex:repeat>
</apex:selectManyCheckbox>
Custom Control Code:
public String[] getCountries() {
return new String[]{'GBR','USA','CAN','IRL'};
}
public List<String> getCountrySelection() {
List<String> countrylist = new List<String>();
countrylist.add('GBR');
countrylist.add('USA');
return countrylist;
}
Within the <apex:repeat> tags it is possible to output the country names with an <apex:outputText value="{!Country}/> and also possible to make an <apex:selectItem> using an API reference to a string outside of the repeat tags but cant seem to find a way to loop through countries and make an <apex:selectItem> for each.
Anyone else had problems with this?
In response to your inquiry I have some good news and some bad news.
First the good news:
This is easier and more elegant than you were assuming. What you are missing is the use of "selectItems" (note the s) component with the appropriate type in apex. You can programatically build the value for selectItems with the selectOptions type in your controller. Here's the example:
Code:
Now for the bad news.
As you might gather if you try the above code out the binding of the array is not working properly in the summer release. We have fixed this in the Winter release and made some syntactic changes to make things more consistent and easier to understand. The following is the working version of this example from prerelease (no change to the controller, you would just use the page below with the controller from above):
Code: