0

Image below is my visualforce page to select what are the fields I want to add to the Booker Information.

enter image description here

This is my apex code for the form/fields:

public PageReference BookerInformation(){

            PageReference gotosetup = new PageReference('/apex/bookerinformation?id=' + eventId);

            String comparelist; 

            List<Event__c> ev = [SELECT Id,Booker_Custom_Fields__c,Start_Date_Time__c ,End_Date_Time__c,Event_Name__c,Organiser_Name__c FROM Event__c
                 Where Id = :eventId AND Event__c.Booker_Custom_Fields__c != ''
                 LIMIT 1];

             if(ev.size()>0){  

                for(Event__c view: ev){
                         comparelist = view.Booker_Custom_Fields__c;   

                    }
                    list<String> comp = comparelist.split(';');
                    comp_set = new List<String>(comp);
                    system.Debug(comp_set);
             }


            gotosetup.setRedirect(false);
            return gotosetup;
    }

I got this fields, firstname, lastname and email are the default fields. While FieldName is my cusomized fields.

<div class="form-group">
    <label for="firtname" class="col-sm-4 control-label"><i class="asterisk">*</i> First Name</label>
    <div class="col-sm-8">
        <apex:inputField value="{!pbook.First_Name__c}" styleClass="form-control"/>
    </div>
</div>
<div class="form-group">
    <label for="latname" class="col-sm-4 control-label"><i class="asterisk">*</i> Last Name</label>
    <div class="col-sm-8">
        <apex:inputField value="{!pbook.Last_Name__c}" styleClass="form-control"/>
    </div>
</div>
<div class="form-group">
    <label for="emailaddress" class="col-sm-4 control-label"><i class="asterisk">*</i> Email Address</label>
    <div class="col-sm-8">
        <apex:inputField value="{!pbook.Email_Address__c}" styleClass="form-control"/>
    </div>
</div>

<apex:repeat value="{!comp_set}" var="fieldName">
<div class="form-group">
    <label for="customfields" class="col-sm-4 control-label customfields-label"><i class="asterisk"></i>{!fieldName}</label>
    <div class="col-sm-8">
        <apex:inputField value="{!pbook[fieldName]}" styleClass="form-control"/>
    </div>
</div>
</apex:repeat>
<div class="form-group">
    <label for="confirmemail" class="col-sm-4 control-label"></label>
    <div class="col-sm-8">
        <apex:commandButton action="{!BookingConfirmation}" value="PROCEED" styleClass="btn btn-success btn-proceed"/>
    </div>
</div>

This is Bokooking Confirmation code:

 public PageReference BookingConfirmation() {

      try{
           PageReference pagr= new PageReference('/apex/bookingconfirmation?id=' + eventId); 
           String FirstName = pbook.First_Name__c;
         String LastName = pbook.Last_Name__c;
         String Email = pbook.Email_Address__c;  

         //Custom Fields is not supposed to be like this. They must not set to static. How can I do this to make it dynamic. Loop? or Map?.
         //This custom maybe Address__c or City__c or Country__c.
         String Religion = pbook.Religion__c;   
         String Nationality = pbook.Nationality__c;
         pagr.getParameters().put('Religion',Religion);
         pagr.getParameters().put('Nationality',Nationality);    

         pagr.getParameters().put('FirstName',FirstName);
         pagr.getParameters().put('LastName',LastName);
         pagr.getParameters().put('Email',Email);

           pagr.setRedirect(false);  
           return pagr;  
        }
        catch(Exception ex){
        ApexPages.addMessages(ex);
        }
        return null; 
    }

And this is my other page just to display the details I fill up on the form:

    <div class="form-group">
    <label for="firtname" class="col-sm-4 control-label">First Name</label>
      <div class="col-sm-8">
       <p class="p-values">
        <apex:outputText value="{!$CurrentPage.parameters.FirstName}"/>
       </p>
      </div>
    </div>
    <div class="form-group">
    <label for="latname" class="col-sm-4 control-label">Last Name</label>
      <div class="col-sm-8">
       <p class="p-values">
         <apex:outputText value="{!$CurrentPage.parameters.LastName}"/>
       </p>
      </div>
     </div>
    <div class="form-group">
     <label for="emailaddress" class="col-sm-4 control-label">Email Address</label>
       <div class="col-sm-8">
         <p class="p-values">
          <apex:outputText value="{!$CurrentPage.parameters.Email}"/>
         </p>
       </div>
    </div>
<!-- This Religion and Nationality is not to be displayed like this. They must like a dynamic display since this field is customizable
     not a default fields.
 -->
<div class="form-group">
    <label for="emailaddress" class="col-sm-4 control-label">Religion</label>
    <div class="col-sm-8">
        <p class="p-values">
            <apex:outputText value="{!$CurrentPage.parameters.Religion}"/>
        </p>
    </div>
</div>
<div class="form-group">
    <label for="emailaddress" class="col-sm-4 control-label">Nationality</label>
    <div class="col-sm-8">
        <p class="p-values">
            <apex:outputText value="{!$CurrentPage.parameters.Nationality}"/>
        </p>
    </div>
</div>

My problem is how could I pass the dynamic field into a parameter to view it on the other page? I tried to loop it but its not working. Any idea on how to do this.?

  • What is comp_set comprised of? – Eric Aug 25 '15 at 2:31
  • Your second page should be using the same controller as the first then you can reference the values just like in the first page since you setRedirect(false). as long as they have the exact same controller/extensions. Also, how are you directing to the second page? A command button? If so make sure it has a rerender values post to the controller – Eric Aug 25 '15 at 2:34
  • DEBUG|(address__c, city__c) this is the comp_set.. those are the customized fields.. – Lennon Leopoldo Aug 25 '15 at 2:35
  • Sorry I do not understand what you are trying to say. Could you post the code around all fields being used as well as the VF and controller code around the method used to navigate to the second page – Eric Aug 25 '15 at 2:36
  • It can be like this.. DEBUG|(religion__c, nationality__c) depend on what fields I added to the form.. they are not static fields.. they are dynamic.. Thats why Its hard for me to determine and pass it a parameters. – Lennon Leopoldo Aug 25 '15 at 2:38
1

You should be able to reference comp_set in the second page if the controllers and extensions are the same.

Without seeing the page and everything in context there could be a lot of little things you are forgetting.

What you can do to force it to work it to JSON serialize the comp_set into a string and URL format it. Then in the controller for the second page deserialize it into the List to get the value.

Still unclear on how your flow works and what the opening page are on the first and second pages so hard to say.

Again, with the same controllers and extensions on both pages you should be able to access the values just like you did in the first page unless you marked it as transient or static or the controllers are different.

0

I already got it.. I just now the pbook.get() is working.. Below is the code to get the data from pbook from custom fields..

for(Integer i=0; i<comp_set.size(); i++){
    String list_field= String.valueOf(pbook.get(comp_set[i]));
    String label =  String.valueOf(comp_set[i]);

    pagr.getParameters().put(label, list_field);
    system.Debug(pbook.get(comp_set[i]));
 }

What I need to work now is How to display those parameters in the visualforce page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.