• GeneEA
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Hello.

I have a VF page that displays 2 lists via the apex:repeat method. The items on the list can be deleted when clicking on a link that invoked the following method:

public PageReference deleteAdditionalCategory(){
        PageReference p = null;
        try{
            String categoryId = ApexPages.currentPage().getParameters().get('CategoryID');
            if(vendorAccountMembershipDetails != null && categoryId != null){
                Category__c c = mapCatList.get(categoryId);
                if(c != null){
                  mapCatList.remove(c.Id);
              	  
              	  Integer lSize = 0;
                  if(addCat != null && addCat.size() > 0){
                  	lSize = addCat.size();
                	for(Integer i=0; i < lSize; i++){
	                	if(addCat[i].Id == c.Id)
	                		addCat.remove(i);
	                		//catList.remove((i+1));
                	}
                  }
                  if(catList != null && catList.size() > 0){
                  	lSize = catList.size();
                	for(Integer j=1; j < lSize; j++){
	                	if(catList[j].Id == c.Id)
	                		catList.remove(j);
                	}
                  }
                  delete c;
                }
            }
            goAction();
        }catch(Exception e){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Exception - ' +e.getMessage());
            ApexPages.addMessage(msg);
            system.debug('------Exception caught----'+e);
            if(vendorAccountMembershipDetails != null){
                //sendExceptionEmail(vendorAccountMembershipDetails, e);
            }    
        }
        
        return p;
    }

 

 The problem is, the first list (addCat) gets updated but the second one (catList) doesn't. The difference between the two lists is that addCat contains all additional categories associated with a membership order form while catList contains all additional categories plus the primary category. This way, catList will always be larger by 1.

The error I am getting is: Exception - List index out of bounds: followed by the index number of the item I am trying to remove from the list. Here's the odd part... The method will correctly remove items from the lists if I am removing the item at the end of the list. If I try deleting something in the middle, that's when the exception happens.

  • April 23, 2012
  • Like
  • 0

Hello.

I need help in getting a VF page controller to access inputField values that are created inside an apex:repeat. I know that when converted to HTML, each of those inputFields has an ID that auto-increments, but I don't know how to get the controller to access those values.

Here is the code snippet from the VF page in question that contains the apex:repeat generated inputFields:

 

<tr>
<td colspan="3"><apex:actionStatus id="msgStatus2"layout="block">
<apex:facet name="start">
<apex:image url="{!URLFOR($Resource.ChatStyles, 'images/indicator_2.gif')}" />
</apex:facet>
<apex:facet name="stop">
<apex:outputPanel id="additionalCategoryView1" layout="block">
																		<table width="741" border="0">
<tr>
<td colspan="2">
<table border="0" width="741">
<apex:repeat value="{!categoryList}" rendered="{!categoryList.size>0}" var="additionalCategory" id="additionalCategoryId">																						<tr>																						<td align="right" width="156" style="padding: 0px 5px 0px 0px;" class="FormDescriptions">Additional Category<font style="font-size: 11px;" color="red">*</font></td>																				<td colspan="2" width="200" style="padding: 0px 5px 0px 0px;"><apex:inputField id="categoryname" value="{!additionalCategory.Category_Name__c}" required="false" styleClass="formbox_cream">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" immediate="true" reRender="selectedPackageSummary" status="counterStatus" />
																							</apex:inputField> <apex:outputPanel rendered="{!step2Flag && additionalCategory.Category_Name__c==null}">
																								<div class="errorMsg"><strong>Error:</strong>Value Cannot be null</div>
