-1

Hi i am writing a simple controller class with code

public class OMTime1 {

    public String xx { get; set; }


  public PageReference continue1(){
    String url='/apex/OneMoreTime?id='+ApexPages.currentPage().getParameters().get('id')+'&process='+xx;
    PageReference page=new PageReference(url);
     page.setRedirect(true);
        return page;
    }
}

and a simple VF Page with code

<apex:page controller="OMTime1" >
  <!-- Begin Default Content REMOVE THIS -->

  <!-- End Default Content REMOVE THIS -->
  <apex:form >
   <apex:selectList id="chooseColor" value="{!xx}" size="1">
            <apex:selectOption itemValue="1" itemLabel="Terminate Resource"/>
            <apex:selectOption itemValue="2"
             itemLabel="Change Resource Position at Same Location"/>
            <apex:selectOption itemValue="3" itemLabel="Change Resource Position with in same Location "/>
            <apex:selectOption itemValue="4"  itemLabel="Change Resource Position to a Different Location"/>
        </apex:selectList>
               </apex:form>
               <apex:form >
             <apex:commandButton value="Continue" action="{!continue1}"    id="theButton"/>
</apex:form>
</apex:page>

my task s when user click on button name as Continue page will redirect to it a url /apex/OneMoreTime?id=record_id&process=some_value some_value=1,2,3, or 4 but when i click on button it redirect to /apex/OneMoreTime?id=record_id&process=null

why this null is coming in parameter i want to redirect a value related to label of select option.please suggest way how to resolve it

mathlearner
  • 7,509
  • 31
  • 126
  • 189

1 Answers1

0

Short answer: because <apex:commandButton> is broken ;)

Recently I've posted an explanation of 2 most common workarounds on Salesforce-dedicated stackexchange site: https://salesforce.stackexchange.com/questions/4937/command-button-vs-command-link

Use an <apex:commandLink styleClass="btn"> and it will work while looking almost the same as button.

Community
  • 1
  • 1
eyescream
  • 18,088
  • 2
  • 34
  • 46