Showing posts with label visual force. Show all posts
Showing posts with label visual force. Show all posts

Using Wrapper class for displaying records from two objects in a single table

Sometimes we need to display data from different objects (not related to each other) in a table. Best way to do that is using wrapper class. I am showing you an example where i am displaying records from contact and account object ( i am not using their r/ship, so it could be any two object)

Page:
<apex:page controller="Deleteme7_controller" >
<apex:pageBlock >
    <apex:pageblocktable value="{!final}" var="a">
            <apex:column value="{!a.acc.name}" /> 
            <apex:column value="{!a.con.name}"/>
            </apex:pageblockTable>
     </apex:pageBlock>
</apex:page>

Controller:

public with sharing class Deleteme7_controller {
List final3 = new list();
wrapclass wrapobject;
public Deleteme7_controller (){
list a= [select id,name from account];
list c = [select name,id from contact];
add(a,c);
}

public list getFinal(){
return final3;
}

public void add(list a,list b){
integer j=0;

public class wrapclass{
public account acc{get;set;}
public contact con{get;set;}

}
}

Date with inputtext

We can now use a standard datepicker with <apex:inputtext> also. you can use the code Make sure you have id attribute given some value in inputtext

Creating dependant pickist in visualforce from custom settings

Creating dependant pickist in visualforce from custom settings

Hi,
Today, i got a requirement for creating a dependant picklist which gets its values from custom setting. I thought of sharing it with you all.

In my example, i am selecting name of countries and its associated city from custom settings.

Steps :
1) Create a new list type custom setting, with only one text field named 'City' in my case.
2) Click on manage in the custom setting, and create a new record.
Name of the custom setting record should be name of the country.
City field contains name of the cities for that country, separated by ';'



3) Code for page :



<apex:page controller="CustomSettings_controller" >
<apex:pageBlock >
<apex:form >
<apex:actionFunction name="rerenderStates" rerender="ListState" >
<apex:param name="firstParam" assignTo="{!country}" value="" />
</apex:actionFunction>

<apex:pageblocksection >
Country <apex:selectList id="ListCountry" value="{!country}" size="1" onchange="rerenderStates(this.value)">
<apex:selectOptions value="{!countrylist}"></apex:selectOptions>
</apex:selectList>
</apex:pageblocksection>

<apex:pageblocksection >
State <apex:selectList id="ListState" value="{!states}" size="1">
<apex:selectOptions value="{!statelist}"></apex:selectOptions>
</apex:selectList>
</apex:pageblocksection>

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

4) code for controller :




public class CustomSettings_controller {


Map<String, countrystate__c> c = countrystate__c.getall();


public list<selectoption> getStateList() {
list<selectoption> s = new list<selectoption> ();
s.add(new selectoption('','Select one'));
if(country==null){
country='';
}
else
if(c.containskey(country)){
s.clear();
string sm = c.get(country).States__c;
for(string st: sm.split(';'))
s.add(new selectoption(st,st));
}

return s;
}


public List<SelectOption> getCountrylist() {
List<SelectOption> country = new List<SelectOption>();
country.add(new selectoption('India','---SELECT ONE---'));
list<string> countryname= new list<string>();
countryname.addall(c.keyset());

for(string s : countryname){
country.add(new selectoption(s,s));

}

return country;
}


public String states { get; set; }

public String country{ get; set;}

}


Final Outcome :