<script>document.getElementById('{!$Component.categoryname}').style.borderColor = '#ff0000';</script>
																							</apex:outputPanel></td>
																							<td align="right" width="115" class="bodySmall" style="padding: 0px 0px 0px 10px;">Primary Zip Code<font style="font-size: 11px;" color="red">*</font><br /> (50 mile radius)</td>
																							<td width="60" style="padding: 0px 5px 2px 0px;">
																							<apex:inputField id="addPromaryZIP" style="width:50px" value="{!additionalCategory.Primary_ZIP_Code__c}" required="false" styleClass="formbox_cream" onblur="return validateZIP(this)">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary status="counterStatus" />
																							</apex:inputField> <apex:outputPanel rendered="{!step2Flag && additionalCategory.Primary_ZIP_Code__c==null}">
																								<div class="errorMsg"><strong>Error:</strong> Value Cannot be null</div>
																								<script>document.getElementById('{!$Component.addPromaryZIP}').style.borderColor = '#ff0000'; </script>
																							</apex:outputPanel></td>
																							<td align="right" width="123" class="bodySmall" style="padding: 0px 5px 0px 8px;"> Additional Zip Code<br /> (50 mile radius)</td>
																							<td width="33" style="padding: 0px 5px 0px 0px;">
																							<apex:inputField style="width:50px" value="{!additionalCategory.Additional_ZIP_Code__c}" required="false"  styleClass="formbox_cream" onblur="return validateZIP(this)">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary" status="counterStatus" />
																							</apex:inputField></td>
																							<td align="right" width="50" style="padding: 0px 5px 0px 5px;" class="bodySmall"><apex:commandLink immediate="true" id="deleteCat" value="Remove" action="{!deleteAdditionalCategory}" reRender="additionalCategoryView1,selectedPackageSummary status="msgStatus2">
																								<apex:param name="CategoryID" value="{!additionalCategory.Id}" />
																							</apex:commandLink></td>
																						</tr>
																						<tr>
																							<td align="right" style="padding: 0px 5px 0px 0px;" class="FormDescriptions"> <p>&nbsp;</p>
																							</td>
																							<td colspan="2" class="bodySmall" align="right"> <strong>Select a Package for this category:</strong></td>
																							<td colspan="3"><apex:selectRadio value="{!additionalCategory.Select_a_Package__c}" required="false" styleClass="formbox_cream" onclick="document.getElementById('{!$Component.primaryCatPackage}').focus();">
																								<apex:selectOption itemValue="15% Package" itemLabel="15% Option ($99)" />
																								<apex:selectOption itemValue="20% Package" itemLabel="20% Option ($0)" />
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary,initialSetupFees,memberAgreement" status="counterStatus" />
																							</apex:selectRadio></td>
																						</tr>
																					</apex:repeat>
																				</table>
																				</td>
																			</tr>
																		</table>
																	</apex:outputPanel>
																</apex:facet>
															</apex:actionStatus></td>
														</tr>

 
Any help would be greatly appreciated. 

  • April 11, 2012
  • Like
  • 0

Hello.

I have a VF page that displays 2 lists via the apex:repeat method. The items on the list can be deleted when clicking on a link that invoked the following method:

public PageReference deleteAdditionalCategory(){
        PageReference p = null;
        try{
            String categoryId = ApexPages.currentPage().getParameters().get('CategoryID');
            if(vendorAccountMembershipDetails != null && categoryId != null){
                Category__c c = mapCatList.get(categoryId);
                if(c != null){
                  mapCatList.remove(c.Id);
              	  
              	  Integer lSize = 0;
                  if(addCat != null && addCat.size() > 0){
                  	lSize = addCat.size();
                	for(Integer i=0; i < lSize; i++){
	                	if(addCat[i].Id == c.Id)
	                		addCat.remove(i);
	                		//catList.remove((i+1));
                	}
                  }
                  if(catList != null && catList.size() > 0){
                  	lSize = catList.size();
                	for(Integer j=1; j < lSize; j++){
	                	if(catList[j].Id == c.Id)
	                		catList.remove(j);
                	}
                  }
                  delete c;
                }
            }
            goAction();
        }catch(Exception e){
            ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR,'Exception - ' +e.getMessage());
            ApexPages.addMessage(msg);
            system.debug('------Exception caught----'+e);
            if(vendorAccountMembershipDetails != null){
                //sendExceptionEmail(vendorAccountMembershipDetails, e);
            }    
        }
        
        return p;
    }

 

 The problem is, the first list (addCat) gets updated but the second one (catList) doesn't. The difference between the two lists is that addCat contains all additional categories associated with a membership order form while catList contains all additional categories plus the primary category. This way, catList will always be larger by 1.

The error I am getting is: Exception - List index out of bounds: followed by the index number of the item I am trying to remove from the list. Here's the odd part... The method will correctly remove items from the lists if I am removing the item at the end of the list. If I try deleting something in the middle, that's when the exception happens.

  • April 23, 2012
  • Like
  • 0

Hello.

I need help in getting a VF page controller to access inputField values that are created inside an apex:repeat. I know that when converted to HTML, each of those inputFields has an ID that auto-increments, but I don't know how to get the controller to access those values.

Here is the code snippet from the VF page in question that contains the apex:repeat generated inputFields:

 

