+ Start a Discussion
DannyK89DannyK89 

Getting Value from Command Button

I would like a value from the visual force page to be transfered to the controller. It seems like the value from the command button is not being transfers. Can someone please help or tell me what I have done wrong. 

 

Here is the section fo the controller. 

 

 

public class SearchController {

    public String Searchtxt {get; set;}
    public Boolean Checkbox {get; set;}
    public String jobSelect {get; set;}
    List<Job__c> joblist = [SELECT Name, Bounty__c, Bounty_Other__c, Bounty_Rules__c FROM Job__c ORDER BY Name];
    
    public List<Job__c> getJob(){
        return joblist;
    }
    public Referral__c referral{
    get{if(referral == null) referral = new Referral__c();  
    referral.Referee__c = ApexPages.currentPage().getParameters().get('id');
    return referral;} set;}
    
    public PageReference SearchId() {
        joblist = [SELECT Name, Bounty__c, Bounty_Other__c, Bounty_Rules__c FROM Job__c WHERE Name =:Searchtxt];
        if(Searchtxt == '' || Searchtxt == null) joblist = [SELECT Name, Bounty__c, Bounty_Other__c, Bounty_Rules__c FROM Job__c ORDER BY Name];
        return null;
    }
    
        public PageReference Referral() {
            jobSelect = ApexPages.currentPage().getParameters().get('id'); 
            for(Job__c j : joblist){
                if(j.id == jobSelect) referral.Job__c = j.Id;
            }
            insert referral;
            PageReference tosecondpage = Page.leadstep1;
            tosecondpage.getParameters().put('Id',referral.Id);
            tosecondpage.setRedirect(true);
            return tosecondpage;
    }
    
    
}

 

 

Here is the Visual Force Page. 

 

<apex:page tabStyle="Job__c" controller="SearchController">
    <apex:form >
        <apex:sectionHeader title="Choosing a Job!"/>
        <apex:pageBlock >
            <apex:pageBlockSection title="Search Job Ids">
                <apex:outputLabel value="If you know the Job Id please enter it here and click 'Search'" for="Search">
                    <br/>
                    <apex:inputText id="Search" value="{!Searchtxt}"/>
                </apex:outputLabel>
                    <br/>
                    <apex:commandButton value="Search" action="{!SearchId}"/>
                    <br/>
                    <apex:commandButton value="Referral" action="{!Referral}"/>
            </apex:pageBlockSection>
            <apex:pageBlockTable value="{!job}" var="item">
                <apex:column width="1%">
                    <apex:inputCheckbox value="{!Checkbox}"/>
                </apex:column>
                <apex:column value="{!item.Name}" width="5%"/>
                <apex:column value="{!item.Bounty__c}" width="5%"/>
                <apex:column value="{!item.Bounty_Other__c}" width="5%"/>
                <apex:column value="{!item.Bounty_Rules__c}" width="5%"/>
                <apex:column width="1%">
                    <apex:commandButton value="About" onclick="window.open('/{!item.Id}');return false;"/>
                    <apex:commandButton value="Referral" action="{!referral}">
                        <apex:param name="jobSelect" value="{!item.Id}"/>
                    </apex:commandButton>
                </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
sravusravu

<apex:param> doesn't really work with <apex:CommandButton>. Try using <apex:commandLink> instead <apex:commandButton> and use style attribute to make the link look like a button. 

All Answers

AhmedPotAhmedPot

Hi,

 

You have missed assignedto parameter in your apex:param tag.

 

<apex:param name="nickName" value="{!stakeholer.id}" assignTo="{!stakeHolderId}"/>
DannyK89DannyK89

OK I put the assignTo in there and still it won't work. It's almost like the Id doesn't want to transfer. 

sravusravu

<apex:param> doesn't really work with <apex:CommandButton>. Try using <apex:commandLink> instead <apex:commandButton> and use style attribute to make the link look like a button. 

This was selected as the best answer