Through JavaScript Remoting for Apex Controllers , we come to know that parameters can be passed from JavaScript to the Apex controller's method annotated with @RemoteAction. Let's see how to pass values from Javascript to an Apex Controller using apex:actionFunction and apex:param components.
Code Snippet
JavaScript
Visualforce Page
- <apex:actionFunction name="doSelectedMaterials" action="{!handleSelectedMaterials}" reRender="" status="statusAddRemove">
- <apex:param name="p1" value="" assignTo="{!contextMaterial}" />
- </apex:actionFunction>
- <apex:actionFunction name="doDeSelectedMaterials" action="{!handleDeselectedMaterials}" reRender="" status="statusAddRemove">
- <apex:param name="p2" value="" assignTo="{!contextMaterial}" />
- </apex:actionFunction>
- <apex:inputCheckbox id="idCheckbox" value="{!subs.IsSelected}" onclick="" onchange="doCheckboxChange(this, '{!subs.parentMaterial.ContractNumber}-{!subs.parentMaterial.MaterialNumber}')" />
Apex Controller
- public String contextMaterial { get; set; }
- public Set
setSelectedMaterials ; - //Handle selected Materials
- public void handleSelectedMaterials(){
- if(mapMaterial.containsKey(contextMaterial)){
- setSelectedMaterials.add(mapMaterial.get(contextMaterial));
- }
- }
- //Handle de-selected Materials
- public void handleDeselectedMaterials(){
- if(mapMaterial.containsKey(contextMaterial)){
- setSelectedMaterials.remove(mapMaterial.get(contextMaterial));
- }
- }
Points to be noted
The caveat here is: You must specify a reRender attribute in the tag.
Without this, the generated function does take any parameters, but as soon as you put it in place, it does - even if you just leave it empty.
Happy Apex Implementation...!
No comments:
Post a Comment
Thank you for visiting. Your comments are highly appreciated.