Sunday 21 February 2016

List Example With Product Line

public  class ListExample {
     public List<String> names {set;get;}
     public List<Account> accs {set;get;}
     public List<ProdWrap> products {set;get;}
     public List<ProdWrap> selected {set;get;}
     public ListExample(){
          names=new List<String>{'sam','Ram','Kiran'};
          accs=new List<Account>();
          products=new List<ProdWrap>();
          Account a1=new Account(Name='Wipro',Industry='Technology');
          Account a2=new Account(Name='Satyam',Industry='Energy');
          accs.add(a1);
          accs.add(a2);
          for(Integer i=0;i<4;i++){
              ProdWrap pw=new Prodwrap();
              products.add(pw);
          }
     }
     public void getValues(){
          selected=new List<ProdWrap>();
          for(ProdWrap ps:products){
              if(ps.flag==true){
                   selected.add(ps);
              }
          }
     }
     public class prodWrap{
          public String name {set;get;}
          public Decimal price {set;get;}
          public Decimal quant {set;get;}
          public Boolean flag {Set;get;}
          public ProdWrap(){
              flag=false;
          }
     }
}

Visualforce Page:
<apex:page  controller="ListExample">
     <apex:form>
          <apex:pageBlock title="List of Name " >
              <apex:pageBlockTable value="{!names}" var="a">
                   <apex:column value="{!a}" />
              </apex:pageBlockTable>
          </apex:pageBlock>
          <apex:pageBlock title="List of Accounts " >
              <apex:pageBlockTable value="{!accs}" var="a">
                   <apex:column value="{!a.Name}" />
                   <apex:column value="{!a.industry}" />
              </apex:pageBlockTable>
          </apex:pageBlock>
          <apex:pageBlock title="List of ProdWrap " >
              <apex:pageBlockTable value="{!products}" var="a">
                   <apex:column>
                        <apex:facet name="header">
                             <apex:inputCheckBox />
                        </apex:facet>
                        <apex:inputCheckBox  value="{!a.flag}"/>
                   </apex:column>
                   <apex:column headerValue="Product Name" >
                        <apex:inputText value="{!a.name}" />
                   </apex:column>
                   <apex:column headerValue="Quantity" >
                        <apex:inputText value="{!a.quant}" />
                   </apex:column>
                   <apex:column headerValue="Price" >
                        <apex:inputText value="{!a.price}" />
                   </apex:column>
              </apex:pageBlockTable>
              <apex:pageBlockButtons location="Bottom">
                   <apex:commandButton value="Submit" action="{!getValues}"  />
              </apex:pageBlockButtons>
          </apex:pageBlock>
         <apex:pageBlock title="List of ProdWrap "  rendered="{! !ISNULL(selected)}"  id="one" >
              <apex:pageBlockTable value="{!selected}" var="a">
                   <apex:column headerValue="Product Name" >
                        <apex:outputText value="{!a.name}" />
                   </apex:column>
                   <apex:column headerValue="Quantity" >
                        <apex:outputText value="{!a.quant}" />
                   </apex:column>
                   <apex:column headerValue="Price" >
                        <apex:outputText value="{!a.price}" />
                   </apex:column>
              </apex:pageBlockTable>
          </apex:pageBlock>
     </apex:form>
</apex:page>


No comments:

Post a Comment