You need to sign in to do that
Don't have an account?
Allada Yeshwanth
Problem in creating a wrapper class :
the records which are going into productswrapped are not being displayed in vf page
vf page: my wrapper demo
<apex:page controller="Ctrl_myWrapper">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="Search" action="{!searchProduct}" reRender="Product-table" />
</apex:pageBlockButtons>
<apex:pageBlockSection id="Product-table" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name" />
<apex:inputText value="{!Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockTable value="{!Like_Products}" var="pr" rendered="{!Like_Products.size>0}">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputLink value="/{!pr.id}">{!pr.Product_Name__c}</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header">Quantity Remaining</apex:facet>
<apex:outputField value="{!pr.Quantity_Remaining__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Unit Price</apex:facet>
<apex:outputField value="{!pr.SellingPricePerUnit__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageblockSection title="Products" columns="1">
<apex:pageBlockTable value="{!ProductsWrapped}" var="prWrap" title="Products">
<apex:column >
<apex:inputCheckbox value="{!prWrap.selected}" />
</apex:column>
<apex:column >
<apex:facet name="header">id</apex:facet>
<apex:outputField value="{!prWrap.pinv.id}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller : Ctrl_myWrapper
public with sharing class Ctrl_myWrapper{
public list<ProductInvoiceWrapper> ProductsWrapped {get ; set; }
public List<Product_Invoice__c> Like_Products { get; set; }
public String Name { get; set; }
public Ctrl_myWrapper()
{
ProductsWrapped = new List<ProductInvoiceWrapper>();
Like_Products = new List<Product_Invoice__c>();
}
public PageReference searchProduct()
{
String likeName = '%'+Name+'%';
Like_Products = [Select Id,Name,Product_Name__c,Quantity_Remaining__c,SellingPricePerUnit__c From Product_Invoice__c where Product_Name__c Like :likeName];
ProductsWrapped.clear();
for(Product_Invoice__c p : Like_Products )
{
ProductsWrapped.add(new ProductInvoiceWrapper(p));
}
return null;
}
public class ProductInvoiceWrapper{
public Product_Invoice__c pinv {get; set;}
public Boolean selected {get; set;}
public Integer Quantity {get; set;}
public ProductInvoiceWrapper(Product_Invoice__c a)
{
this.pinv = a;
selected = false;
Quantity = 0;
}
}
}
vf page: my wrapper demo
<apex:page controller="Ctrl_myWrapper">
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton value="Search" action="{!searchProduct}" reRender="Product-table" />
</apex:pageBlockButtons>
<apex:pageBlockSection id="Product-table" columns="1">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Name" />
<apex:inputText value="{!Name}" />
</apex:pageBlockSectionItem>
<apex:pageBlockTable value="{!Like_Products}" var="pr" rendered="{!Like_Products.size>0}">
<apex:column >
<apex:facet name="header">Name</apex:facet>
<apex:outputLink value="/{!pr.id}">{!pr.Product_Name__c}</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header">Quantity Remaining</apex:facet>
<apex:outputField value="{!pr.Quantity_Remaining__c}"/>
</apex:column>
<apex:column >
<apex:facet name="header">Unit Price</apex:facet>
<apex:outputField value="{!pr.SellingPricePerUnit__c}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageblockSection title="Products" columns="1">
<apex:pageBlockTable value="{!ProductsWrapped}" var="prWrap" title="Products">
<apex:column >
<apex:inputCheckbox value="{!prWrap.selected}" />
</apex:column>
<apex:column >
<apex:facet name="header">id</apex:facet>
<apex:outputField value="{!prWrap.pinv.id}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller : Ctrl_myWrapper
public with sharing class Ctrl_myWrapper{
public list<ProductInvoiceWrapper> ProductsWrapped {get ; set; }
public List<Product_Invoice__c> Like_Products { get; set; }
public String Name { get; set; }
public Ctrl_myWrapper()
{
ProductsWrapped = new List<ProductInvoiceWrapper>();
Like_Products = new List<Product_Invoice__c>();
}
public PageReference searchProduct()
{
String likeName = '%'+Name+'%';
Like_Products = [Select Id,Name,Product_Name__c,Quantity_Remaining__c,SellingPricePerUnit__c From Product_Invoice__c where Product_Name__c Like :likeName];
ProductsWrapped.clear();
for(Product_Invoice__c p : Like_Products )
{
ProductsWrapped.add(new ProductInvoiceWrapper(p));
}
return null;
}
public class ProductInvoiceWrapper{
public Product_Invoice__c pinv {get; set;}
public Boolean selected {get; set;}
public Integer Quantity {get; set;}
public ProductInvoiceWrapper(Product_Invoice__c a)
{
this.pinv = a;
selected = false;
Quantity = 0;
}
}
}
Add an Id field to the second pageblockSection and add that id to the rerender of Search button, check below
<apex:pageBlockButtons location="top">
<apex:commandButton value="Search" action="{!searchProduct}" reRender="Product-table,tblProducts" />
</apex:pageBlockButtons>
--------------------------------------------------------
<apex:pageBlock >
<apex:pageblockSection title="Products" columns="1" id ="tblProducts">
<apex:pageBlockTable value="{!ProductsWrapped}" var="prWrap" title="Products">
<apex:column >
--------------------------------------------------------
regards
Sampath
All Answers
Check whether you are getting records by ProductsWrapped list in searchProduct method
Regards
Yeah, I am storing the records into productsWrapped using for loop.
Add an Id field to the second pageblockSection and add that id to the rerender of Search button, check below
<apex:pageBlockButtons location="top">
<apex:commandButton value="Search" action="{!searchProduct}" reRender="Product-table,tblProducts" />
</apex:pageBlockButtons>
--------------------------------------------------------
<apex:pageBlock >
<apex:pageblockSection title="Products" columns="1" id ="tblProducts">
<apex:pageBlockTable value="{!ProductsWrapped}" var="prWrap" title="Products">
<apex:column >
--------------------------------------------------------
regards
Sampath