You need to sign in to do that
Don't have an account?
ApexPages.currentPage().getParameters() and multiple select fields
Hi there.
ApexPages.currentPage().getParameters() returns a Map<String, String>. But I have an HTML select field on my page which accepts multiple values:
<select size="7" name="a0780000004jDTQAA2" multiple="true"> <option value="a">a</option> <option value="b">b</option> <option value="c">c</option> </select>
Note that this is really plain old HTML in my VF page, not an <apex:inputField> tag. If I select two values in this field and submit the form, the browser will send both values. But in Apex code in my controller, I only have access to the first value (ie. it's Map<String, String>, not Map<String, List<String>>).How do I get access to what was really posted in the form submission?
Thanks.
Use components and bind to properties/methods in your controller, i.e.:
<apex:page controller="multiSelectCon"> <apex:form> <apex:selectList value="{!values}" multiselect="true"> <apex:selectOption itemLabel="a" itemValue="a"/> <apex:selectOption itemLabel="b" itemValue="b"/> <apex:selectOption itemLabel="c" itemValue="c"/> </apex:selectList> <apex:commandButton value="Submit" rerender="out"/> <apex:panelGrid columns="2" id="out" border="1"> Selected:<apex:dataList value="{!values}" var="val">{!val}</apex:dataList> </apex:panelGrid> </apex:form> </apex:page>
public class multiSelectCon { public String[] values { get; set; } public multiSelectCon() { values = new String[]{}; } }
Not an option, are you sure?
I'll spot you this one, next requirement that requires more work is on you ;-)
<apex:page controller="multiSelectCon"> <apex:form > <apex:repeat value="{!inputs}" var="input"> <apex:selectList value="{!input.values}" multiselect="true"> <apex:selectOption itemLabel="a" itemValue="a"/> <apex:selectOption itemLabel="b" itemValue="b"/> <apex:selectOption itemLabel="c" itemValue="c"/> </apex:selectList> </apex:repeat> <apex:commandButton value="Submit" rerender="out"/> <apex:repeat value="{!inputs}" var="input"> <apex:panelGrid columns="2" id="out" border="1"> Selected:<apex:dataList value="{!input.values}" var="val">{!val}</apex:dataList> </apex:panelGrid> </apex:repeat> </apex:form> </apex:page>
public class multiSelectCon { public multiselectinput[] inputs { get; set; } public multiSelectCon() { inputs = new multiselectinput[]{}; for(Integer i=0;i<5;i++) { inputs.add(new multiselectinput()); } } public class multiselectinput { public String[] values { get; set; } public multiselectinput() { values = new String[]{}; } } }
We have an identical issue to the original poster, whereby we want to be able to access parameters in the form POST that have come from a multiple select field.
As is known, values from a multiple select field will come through as ...Weather=Sunny&Weather=Windy
We can not (and do not want to) use an apex:form for the particular page we are dealing with. The browser sends the form POST data through correctly to the controller, however, it appears that the APEX getParameters() method in the controller will only return the first parameter, due to it returning a type of Map<string,string>.
Is this the case? If so, that is unacceptable behaviour, as it is breaking a fundamental element of HTTP POST architecture.
Is there any way to get the full list of form POST parameters from within an APEX controller?