+ Start a Discussion
Jyosi jyosiJyosi jyosi 

Wrapper class to assign the values from page

Hello Everyone,
I have requirment where i need to allow the user to enter the workorder and workorderlinitem.
The workorderlinitem can be entered the with multipe records.I need to have button that increment 5 lines when user click on that button

I got a problem while assiging the values that are entered in page at workorderlinitem
Here is the code for visualforce page and controller

<apex:page tabStyle="WorkOrder" controller="WorkOrdersLineitem">
  <!-- Header WorkOrder Information-->
  <apex:form >

  <apex:pageblock title="WorkOrderDetail" mode="edit" >
   <apex:pageblockButtons >
 
  <apex:commandButton value="Save" action="{!WorkOrderSave}" id="Workordersave"/>
  </apex:pageblockButtons>
  <apex:pageBlockSection title="WorkOrderHeaderInformation" columns="2">
 
  <apex:outputField value="{!workoderrecord.contactId}" />
  <apex:outputField value="{!workoderrecord.AccountId}" />
  <apex:inputfield value="{!workoderrecord.subject}"/><br></br>
  <apex:inputfield value="{!workoderrecord.StartDate}" />
  <apex:inputfield value="{!workoderrecord.EndDate}" />
  <apex:inputfield value="{!workoderrecord.Pricebook2id}"/>
  <apex:inputfield value="{!workoderrecord.RootWorkOrderId}"/>
  <apex:inputfield value="{!workoderrecord.Status}"/>
  <apex:inputfield value="{!workoderrecord.StatusCategory}"/>
  </apex:pageBlockSection>
 
  <!-- Work Order Line Items Information-->

 
   <apex:pageBlockTable value="{!WorkorderLineItemList}" var="c" id="wtable">
   <apex:column headerValue="Ident">
           <apex:outputText value="{!c.ident}"/>
         </apex:column>
         
            <apex:column headerValue="PricebookEntry">
            <apex:inputfield value="{!c.con.PricebookEntryId}"/>
         </apex:column>
         
         <apex:column headerValue="Quantity">
            <apex:inputfield value="{!c.con.Quantity}"/>
         </apex:column>
        
          <apex:column headerValue="Subject">
            <apex:inputfield value="{!c.con.Subject}"/>
         </apex:column>
         
         
          <apex:column headerValue="Status">
            <apex:inputfield value="{!c.con.Status}"/>
         </apex:column>
         
         <apex:column headerValue="StatusCategory">
            <apex:inputfield value="{!c.con.StatusCategory}"/>
         </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:pageblock>

  </apex:form>
</apex:page>

Apex Class

public class WorkOrdersLineitem{
public List<WorkorderLineItemValues> WorkorderLineItemList {get; set;}
public workorder workoderrecord{get;set;}
public static Integer addCount {get; set;}
public Integer nextIdent=1;
Id workoderrecordId ;
WorkOrder WorkOrderInsert  =new Workorder();
List<WorkOrder> LstWorkOrderInsert= new List<WorkOrder>();
public WorkOrdersUKApex()
{
    Id id = ApexPages.currentPage().getParameters().get('id');
    workoderrecord = (id == null) ? new workorder():
     [SELECT contactId, AccountId, subject,StartDate,EndDate,Pricebook2id,RootWorkOrderId,
      Status,StatusCategory FROM workorder WHERE Id = :id];

  WorkorderLineItemList=new List<WorkorderLineItemValues>();
  for (Integer idx=1; idx<5; idx++)
  {
      
       WorkorderLineItemList.add(new WorkorderLineItemValues( nextIdent++));
      
  }
}

 public WorkOrder getworkoderrecord  () {

        return workoderrecord ;
    }
public void WorkOrderSave()
 {
    system.debug('Testing in save');
    List<WorkOrderLineItem> LstWorkOrderLineItem=new List<WorkOrderLineItem>();
    system.debug('Value from Page ==== '+workoderrecord.subject);
    WorkOrderInsert.subject=workoderrecord.subject;
    WorkOrderInsert.StartDate=workoderrecord.StartDate;
    WorkOrderInsert.EndDate=workoderrecord.EndDate;
    WorkOrderInsert.Pricebook2id=workoderrecord.Pricebook2id;
    //WorkOrderInsert.RootWorkOrderId=workoderrecord.RootWorkOrderId;
    WorkOrderInsert.Status=workoderrecord.Status;
    LstWorkOrderInsert.add(WorkOrderInsert);
    if(LstWorkOrderInsert.size()>0)
     {
       try
       {
          insert LstWorkOrderInsert;
       }catch(DMLException e)
          {
           system.debug('Error while inserting the WorkOrder ===>' +e);
          }
     }
    for(WorkorderLineItemValues wrap : WorkorderLineItemList)
       {
        LstWorkOrderLineItem.add(wrap.con);
       }
    if(LstWorkOrderLineItem.size()>0)
    {
        try{
            insert LstWorkOrderLineItem;
        }catch(DMLException e)
        {
            system.debug('LineItemException==>> '+e);
        }
    }
  }

 public void addRows()
{
       for (Integer idx=1; idx<5; idx++)
          {
            WorkorderLineItemList.add(new WorkorderLineItemValues(nextIdent++));
          }
       
}  
public class WorkorderLineItemValues {
  public Integer ident {get;set;}
  public WorkorderLineItem con {get; set;}
  public WorkorderLineItemValues(Integer inIdent) {
     //con = c;
     ident=inIdent;
 }
   
  }  

}


Thanks for the help a lot

Regards,
Jyo