You need to sign in to do that
Don't have an account?
bujji
Regading Command Links
Hi,
I have the situtation like i have some contries with command links in vf page.
If i click on this country in the below select list only the states particular to that county has to show.
How can we achieve this any idea.
It is very urgent.......................
Thanks,
Bujji
You can take idea form below code .I hope it would help.
<apex:page Controller="CountryCont">
<apex:form>
<h1>Sample for Country and State</h1>
<apex:dataList value="{!lstCountries}" var="country">
<apex:commandLink value="{!country}" id="theCommandLink" action="{!SaveMe}">
<apex:param assignTo="{!selectedCountry}" value="{!country}" name="countrySelected" id="countryId" />
</apex:commandLink>
</apex:dataList>
<apex:outputlabel value="States"/>
<apex:selectList value="{!states}" multiselect="false" id="statestlist" size="1">
<apex:selectOptions value="{!items}" />
</apex:selectList>
</apex:form>
</apex:page>
public class CountryCont{
public string selectedCountry {set;get;}
public List<string> lstCountries {set;get;}
public string states{set;get;}
public list<SelectOption> items{set;get;}
public CountryCont(){
lstCountries = new list<string> ();
lstCountries.add('U.S.A.');
lstCountries.add('Canada');
lstCountries.add('Pakistan');
}
public pageReference SaveMe(){
items= new List<SelectOption>();
if(selectedCountry == 'U.S.A.'){
items.add(new SelectOption('Illinos','Illinos'));
items.add(new SelectOption('Montano','Montano'));
}
else if(selectedCountry == 'Canada'){
items.add(new SelectOption('Alberta','Alberta'));
}
else{
items.clear();
}
return null;
}
}
Hi,
Already i have written some code can you tell me how to modify, I have two visual force pages "contrycustomlinks" and "statesByCounty". In custom Links i have 3 links with country name.
In statesByCountry i have a select list i want to display states particualr to the country i have clicke.
How can we do it.I t is very urgent. I am sending my code here.
contry custom Links
--------------------------------------
<apex:page showHeader="true">
<apex:form >
<apex:pageBlock >
<div ><h2>Contry Links</h2></div>
<apex:pageblockSection >
<apex:outputLink value="{!$Page.clubsByCountry}">India</apex:outputLink>
<apex:outputLink value="{!$Page.clubsByCountry}">America</apex:outputLink>
<apex:outputLink value="{!$Page.clubsByCountry}">Australia</apex:outputLink>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
statesNyCountry
-----------------------------------------
<apex:page showHeader="false" controller="dependent_picklist_controller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="States" collapsible="false" id="states">
<apex:pageBlockSectionItem >
<apex:outputLabel value="States: "/>
<apex:selectList size="1" multiselect="false" >
<apex:selectOptions value="{!States}"/>
</apex:selectList>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
controller
----------------------------------------------
public class customlink_contry
{
public String State { get; set; }
public String Country { get; set; }
private List<Foundation_States__c> States_list = new List<Foundation_States__c>();
private List<Foundation_States__c> States_list1 = new List<Foundation_States__c>();
Id linkAttr = ApexPages.currentPage().getParameters().get('id');
// Constructor - Executes on Initilization of the class only.
public customlink_contry()
{
// states list contains all the States with out any filters.
States_list = [SELECT id,
Name,
State_Code__c,
Foundation_Countries__c
FROM
Foundation_States__c
WHERE
Foundation_Countries__c != null
];
}
public List<selectOption> getStates()
{
//system.debug('***CheckC Country Value------'+Country);
List<selectOption> optionList = new List<selectOption>();
if(Country != null || Country != '')
{
for(Foundation_States__c Ostate : States_list )
{
//system.debug('*****Country ID******'+Ostate.Foundation_Countries__c);
if(Ostate.Foundation_Countries__c == Country )
{
//system.debug('*****Country String******'+Country);
optionList.add(new selectOption(Ostate.id,Ostate.name));
}
}// end for loop
}
return optionList;
}
}
Please modify the code........... to achieve the result or any help................
In Cusotmlink_country where are you assigning value in Country variable ? I think you need to use param to assign value in Country variable .
<apex:pageblockSection >
<apex:outputLink id="optLink1" value="{!$Page.clubsByCountry}">India</apex:outputLink>
<apex:outputLink id="optLink2" value="{!$Page.clubsByCountry}">America</apex:outputLink>
<apex:outputLink id="optLink3" value="{!$Page.clubsByCountry}">Australia</apex:outputLink>
<apex:param assignTo="{!Country}" name="countrySelected" id="countryId" value="Country" />
</apex:pageblockSection>
I added here but i am not getting states in other visual force page.
Please take hint from the code below.Add debug to make sure that selected country is assinged in variable.
<apex:outputLink id="optLink1" value="{!$Page.clubsByCountry}">India
<apex:param assignTo="{!Country}" name="countrySelected" id="countryIdIndia" value="India" />
</apex:outputLink>
<apex:outputLink id="optLink2" value="{!$Page.clubsByCountry}">America
<apex:param assignTo="{!Country}" name="countrySelected" id="countryIdAmerica" value="America" />
</apex:outputLink>