Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

List Example:

public class ProdWrapper {


public String prodName {set;get;}
public String prodCode {set;get;}
public Integer quantity {set;get;}
public Decimal price {set;get;}
public Boolean flag {set;get;}
public Decimal total {set;get;}
}

public class ProdLineItems {


public List<ProdWrapper> items {set;get;}
public List<ProdWrapper> selected {set;get;}
public Integer rowNo {set;get;}
public ProdLineItems(){
items=new List<ProdWrapper>();
addRows();
}
public void addRows(){
for(Integer i=1;i<=3;i++){
ProdWrapper pw=new ProdWrapper();
items.add(pw);
}
}
public void addEle(){
ProdWrapper pw=items.get(rowNo);
items.add(rowNo+1,pw);
}
public void removeEle(){
items.remove(rowNo);
}
public void submit(){
selected=new List<ProdWrapper>();
for(ProdWrapper ps:items){
if(ps.flag==true){
selected.add(ps);
}
}
}
}

<apex:page controller="ProdLineItems" id="page" sidebar="false" >


<script>
function show(rowId){
var rows=rowId.split(':');
document.getElementById('page:fm:hid').value=rows[4];
}
</script>
<apex:form id="fm">
<apex:inputHidden id="hid" value="{!rowNo}" />
<apex:pageBlock title="Products" id="pb">
<apex:pageBlockButtons>
<apex:commandButton value="Submit" action="{!submit}" />
<apex:commandButton value="AddMore" action="{!addRows}" />
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!items}" var="a" id="pbt">
<apex:column >
<apex:facet name="header"><apex:inputCheckBox /></apex:facet>
<apex:inputCheckBox value="{!a.flag}" />
</apex:column>
<apex:column headervalue="ProductName" >
<apex:inputText value="{!a.prodName}" />
</apex:column>
<apex:column headervalue="ProductCode">
<apex:inputText value="{!a.prodCode}" />
</apex:column>
<apex:column headervalue="Quanity" >
<apex:inputText value="{!a.quantity}" id="quant" />
</apex:column>
<apex:column headervalue="Price" >
<apex:inputText value="{!a.price}" id="price" />
</apex:column>
<apex:column headervalue="Total" >
<apex:inputText value="{!a.total}" id="total"/>
</apex:column>
<apex:column headervalue="Action">
<apex:commandButton value="Add" id="b1"
onclick="show(this.id)" action="{!addEle}"/>
<apex:commandButton value="Del" id="b2"
onclick="show(this.id)" action="{!removeEle}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>

<apex:pageBlock title="Products" id="pb1" rendered="{! !ISNULL(selected)}">


<apex:pageBlockTable value="{!selected}" var="a" id="pbt">
<apex:column >
<apex:facet name="header"><apex:inputCheckBox /></apex:facet>
<apex:inputCheckBox value="{!a.flag}" />
</apex:column>
<apex:column headervalue="ProductName" >
<apex:inputText value="{!a.prodName}" />
</apex:column>
<apex:column headervalue="ProductCode">
<apex:inputText value="{!a.prodCode}" />
</apex:column>
<apex:column headervalue="Quanity" >
<apex:inputText value="{!a.quantity}" id="quant" />
</apex:column>
<apex:column headervalue="Price" >
<apex:inputText value="{!a.price}" id="price" />
</apex:column>
<apex:column headervalue="Total" >
<apex:inputText value="{!a.total}" id="total"/>
</apex:column>

</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

You might also like