You need to sign in to do that
Don't have an account?
Showing Data in page block table by wrapper class
Hello Friends,
I am trying to create a table where we can show the data by wrapper class.here is my code
public class CLS_LeadPagination {
public List<leadWrapper> leadlist {get;set;}
public list<lead> leads{get;set;}
public list<string> leadString{get;set;}
public CLS_LeadPagination()
{
leadlist= new List<leadWrapper>();
leads=new list<lead>();
leadString=new list<string>();
leads= [select name,Email from lead order by name];
leadWrapper objwrap;
for(lead l:leads)
{
objwrap=new leadWrapper();
objwrap.leadobj=l;
leadlist.add(objwrap);
leadString.add(l.name);
}
}
public ApexPages.StandardSetController con {
get {
if(con == null) {
con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name FROM lead Order By Name ]));
con.setPageSize(10);
}
return con;
}
set;
}
public Boolean hasNext {
get {
return con.getHasNext();
}
set;
}
public Boolean hasPrevious {
get {
return con.getHasPrevious();
}
set;
}
public Integer pageNumber {
get {
return con.getPageNumber();
}
set;
}
public void first() {
con.first();
}
// returns the last page of records
public void last() {
con.last();
}
public void previous() {
con.previous();
}
// returns the next page of records
public void next() {
con.next();
}
// returns the PageReference of the original page, if known, or the home page.
public pageReference SelectRecord()
{
pageReference pr=new pageReference('/apex/VF_LeadNew_Edit_Page');
return pr;
}
public pageReference Cancel()
{
return null;
}
public class leadWrapper {
public Boolean checked{ get; set; }
public lead leadobj { get; set;}
public string leadname { get; set;}
public leadWrapper(){
leadobj = new lead();
leadname=leadobj.name;
checked = false;
}
}
}
++++++++++++++++++++++++++++++++
<apex:page controller="CLS_LeadPagination" >
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons location="top">
<apex:commandButton action="{!SelectRecord}" value="NewLead"/>
</apex:pageBlockButtons>
<apex:pageMessages />
<apex:pageBlockSection title="Leads - Page #{!pageNumber}" columns="1">
<apex:pageBlockTable value="{!leadlist}" var="lead">
<apex:column headerValue="Name">
<apex:outputLink value="/{!lead.leadobj.Id}/e">{!lead.leadobj.name} </apex:outputLink>
</apex:column>
<apex:column value="{!lead.leadobj.Email}" headerValue="Email"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:panelGrid columns="4">
<apex:commandLink action="{!first}">First</apex:commandlink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">Previous</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">Next</apex:commandlink>
<apex:commandLink action="{!last}">Last</apex:commandlink>
</apex:panelGrid>
</apex:form>
</apex:page>
but here i dont want to display data using standard variable(!lead.leadobj.name).Is there is any way to take variable in wrapper class and showing the name of lead by that.
Any quick reply will be very helpfull
Yes. You can do that. You have already done that.
Just make this change in VF page
<apex:outputLink value="/{!lead.leadobj.Id}/e">{!lead.leadname} </apex:outputLink>
Similarly you can create variables for email and other details in the wrapper class and use it on VF page
here i have used standard field.how can i create the variable inwarpper class and assign the value in them.
You have already done. I have highlighted it with BOLD
public class leadWrapper {
public Boolean checked{ get; set; }
public lead leadobj { get; set;}
public string leadname { get; set;}
public leadWrapper(){
leadobj = new lead();
leadname=leadobj.name;
checked = false;
}
}
I
Other approach you can take is as follows:
public class leadWrapper {
public Boolean checked{ get; set; }
public string leadname { get; set;}
public leadWrapper(){
checked = false;
}
}
leadWrapper objwrap;
for(lead l:leads)
{
objwrap=new leadWrapper();
objwrap.leadname=l.Name;
leadlist.add(objwrap);
}
}
First Name – Input Test box
Last Name – Input Test box
Gender – Radio button
Department – picklist
Submit button
On click of submit button display, the name = first name+ last name, gender and department in tabular format below the button
can any one explain how to get output through pageblock table using wrapper class.
<apex:page sidebar="false" controller="TableController">
<apex:form id="pb2">
<apex:pageBlock >
<apex:pageBlockSection columns="2">
<apex:inputText value="{!Firstname}" label="FirstName"/>
<apex:inputText value="{!Lastname}" label="LastName"/>
<apex:selectRadio value="{!SelectedGender}" label="Gender">
<apex:selectOption itemLabel="MALE" itemValue="MALE"/>
<apex:selectOption itemLabel="FEMALE" itemValue="FEMALE"/>
</apex:selectRadio>
<apex:selectList size="1" value="{!selectedpicklistvalue}" label="Department">
<apex:selectOption itemLabel="MIS" itemValue="MIS"/>
<apex:selectOption itemLabel="LEGAL" itemValue="LEGAL"/>
<apex:selectOption itemLabel="IP&SCIENCE" itemValue="IP&SCIENCE"/>
<apex:selectOption itemLabel="MEDIA" itemValue="MEDIA"/>
</apex:selectList>
</apex:pageBlockSection>
<apex:commandButton value="S U B M I T" action="{!submit}" reRender="pb2"/>
</apex:pageBlock>
</apex:form>
</apex:page>