function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chitral ChaddaChitral Chadda 

show selected picklist value in other vf pge

it dosent work issue is with id

<apex:page controller="showpick">
<apex:sectionHeader title="this is section header title"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="this is page block section title" columns="2">
<apex:selectList size="1" value="{!selectedcountry}">
<apex:selectOptions value="{!country}"/>
<apex:actionSupport event="onchange" rerender="save"/>

</apex:selectList>

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

class:
public class showpick
{
     public string selectedcountry{get;set;}
     public showpick()
     {}
    
     public list<selectoption> getcountry()
     {
       list<selectoption> options = new list<selectoption>();
      options.add(new selectoption('-','none'));
      options.add(new selectoption('abc','a'));
      options.add(new selectoption('xyz','x'));
     
      return options;
    
     }
     public pagereference save()
     {
      pagereference pref = new pagereference('/apex/show?id='+id);
      pref.setredirect(true);
      return pref;
      }
}
Error Error: showpick Compile Error: Variable does not exist: id at line 19 column 63

other vf page
<apex:page standardController="account">
<apex:pageBlock>
<apex:pageBlockSection>
<apex:outputText label="you selected" value="{!selectedcountry}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>
 
</apex:page>
Best Answer chosen by Chitral Chadda
Prem_PalPrem_Pal
Please declare the "id" variable, may be a of data type string.
public class showpick
{
     public string selectedcountry{get;set;}
     public string id;
     public showpick()
     {}
    
     public list<selectoption> getcountry()
     {
       list<selectoption> options = new list<selectoption>();
      options.add(new selectoption('-','none'));
      options.add(new selectoption('abc','a'));
      options.add(new selectoption('xyz','x'));
     
      return options;
    
     }
     public pagereference save()
     {
      pagereference pref = new pagereference('/apex/show?id='+id);
      pref.setredirect(true);
      return pref;
      }
}

If you want use that variable as property please use getter setter methods.


All Answers

Prem_PalPrem_Pal
Please declare the "id" variable, may be a of data type string.
public class showpick
{
     public string selectedcountry{get;set;}
     public string id;
     public showpick()
     {}
    
     public list<selectoption> getcountry()
     {
       list<selectoption> options = new list<selectoption>();
      options.add(new selectoption('-','none'));
      options.add(new selectoption('abc','a'));
      options.add(new selectoption('xyz','x'));
     
      return options;
    
     }
     public pagereference save()
     {
      pagereference pref = new pagereference('/apex/show?id='+id);
      pref.setredirect(true);
      return pref;
      }
}

If you want use that variable as property please use getter setter methods.


This was selected as the best answer
Chitral ChaddaChitral Chadda

i made the change 
and when after select the pick list value
https://c.ap1.visual.force.com/apex/v?id=null

other vf page (rpage refernce)
Error Error: Unknown property 'AccountStandardController.selectedcountry'

<apex:page standardController="account">
<apex:pageBlock>
<apex:pageBlockSection>
<apex:outputText label="you selected" value="{!selectedcountry}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:page>
Prem_PalPrem_Pal
That is obvious!

You have to set a value before you use it.

Please update the logic of your code.
Chitral ChaddaChitral Chadda
Sure
Chitral ChaddaChitral Chadda
unable to figure out the change
cz my actual requuiremnt is that wen i select a value from piklist it shud  display that select value in other vf page
Error Error: Unknown property 'AccountStandardController.selectedcountry'

<apex:page standardController="account">
<apex:pageBlock>
<apex:pageBlockSection>
<apex:outputText label="you selected" value="{!selectedcountry}">
</apex:outputText>
</apex:pageBlockSection>
</apex:pageBlock>

</apex:page>

do i need to make change in this particular part of code?