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
EricVlachEricVlach 

Best Practice Suggestions? adding multiple child objects

I need suggestions from the pros - every time I start implementing a possible solution, I run into problems.

I have License object, with License Feature child object. (A software license, on which one or more license features can be added to increase the product capabilities.)

The license feature names come from a list in my controller. Here is what I would like my form to look like: (check to toggle date box)

License Name:
Feature NameExpiration Date
Feature A
Feature B
Feature C

Upon save, the License object would be created, as well as those features which are CHECKED. I can do this very easily if I code for each license feature independently. However, being the good programmer that I am, I am looking to write the code for the quickest implementation of future additional features. All I would do is add an item to a List of features, and the rest would auto-generate. Here is my latest attempt:

Page Snippet:
<apex:dataTable columns="2" value="{!AllLicenseFeatures}" var="feature">
  <apex:column>
    <apex:facet name="header">Available Features</apex:facet>
    <apex:inputCheckbox value="{!feature.name}" id="feature{!feature.name}" onChange="toggle('feature{!feature.name}Expiration')" />
  </apex:column>
  <apex:column>
    <apex:facet name="header">Expiration Date</apex:facet>
    <apex:InputField id="feature{!feature.name}Expiration" value="{!feature.Expiration_Date__c}" />
  </apex:column>
</apex:dataTable>
 

Current Problem: variable from the apex:dataTable tag is not usable in the apex:InputField or apex:InputCheckbox - it is looking for a controller class called feature, instead of using the variable.

Error messages returned by the compiler:

Error Error: id="feature{!feature.name}" core.apexpages.quickfix.QuickFixException: Unknown property 'newLicenseController.feature' Quick Fix Create Apex method 'newLicenseController.getFeature'

Error Error: Unknown property 'newLicenseController.feature'

How do I get those apex tags to refer to the dataTable variable feature, not a controller method feature!?

Controller Snippet:
List<String> feature_names = new List<String>{'Feature A','Feature B','Feature C'};
License_Feature__c[] features = new License_Feature__c[feature_names.size()];

public License_Feature__c getLicenseFeature(Integer i){
   if (features[i] == null) features[i] = new License_Feature__c();
   return features[i];
}
public License_Feature__c[] getAllLicenseFeatures() {
   integer i;
for ( i = 0; i < feature_names.size() ; i ++) { features[i] = getLicenseFeature(i); features[i].name = feature_names[i]; } return features; }
 


Message Edited by EricVlach on 09-11-2008 12:24 PM
Mark YoungMark Young
Hi Eric,
 
You can't use the var variable in an 'id' field.  Remove the id="feature{!feature.name}" and you should be fine.
 
If you want to refer to the components using ids for script / label purposes etc, name them id="featureCheck" and then you can still use {!$Component.featureCheck} within the scope of that row.
 
Mark