<tr>
<td colspan="3"><apex:actionStatus id="msgStatus2"layout="block">
<apex:facet name="start">
<apex:image url="{!URLFOR($Resource.ChatStyles, 'images/indicator_2.gif')}" />
</apex:facet>
<apex:facet name="stop">
<apex:outputPanel id="additionalCategoryView1" layout="block">
																		<table width="741" border="0">
<tr>
<td colspan="2">
<table border="0" width="741">
<apex:repeat value="{!categoryList}" rendered="{!categoryList.size>0}" var="additionalCategory" id="additionalCategoryId">																						<tr>																						<td align="right" width="156" style="padding: 0px 5px 0px 0px;" class="FormDescriptions">Additional Category<font style="font-size: 11px;" color="red">*</font></td>																				<td colspan="2" width="200" style="padding: 0px 5px 0px 0px;"><apex:inputField id="categoryname" value="{!additionalCategory.Category_Name__c}" required="false" styleClass="formbox_cream">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" immediate="true" reRender="selectedPackageSummary" status="counterStatus" />
																							</apex:inputField> <apex:outputPanel rendered="{!step2Flag && additionalCategory.Category_Name__c==null}">
																								<div class="errorMsg"><strong>Error:</strong>Value Cannot be null</div>
<script>document.getElementById('{!$Component.categoryname}').style.borderColor = '#ff0000';</script>
																							</apex:outputPanel></td>
																							<td align="right" width="115" class="bodySmall" style="padding: 0px 0px 0px 10px;">Primary Zip Code<font style="font-size: 11px;" color="red">*</font><br /> (50 mile radius)</td>
																							<td width="60" style="padding: 0px 5px 2px 0px;">
																							<apex:inputField id="addPromaryZIP" style="width:50px" value="{!additionalCategory.Primary_ZIP_Code__c}" required="false" styleClass="formbox_cream" onblur="return validateZIP(this)">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary status="counterStatus" />
																							</apex:inputField> <apex:outputPanel rendered="{!step2Flag && additionalCategory.Primary_ZIP_Code__c==null}">
																								<div class="errorMsg"><strong>Error:</strong> Value Cannot be null</div>
																								<script>document.getElementById('{!$Component.addPromaryZIP}').style.borderColor = '#ff0000'; </script>
																							</apex:outputPanel></td>
																							<td align="right" width="123" class="bodySmall" style="padding: 0px 5px 0px 8px;"> Additional Zip Code<br /> (50 mile radius)</td>
																							<td width="33" style="padding: 0px 5px 0px 0px;">
																							<apex:inputField style="width:50px" value="{!additionalCategory.Additional_ZIP_Code__c}" required="false"  styleClass="formbox_cream" onblur="return validateZIP(this)">
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary" status="counterStatus" />
																							</apex:inputField></td>
																							<td align="right" width="50" style="padding: 0px 5px 0px 5px;" class="bodySmall"><apex:commandLink immediate="true" id="deleteCat" value="Remove" action="{!deleteAdditionalCategory}" reRender="additionalCategoryView1,selectedPackageSummary status="msgStatus2">
																								<apex:param name="CategoryID" value="{!additionalCategory.Id}" />
																							</apex:commandLink></td>
																						</tr>
																						<tr>
																							<td align="right" style="padding: 0px 5px 0px 0px;" class="FormDescriptions"> <p>&nbsp;</p>
																							</td>
																							<td colspan="2" class="bodySmall" align="right"> <strong>Select a Package for this category:</strong></td>
																							<td colspan="3"><apex:selectRadio value="{!additionalCategory.Select_a_Package__c}" required="false" styleClass="formbox_cream" onclick="document.getElementById('{!$Component.primaryCatPackage}').focus();">
																								<apex:selectOption itemValue="15% Package" itemLabel="15% Option ($99)" />
																								<apex:selectOption itemValue="20% Package" itemLabel="20% Option ($0)" />
																								<apex:actionSupport event="onchange" action="{!packageSummary}" reRender="selectedPackageSummary,initialSetupFees,memberAgreement" status="counterStatus" />
																							</apex:selectRadio></td>
																						</tr>
																					</apex:repeat>
																				</table>
																				</td>
																			</tr>
																		</table>
																	</apex:outputPanel>
																</apex:facet>
															</apex:actionStatus></td>
														</tr>

 
Any help would be greatly appreciated. 

  • April 11, 2012
  • Like
  • 0