+ Start a Discussion
Atla MasthanaiahAtla Masthanaiah 

Wraper Class

public class ProdWraper {
    public String name{set;get;}
    public String id{set;get;}
    public Decimal cost{set;get;}
    public ProdWraper(String name,String id,Decimal cost){
        this.name='name';
        this.cost=cost;
        this.id='id';
    }
}

public class WraperItem {
    public map<String,ProdWraper> obmap{set;get;}
    public list<selectoption> options{set;get;}
    public String selected{set;get;}
    public ProdWraper pw{set;get;}
    public WraperItem(){
        obmap=new list<String,ProaWraper>();
        options=new list<selected>();
        ProdWraper pw=new ProdWraper(name='mahesh',id='E-01',100);
        obmap.put(pw.id,pw);
        ProdWraper pw1=new ProdWraper(name='naresh',id='E-02',200);
        obmap.put(pw1.id,pw1);
        ProdWraper pw2=new ProdWraper(name='mahesh',id='E-03',100);
        obmap.put(pw2.id,pw2);
        set<String> key=obmap.keyset();
        selectoption op=new selectoption('NONE','--NONE--');
        options.add(op);
        for(String p:key){
            selectoption s=new selectoption(p,p);
            options.add(s);
        }
    }
    public void getWrap(){
        pw=obmap.get(selected);
    }
}

<apex:page controller="WraperItem">
    <apex:form>
    <apex:pageBlock title="productwraper" id="one">
        <apex:outputLabel value="name"/>
        <apex:selectList value="{!selected}" size="1">
            <apex:selectOptions value="{!obmap}"/>
            <apex:actionSupport event="onchange" action="{!getWrap}" reRender="one"/>
            </apex:selectList>
        <apex:outputLabel value="EnterName"/>
       <apex:inputText value="{!pw.name}"/>
         <apex:outputLabel value="Enterid"/>
       <apex:inputText value="{!pw.id}"/>
         <apex:outputLabel value="Entercost"/>
       <apex:inputText value="{!pw.cost}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

This is Wrapper class   pro
pls Correct my code
Mahesh DMahesh D
Hi Atla,

Please find the modified VF Page and Apex Class:

I also tested it in my DE environment and it is displaying properly.
<apex:page controller="WraperItem">
    <apex:form>
    <apex:pageBlock title="productwraper" id="one">
        <apex:outputLabel value="name"/>
        <apex:selectList value="{!selected}" size="1">
            <apex:selectOptions value="{!obmap}"/>
            <apex:actionSupport event="onchange" action="{!getWrap}" reRender="one"/>
            </apex:selectList>
        <apex:outputLabel value="EnterName"/>
       <apex:inputText value="{!pw.name}"/>
         <apex:outputLabel value="Enterid"/>
       <apex:inputText value="{!pw.id}"/>
         <apex:outputLabel value="Entercost"/>
       <apex:inputText value="{!pw.cost}"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>
public class WraperItem {
    public map<String,ProdWraper> obmap{set;get;}
    public list<SelectOption> options{set;get;}
    
    public String selected {set;get;}
    
    public ProdWraper pw{set;get;}
    public WraperItem(){
        obmap=new Map<String,ProdWraper>();
        options=new list<selectoption>();
        ProdWraper pw=new ProdWraper('mahesh', 'E-01',100);
        obmap.put(pw.id,pw);
        ProdWraper pw1=new ProdWraper('naresh', 'E-02',200);
        obmap.put(pw1.id,pw1);
        ProdWraper pw2=new ProdWraper('mahesh', 'E-03',100);
        obmap.put(pw2.id,pw2);
        set<String> key=obmap.keyset();
        selectoption op=new selectoption('NONE','--NONE--');
        options.add(op);
        for(String p:key){
            selectoption s=new selectoption(p,p);
            options.add(s);
        }
    }
    public void getWrap(){
        pw=obmap.get(selected);
    }
    
    public class ProdWraper {
        public String name{set;get;}
        public String id{set;get;}
        public Decimal cost{set;get;}
        public ProdWraper(String name,String id,Decimal cost){
            this.name='name';
            this.cost=cost;
            this.id='id';
        }
    }
}

Also find the below useful links about Wrapper Class.

Wrapper class in Apex Salesforce

A wrapper or container class is a class, a data structure, or an abstract data type which contains different objects or collection of objects as its members.

A wrapper class is a custom object defined by programmer wherein he defines the wrapper class properties. Consider a custom object in salesforce, what do you have in it? fields right? different fields of different data types. Similarly wrapper class is a custom class which has different data types or properties as per requirement. We can wrap different objects types or any other types in a wrapper class.
In the Visualforce most important use case is to display a table of records with a check box and then process only the records that are selected.

https://developer.salesforce.com/page/Wrapper_Class

https://developer.salesforce.com/forums/?id=906F0000000AZh8IAG

http://www.sfdcpoint.com/salesforce/wrapper-class-in-apex/

https://success.salesforce.com/answers?id=90630000000hSoLAAU

https://success.salesforce.com/answers?id=90630000000hSoLAAU

http://salesforce.stackexchange.com/questions/41998/wrapper-class-controller-and-visualforce


Please do let me know if it helps you.

Regards,
Mahesh