4

i am not able to access the enteredacc variable value in my other vf pages,i am using a single controller and also while moving from one page to another i am setting redirect to false,here is my apex classes and vf pages (3)

apex class:

public class picklistdemo1{

    public picklistdemo1(ApexPages.StandardController controller) {
    }

    public String enteredacc {get; set;}
    public String Acno1{get;set;}
    public String Acname{get;set;}
    public Double AcAnnualRevenue{get;set;}
    public String AcPhone{get;set;}
    public Date Acdate{get;set;}

    public void accDetails()
    { 
        system.debug('enteredaccno is '+enteredacc); 
        if(enteredacc == '' || enteredacc == null) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please enter valid Account number or if you are a new user register by clicking the below button'));
            return ;
        }
        else
        {
            List<Account> acc=[Select Name,AccountNumber,AnnualRevenue,Phone,SLAExpirationDate__c from Account where AccountNumber= :enteredacc];

            for(Account a : acc)
            {
                Acno1=a.AccountNumber;
                Acname=a.Name;
                AcAnnualRevenue=a.AnnualRevenue;
                AcPhone=a.Phone;
                Acdate=a.SLAExpirationDate__c;
            }
        }
    }


    public PageReference show1() {
        return null;
    }

    public ORDER__c rec=new ORDER__c();
    public List<SelectOption> listofbooks{get;set;}

    public list<String> selectedbooks { get; set; }

    public PageReference add() {

        rec.Accountname__c=enteredacc;
        rec.select_books__c=String.join(selectedbooks,',');
        insert rec;
        return null;
    }
    public PageReference gotoPage() {
        PageReference pr = Page.multipicklist;
        pr.setRedirect(false);
        return pr;
    }
    public PageReference gotoPageagain() {
        PageReference pr = Page.adding_order;
        pr.setRedirect(false);
        return pr;
    }

    public picklistdemo1()
    {
        listofbooks=new List<SelectOption>();
        listofbooks.add(new SelectOption('b1','b1'));
        listofbooks.add(new SelectOption('b2','b2'));
        listofbooks.add(new SelectOption('b3','b3'));
        listofbooks.add(new SelectOption('b4','b4'));
        listofbooks.add(new SelectOption('b5','b5'));
        listofbooks.add(new SelectOption('b6','b6'));
        listofbooks.add(new SelectOption('b7','b7'));
        listofbooks.add(new SelectOption('b8','b8'));
        listofbooks.add(new SelectOption('b9','b9'));
        listofbooks.add(new SelectOption('b10','b10'));
    }
}

vf page 1:

<apex:page standardController="Account" extensions="picklistdemo1">
<apex:form >
<apex:pageBlock id="firstblock" >
<apex:pageMessages id="showmsg"></apex:pageMessages>
<apex:pageBlockSection >
<apex:outputText >Enter Account Number:</apex:outputText>
<apex:inputText value="{!enteredacc}"/>
</apex:pageBlockSection>
<apex:commandButton value="Search" action="{!accDetails}" rerender="firstblock,nextblock,showmsg"/>
<apex:outputText >enteredacc:{!enteredacc}</apex:outputText>
<apex:commandButton value="Next!" action="{!gotoPage}"/>
</apex:pageBlock>

<apex:pageBlock id="nextblock">
<apex:pageBlockSection title="ACCOUNTDETAILS">
<apex:outputText >Account Number:</apex:outputText>
<apex:inputText value="{!Acno1}"/>

<apex:outputText >Account Name:</apex:outputText>
<apex:inputText value="{!Acname}"/>
<apex:outputText >Annual Revenue:</apex:outputText>
<apex:inputText value="{!AcAnnualRevenue}"/>
<apex:outputText >Phone No.:</apex:outputText>
<apex:inputText value="{!AcPhone}"/>

</apex:pageBlockSection>
<apex:pageBlockSection title="REGESTRATION">


<apex:inputText value="{!Account.AccountNumber}"/>
<apex:inputText value="{!Account.name}"/>

<apex:inputText value="{!Account.AnnualRevenue}"/>

<apex:inputText value="{!Account.Phone}"/>

<apex:inputText value="{!Account.SLAExpirationDate__c}"/>


<apex:commandButton value="REGISTER!" action="{!save}"/>
</apex:pageBlockSection>

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

vf page 2:

<apex:page controller="picklistdemo1">
<apex:form >
<apex:outputPanel >
<apex:outputLabel >select book from the list</apex:outputLabel>
<apex:selectList value="{!selectedbooks}" size="6" multiselect="true">
<apex:selectOptions value="{!listofbooks}">
<apex:commandbutton value="Show Values" action="{!show1}" rerender="pbs1,pbs2"/>
<apex:commandButton value="NEXT" action="{!gotoPageagain}"/>

</apex:selectOptions>
</apex:selectList>
</apex:outputPanel>
</apex:form>


<apex:pageBlock title="selected books">
<apex:pageBlockSection id="pbs1">
<apex:pageBlockSectionItem >
{!selectedbooks}
</apex:pageBlockSectionItem>
<apex:pageBlock title="accountvalue">
<apex:pageBlockSection id="pbs2">
<apex:pageBlockSectionItem > {!enteredacc}</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

vf page 3:

<apex:page controller="picklistdemo1">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="order information">
<apex:outputText > value="{!enteredacc}"</apex:outputText>
<apex:outputText > value="{!selectedbooks}"</apex:outputText>
<apex:commandButton value="PLACE ORDER" action="{!add}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

please help ,i am stuck in these for several hours..... Thanks in advance

1 Answer 1

4

The documentation clearly states that when a controller is shared between two pages and with setRedirect=false ,the view state is preserved only if and only if the target page uses the same controller and contains the proper subset of extensions used by the source page.

Hence looking into this I have changed the first line of your vf page to use your controller as extensions and it works for me

<apex:page standardController="Account" extensions="picklistdemo1">

Also note that your constructor wont run and hence you may create a getter for your picklist values

public List<SelectOption> getpicklistvalues(){
  listofbooks=new List<SelectOption>();
  listofbooks.add(new SelectOption('b1','b1'));
  listofbooks.add(new SelectOption('b2','b2'));
  listofbooks.add(new SelectOption('b3','b3'));
  listofbooks.add(new SelectOption('b4','b4'));
  listofbooks.add(new SelectOption('b5','b5'));
  listofbooks.add(new SelectOption('b6','b6'));
  listofbooks.add(new SelectOption('b7','b7'));
  listofbooks.add(new SelectOption('b8','b8'));
  listofbooks.add(new SelectOption('b9','b9'));
  listofbooks.add(new SelectOption('b10','b10'));
  return listofbooks;
}

enter image description here

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .