+ Start a Discussion
anup-prakashanup-prakash 

Wrapperclass issue setting value

Hi I am facing trouble to set values in wrapper class.. I don't know what is happening.. or what I am missing that its not setting the values.. Ny help!!

Best Answer chosen by Admin (Salesforce Developers) 
Avidev9Avidev9

Man you have added immediate=true to your addButton, Please remove that one,(it actually skips validation and calls to setter)

 

Something like

 

<apex:commandButton action="{!addToCart}" rerender="pbs3" value="Add to Cart" />

All Answers

Avidev9Avidev9
THe description was not helpful to debug your issue!

Anyways go through this blog if it helps http://blogforce9.blogspot.in/2013/06/wrapper-classes-wrap-it-up-with-wrapper.html
CoolSurenCoolSuren

Hi anup,

 

Refer the following links,

 

http://wiki.developerforce.com/page/Wrapper_Class

 

http://techman97.wordpress.com/tag/wrapper-class/

 

if u don't get anything from the above link, just post your code.  

anup-prakashanup-prakash
<apex:page controller="BillingPageController" title="Billing Console" sidebar="false" Showheader="true" tabstyle="Prod__c">
    <apex:form >
        <apex:pageblock title="Billing">
        	<apex:pageBlockButtons >
        		<apex:commandButton action="{!addToCart}" rerender="pbs3" value="Add to Cart" immediate="true" />
                <apex:commandButton action="{!viewCart}" value="View Cart" />
                <apex:commandButton action="{!checkout}" value="Checkout" />
                <apex:commandButton action="{!returnProductPage}" value="Add new Product/Lot" />
                <apex:commandButton action="{!cancel}" value="Cancel" />
        	</apex:pageBlockButtons>
            <apex:pageblockSection id="pbs1" columns="2" collapsible="False" title="Customer Detail" >
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="Customer Name" />  
                    <apex:selectList value="{!custSelected}" multiselect="False" size="1">
                    <apex:actionSupport action="{!methodSelectCust}" reRender="op1,pbs2" event="onchange" />
                        <apex:selectOptions value="{!custList}" />
                    </apex:selectList>
                </apex:pageblockSectionItem>
                <apex:pageblockSectionItem >
                    <apex:outputLabel value="Customer Detail" />
                    <apex:outputpanel Id="op1" rendered="True" >
                        <apex:outputField value="{!custDetail.Name__c}"/><BR/>
                        <apex:outputfield value="{!custDetail.Address__c}"/><BR/>
                        <apex:outputLabel value="TIN:" />&nbsp;&nbsp;
                        <apex:outputfield value="{!custDetail.TIN_Number__c}"/><BR/>
                        <apex:outputLabel value="Licence:" />&nbsp;&nbsp;
                        <apex:outputfield value="{!custDetail.Licence_Number__c}"/>
                    </apex:outputpanel>
                </apex:pageblockSectionItem>
            </apex:pageblockSection>

            <apex:pageBlockSection Id="pbs2" title="Products" columns="1" collapsible="False" rendered="true" >
                
                <apex:pageblockSectionItem >
                    <apex:pageblocktable value="{!productWrapperList}" var="pwl" >
                        <apex:column >
                            <apex:facet name="header">Select</apex:facet>
                            <apex:inputCheckbox value="{!pwl.chkValue}" />
                        </apex:column>
                        <apex:column value="{!pwl.product.Name}">
                            <apex:facet name="header">Product Name</apex:facet>
                        </apex:column>
                        <apex:column >
                            <apex:selectlist value="{!pwl.selectedBatchID}"  multiselect="false" size="1" >
                                <apex:selectOptions value="{!pwl.batchNumberList}" />
                            </apex:selectlist>
                            <apex:facet name="header">Batch Number----MRP----In Stock</apex:facet>
                        </apex:column>
                        <apex:column >
                            <apex:inputtext value="{!pwl.qty}" />
                            <apex:facet name="header">Quantity</apex:facet>
                        </apex:column>
                        <apex:column >
                            <apex:facet Name="header">Vacant</apex:facet>
                        </apex:column>
                    </apex:pageblocktable>
                </apex:pageblockSectionItem>
            </apex:pageBlockSection>

            <apex:pageblocksection id="pbs3" title="My cart" columns="1" rendered="true" collapsible="false">
                    {!ProductWrapperList}
               <apex:pageblocksectionItem >
                  <apex:pageBlockTable value="{!slectedProductWrapperListCart}" var="spwlc">
                  	 <apex:column value="{!spwlc.product.Name}" >
                    	 <apex:facet name="header">Product Name</apex:facet>
                     </apex:column>
                     <apex:column value="{!spwlc.qty}" >
                     	<apex:facet name="header">Quantity</apex:facet>
                      </apex:column>
                  </apex:pageBlockTable>
               </apex:pageblocksectionItem>
            </apex:pageblocksection>
        </apex:pageblock>
    </apex:form>
</apex:page>

 

