function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
astroastro 

how to invoke a controller method from within a repeat tag

Hey Guys new to VF and having some problems,

 

here' what I want to do, and I currently cannot find any way of doing this:

 

I have a repeat tag that populates a few fields from a list.

each iteration displays the record's name and 2 2 pickList values (which I want to the user to be able to change via a selectList)

 

 

For each iteration I would like the selectList to display the current pickList value the record holds, instead of being in alphabetical order.

 

Ultimately I want the user to be able to update each of these records pickList fields based on the current value of the selectLists. 

 

Currently the selectLists simply hold all values in the pickList field and when the 'save' button is pushed, the selectList values aren't referenced and the pickList fields remain the same.

 

How can I make it so the selectList displays the records original pickList values first and then the rest of the pickList var's so that on save I can reference each records selectList value and update that record.

 

Also would I be able to make the ID for a pageBlocksection (which resides within thet repeat tag) based on a value retrieved in the repeat process?  this way I can grab the selectList values from each record dynamically no matter how many records I display.

 

I apologize for the length of my question and hope someone can help!

 

Page:

 

<apex:page standardController="Speaker_Bureau_Membership_gne__c" showheader="false" sidebar="false" extensions="em3_bureau_nomination_ctrlr"> <!-- <div class="ptBody secondaryPalette"><div class="content"><img src="/s.gif" alt="Speaker Bureau Membership" class="pageTitleIcon" title="Speaker Bureau Membership"><h1 class="pageType noSecondHeader">Bureau Nomination</h1><div class="blank">&nbsp;</div></div><div class="links"><a href="javascript:printWin('/a2x/x?fcf=00BQ0000000TXDw&amp;rpp_sticky=false')" class="configLinks" title="Printable View (New Window)">Printable View</a> | <a href="javascript:openPopupFocusEscapePounds('/help/doc/user_ed.jsp?loc=help&amp;target=co_view.htm&amp;section=CustomObjects', 'Help', 700, 600, 'width=700,height=600,resizable=yes,toolbar=yes,status=no,scrollbars=yes,menubar=yes,directories=no,location=no,dependant=no', false, false);" title="Help for this Page (New Window)"><span class="helpLink">Help for this Page</span><img src="/s.gif" alt="Help" class="helpIcon" title="Help"></a></div></div><div class="ptBreadcrumb"></div> --> <apex:pageBlock id="theIDs" > <apex:pageBlockButtons > <apex:form > <!-- <apex:commandButton action="{!nominate}" value="Nominate Speakers"/> <apex:commandButton action="{!cancel}" value="Cancel" onClick="window.top.close();"/> <apex:actionFunction name="Nominate" action="{!nominate}" id="out" status="myStatus" onComplete="window.close();"/> --> <apex:commandButton id="nominate" value="Nominate Speakers" action="{!nominate}" onComplete="parent.window.opener.location.reload(); window.close();" /> <apex:commandButton value="Cancel" onClick="window.close();"/> <apex:commandButton value="View IDs" action="{!setID}" reRender="status" /> </apex:form> </apex:pageBlockButtons> <apex:Repeat value="{!members}" var="m"> <apex:param name="mName" value="test" /> <apex:pageBlock > <apex:form > <apex:facet name="header"><b>{!m.name}</b></apex:facet> <apex:pageBlockSection title="{!m.name}" collapsible="false" columns="3"> <apex:outputField value="{!m.Bureau_Member_gne__c}" /> <apex:pageBlockSectionItem > <apex:outputLabel value="Spaker Bureau" for="speaker_bureau"/> <apex:selectList value="{!selected_option}" multiselect="false" size="1" id="speaker_bureau"> <apex:selectOptions value="{!Bureaus}"/> </apex:selectList> </apex:pageBlockSectionItem> <apex:inputField value="{!m.Speaker_Scope_gne__c}" /> </apex:pageBlockSection> </apex:form> </apex:pageBlock> </apex:Repeat> </apex:pageBlock> <apex:pageBlock id="status"> <apex:outputText value="{!ID}" /> </apex:pageBlock> </apex:page>

 

 Controller:

 

