+ Start a Discussion
acrozieracrozier 

assigning more than one value and variable to a data table

Is this possible?  I am trying to modify one of Bob Buzzard's creations to populate incentive lines. 

 

Extension:  (I am grabbing the job id of the page and searching for the Name.  I then need to inject this value into a column on the VisualForce page so that I can reference this in other places.

 

public class ManageListController
{
 public List<AIIncentiveWrapper> wrappers {get; set;}
 public static Integer toDelIdent {get; set;}
 public static Integer addCount {get; set;}
 public id jobid;
 public Job__c j;
 private Integer nextIdent=0;
  
 public ManageListController(ApexPages.StandardController controller)
 {
  jobid = apexpages.currentpage().getParameters().get('id');
  system.debug('################################## Id'+jobid);
  j = [SELECT Name FROM Job__c WHERE id=:jobid];
  wrappers=new List<AIIncentiveWrapper>();
  for (Integer idx=0; idx<1; idx++)
  {
   wrappers.add(new AIIncentiveWrapper(nextIdent++));
  }
 }
  
 public void delWrapper()
 {
  Integer toDelPos=-1;
  for (Integer idx=0; idx<wrappers.size(); idx++)
  {
   if (wrappers[idx].ident==toDelIdent)
   {
    toDelPos=idx;
   }
  }
   
  if (-1!=toDelPos)
  {
   wrappers.remove(toDelPos);
  }
 }
  
 public void addRows()
 {
  for (Integer idx=0; idx<addCount; idx++)
  {
   wrappers.add(new AIIncentiveWrapper(nextIdent++));
  }
 }
  
 public PageReference save()
 {
  List<AIIncentive__c> accs=new List<AIIncentive__c>();
  for (AIIncentiveWrapper wrap : wrappers)
  {
   accs.add(wrap.acc);
  }
   
  insert accs;
   
  return new PageReference('/' + Schema.getGlobalDescribe().get('AIIncentive__c').getDescribe().getKeyPrefix() + '/o');
 }
  
 public class AIIncentiveWrapper
 {
  public AIIncentive__c acc {get; private set;}
  public Integer ident {get; private set;}
   
  public AIIncentiveWrapper(Integer inIdent)
  {
   ident=inIdent;
   acc=new AIIncentive__c(Name='Incentives ' + ident);
  }
 }
}

 Visualforce page:  (How can I pull in my {!j} value to then spit out the Name field to each of these entries.

<apex:page standardController="Job__c" extensions="ManageListController" tabstyle="Job__c">
 <apex:form >
   <apex:pageBlock title="Incentives">
      <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
         <apex:column headerValue="Ident">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>
         <apex:column headerValue="QTY">
            <apex:inputField value="{!wrapper.acc.QTY__c}"/>
         </apex:column>
         <apex:column headerValue="Description">
            <apex:inputField value="{!wrapper.acc.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Honoraria">
            <apex:inputField value="{!wrapper.acc.Honoraria__c}"/>
         </apex:column>
         <apex:column headerValue="Action">
            <apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable">
               <apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>
            </apex:commandButton>
         </apex:column>
      </apex:pageBlockTable>
      <apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="1" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
         <apex:param name="addCount" value="5" assignTo="{!addCount}"/>
      </apex:commandButton>
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlock>
 </apex:form>
</apex:page>

 

bob_buzzardbob_buzzard

If you want the job name to appear in each row of the table, it should simply be a matter of adding that to the wrapper class:

 

public ManageListController(ApexPages.StandardController controller)
 {
  jobid = apexpages.currentpage().getParameters().get('id');
  system.debug('################################## Id'+jobid);
  j = [SELECT Name FROM Job__c WHERE id=:jobid];
  wrappers=new List<AIIncentiveWrapper>();
  for (Integer idx=0; idx<1; idx++)
  {
   AllIncentiveWrapper aiw=new AIIncentiveWrapper(nextIdent++);
   aiw.job=j;
   wrappers.add(aiw);
  }
 }

 and repeat this wherever a wrapper is created (or add it as an additional parameter on the constructor etc).

 

Change the wrapper class to:

 

 public class AIIncentiveWrapper
 {
  public AIIncentive__c acc {get; private set;}
  public Integer ident {get; private set;}
  public Job__c job {get; set;}
   
  public AIIncentiveWrapper(Integer inIdent)
  {
   ident=inIdent;
   acc=new AIIncentive__c(Name='Incentives ' + ident);
  }
 }

 and in the page:

 

 <apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
         <apex:column headerValue="Job"> <apex:outputText value="{!wrapper.job.Name}"/> </apex:column>
         <apex:column headerValue="Ident">
            <apex:outputText value="{!wrapper.ident}"/>
         </apex:column>

 

Is that what you are looking for, or have I misunderstood your post ?