public with sharing class BillingPageController {
	
	/* VARIABLE DECLARATION */
	
	public list<ProductWrapper> productWrapperList {get;set;}
	public list<ProductWrapper> slectedProductWrapperListCart {get;set;}
	public String custSelected {get; set;}
	public list<selectOption> custList {get; set;}
	public Customer__c custDetail {get; set;}
	
	/*DEFINING METHODS AND CONSTRUCTORS*/
	
	public BillingPageController(){
		custList =  new  list<selectOption>();
		productWrapperList = new List<productWrapper>();
		slectedProductWrapperListCart = new list<ProductWrapper>();
		for(Customer__c c: [Select ID, Name__c from Customer__c]){
			custList.add(new SelectOption( c.ID, c.Name__c));
		}
	}
	
	public void methodSelectCust(){
		custDetail = [select Name__c, Address__c, TIN_Number__c, Ph__c, Licence_Number__c, E_mail_Add__c from Customer__c where ID = :custSelected];
		for(Prod__c p:[Select Name, ManufacturerName__c, (Select Name, MRP__c, Unit_Price__c, Quantity__c From Prod_Details__r) From Prod__c ]){
			productWrapperList.add(new ProductWrapper(p));
		}
	}
	
    public void addToCart(){
 		for(ProductWrapper pw : productWrapperList){ 				/* Add the selected products to the selectedProductWrapperList list*/
    		if( (pw.qty > 0) && (pw.chkValue) && (pw.mapOfProdDetailIDToMrp.get(pw.selectedBatchID).Quantity__c > pw.qty) ){
    			pw.amount = ((pw.qty)*(pw.mapOfProdDetailIDToMrp.get(pw.selectedBatchID).MRP__c));
    			slectedProductWrapperListCart.add(pw);
    			for(selectOption so : pw.batchNumberList){		/* Updated the stock Quantity after the addition to cart*/
    				if(so.getValue() == pw.selectedBatchID){  
    					decimal updatedValue = pw.mapOfProdDetailIDToMrp.get(pw.selectedBatchID).Quantity__c-pw.qty;
    					decimal updatedMRP = pw.mapOfProdDetailIDToMrp.get(pw.selectedBatchID).MRP__c;
    					String updatedName = pw.mapOfProdDetailIDToMrp.get(pw.selectedBatchID).Name;
    					so.setlabel(updatedName+'-----'+updatedMRP+'-----'+updatedValue);
    				}
    			}
    		}
    	} 
	}
	
	public void viewCart(){
		
	}
	
	public void checkout(){
	}
	
	public pagereference  cancel(){
		productWrapperList.clear();
		slectedProductWrapperListCart.clear();
		custSelected = null;
		custDetail = null;
		PageReference pg = new PageReference('/apex/billingpage');
		return pg;
	}
	
 	public pagereference returnProductPage(){
    	return page.Product;
    }
    
	/*INNER CLASS DECLARATION FOR PRODUCT TABLE*/
	
	public class ProductWrapper{
		public boolean chkValue {get; set;}
		public Prod__c product {get;set;}
		public list<selectOption> batchNumberList {get; set;}
		public String selectedBatchID {get; set;}
		public integer qty {get; set;}
		public decimal amount {get; set;}
		public map<String,Prod_Detail__c> mapOfProdDetailIDToMrp = new map<String,Prod_Detail__c>();
		
		public ProductWrapper(prod__c p){
			batchNumberList = new list<selectOption>();
			product = p;
			for(Prod_Detail__c prd: p.Prod_Details__r){
				if(prd.Quantity__c > 0){
				batchNumberList.add(new selectoption(prd.Id,prd.Name+'-----'+prd.MRP__c+'-----'+prd.Quantity__c));
				mapOfProdDetailIDToMrp.put(prd.Id,prd);
				}
			}
		}
	}
}

 

Yoganand GadekarYoganand Gadekar

Hi,

here's a practcle example on wrapper class for you:

how-to-use-wrapper-class

 

Kit kudos if it helps you and mark as answer if it completely solves your problem.

 

Thanks

Avidev9Avidev9
LIl explanantion may be ?
What is not working ?
what is expected ?

We cant actually comment by just seeing the code.
anup-prakashanup-prakash

Thanks Avi..

 

The thing is that.. I have a wrapper class and when the form is submitted.. the data is not being set to the wrapper object..

anup-prakashanup-prakash
Just That if data could be set.. I've used wrapper class before.. but this time I don't know whats happening that the data is not being set to the wrapper Object..
anup-prakashanup-prakash

I am able to get the values on teh page but not setting the values..

Avidev9Avidev9

Man you have added immediate=true to your addButton, Please remove that one,(it actually skips validation and calls to setter)

 

Something like

 

<apex:commandButton action="{!addToCart}" rerender="pbs3" value="Add to Cart" />
This was selected as the best answer
anup-prakashanup-prakash
Removed it still no go!!
anup-prakashanup-prakash
Thanks Avi...
anup-prakashanup-prakash
The eclipse didn't save it coz of some network trouble.. did it again and worked...

So what did this Immidiate = true do??????
anup-prakashanup-prakash
I would have to say it once again that you guys are the heroes here..!!!! Thanks So Much Once again.....
Avidev9Avidev9
Immediate true basically escapes any page level validations like... if a field is marked required in the page by using "required= true", escapes setter .... etc.

Generally they are used when you dont need to send any data to the controller