public class em3_bureau_nomination_ctrlr { private List<String> myList = new List<String>(); private List<SelectOption> options = new List<SelectOption>(); private List<Speaker_Bureau_Membership_gne__c> myMembers = new List<Speaker_Bureau_Membership_gne__c>(); private String selected_option; private List<Speaker_Bureau_gne__c> myBureaus = new List<SPeaker_Bureau_gne__c>(); private static List<Speaker_Bureau_Membership_gne__c> members = new List<Speaker_Bureau_Membership_gne__c>(); private Map<ID,Speaker_Bureau_Membership_gne__c> ID_to_members_map = new Map<ID,Speaker_Bureau_Membership_gne__c>(); private String IDs; public em3_bureau_nomination_ctrlr(ApexPages.StandardController controller){ reset(); myList = new Map<String,String>(ApexPages.currentPage().getParameters()).values(); setMembers(); setBureaus(); } public void reset(){ myList.clear(); options.clear(); myMembers.clear(); selected_option = null; myBureaus.clear(); members.clear(); ID_to_members_map.clear(); IDs = null; } public void setID(){ IDs +=System.CurrentPageReference().getParameters().get('mName')+','; } public string getID(){ return IDs; } public List<SelectOption> getBureaus(){ options = new List<SelectOption>(); for(Speaker_Bureau_gne__c sb : myBureaus ){ options.add(new SelectOption(sb.Name,sb.Name)); } return options; } public void setBureaus(){ myBureaus = [select ID, Name from Speaker_Bureau_gne__c]; } //For some reason the members variable in this method has a double of every member when it gets to this function. //so if members originally had 2 membership records in the list, it would have 4 in this method. No idea why. Fixed this by making //the members variable static - unclear as to why that helped but logic behind making it static was to have it keeps it's value and not //be refreshed upon instantiation of the controller public void nominate(){ List<Speaker_Bureau_Membership_gne__c> nominations = new List<Speaker_Bureau_Membership_gne__c>(); for(Speaker_Bureau_Membership_gne__c membership : members){ nominations.add(new Speaker_bureau_membership_gne__c( User__c = Membership.User__c, Speaker_Status_gne__c = 'Nominated', Speaker_Scope_gne__c = membership.Speaker_Scope_gne__c, Speaker_Bureau_ID_gne__c = membership.Speaker_Bureau_ID_gne__c, Nomination_Date_gne__c = System.now(), Nominated_By_gne__c = UserInfo.getUserID(), Bureau_Member_gne__c = membership.Bureau_Member_gne__c )); } try{ insert(nominations); }catch(DmlException e){ System.debug(e.getMessage()); } } public void setselected_option(String t){ } public String getselected_option(){ return null; } /*public pageReference cancel(){ //https://cs3.salesforce.com/a2x/o //PageReference pageRef = new PageReference('/a2x/o'); //pageRef.setRedirect(true); //return pageRef; }*/ public void setMembers(){ myMembers = [select ID,User__c, Name,Speaker_bureau_id_gne__c,Bureau_Member_gne__c,Speaker_scope_gne__c from Speaker_Bureau_Membership_gne__c]; createMap(myMembers); } public void createMap(List<Speaker_Bureau_Membership_gne__c> theMembers){ for(Speaker_Bureau_membership_gne__c current_member : theMembers){ if(!ID_to_members_map.keySet().contains(current_member.id)){ ID_to_members_map.put(current_member.id,current_member); } } } public List<Speaker_Bureau_Membership_gne__c> getMembers(){ for(String memberID : myList){ ID temp = memberID; members.add(ID_to_members_map.get(temp)); } return members; } public void setList(ID text){ if(text != null){ myList.add(text); } } public List<String> getList(){ return myList; } }

 

 

 

 

shippushippu

Yes I have a similar requirement in my project to invoke a controller method multiple times so that it retrieves different values into picklists.

 

My Visualforce page has

 

<apex:repeat var="val" value="{!userFilterPref}" >

<apex:outputText > Select {!val} </apex:outputText>

<apex:selectList value="{!selectedValue}" size="1" id="viewId" >

<apex:selectOptions value="{!picklistValues}" />

</apex:selectList>

</apex:repeat>

 

I want the getPicklistValues() method in my controller be called as many times as the size of collection 'userFilterPref'. But, it is not happening with above code. The picklistvalues remain same for all filters.

 

Can somebody please suggest a solution for this?