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
mikefmikef 

Issue with a pick list in VF

Hi:

I can't get my set method to fire when I have a selectList VF tag.

Code:
<!-- page code -->
<apex:selectList id="chooseRole" value="{!partnerRoleValue}" size="1">
        <apex:selectOption itemValue="Source Lead" itemLabel="Source Lead"/>
        <apex:selectOption itemValue="Joint Sales" itemLabel="Joint Sales"/>
        <apex:selectOption itemValue="Reseller" itemLabel="Reseller"/>
        <apex:selectOption itemValue="Referral" itemLabel="Referral"/>
        <apex:selectOption itemValue="Technology" itemLabel="Technology"/>
</apex:selectList>


Code:
/**controller code**/

public String getPartnerRoleValue() {
     return partnerRoleValue;
}

public void setPartnerRoleValue(String parterRoleValues) {
     this.partnerRoleValue = partnerRoleValue;
     System.debug('test partner value ' + getPartnerRoleValue()); 
}

When viewing the  system  log window the debug comes up null, and the value of the selectList doesn't populate back to sfdc.
I have other fields on the record that I populate and their are working fine.


 

jwetzlerjwetzler
That code worked for me.

Code:
<apex:page controller="selectCon" id="thePage">
    <apex:outputPanel id="thePanel">
        {!partnerRoleValue}
    </apex:outputPanel>
    
    <apex:form>
        <apex:selectList id="chooseRole" value="{!partnerRoleValue}" size="1">
            <apex:selectOption itemValue="Source Lead" itemLabel="Source Lead"/>
            <apex:selectOption itemValue="Joint Sales" itemLabel="Joint Sales"/>
            <apex:selectOption itemValue="Reseller" itemLabel="Reseller"/>
            <apex:selectOption itemValue="Referral" itemLabel="Referral"/>
            <apex:selectOption itemValue="Technology" itemLabel="Technology"/>
        </apex:selectList>
        <apex:commandButton value="rerender" rerender="thePage:thePanel"/>
    </apex:form>
</apex:page>

 
Code:
public class selectCon {
    String value = ''; 
    
    public String getPartnerRoleValue() {
        return value;
    }
    
    public void setPartnerRoleValue(String partnerRole) {
        value = partnerRole;
        System.debug('test partner value ' + getPartnerRoleValue());
    }
}

 
Any difference between what I'm doing and what you're doing?

Jill

mikefmikef
Thanks Jill:

I looked at your code and the only thing that was different is the form tag.

So I copy and pasted your code in my page and the system.debug sill comes up null.

Could this be an org setting?
jwetzlerjwetzler
I don't think there's really any org setting that would affect this.

Would you mind posting your whole page and controller?  Or if not could you shrink it down to something I can fully copy and paste into my test org?

Jill
mikefmikef
The formating will be off but here is the code.


Code:
<apex:page controller="AddPartnerController" tabStyle="Opportunity">
<apex:form>
<apex:pageBlock mode="detail" id="block">
<apex:pageBlockSection>
<apex:pageBlockSectionItem>
<apex:outputLabel for="searchText">Search Text</apex:outputLabel>
<apex:panelGroup>
<apex:inputText id="searchText" value="{!searchText}"/>
<apex:commandButton value="Go!" action="{!search}" rerender="block" status="status"/>
<apex:commandButton value="Remove Partner" action="{!removePartner}" rerender="block" status="remove"/>
</apex:panelGroup>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>

<apex:actionStatus id="status" startText="requesting..."/>
<apex:pageBlockSection title="Results" id="results" columns="1" rendered="{!dataTableVisibility}">
<apex:pageBlockList value="{!results}" var="acc">
<apex:column>
<apex:facet name="header"><b>Action</b></apex:facet>
<apex:commandLink action="{!pickPartner}" value="{!action}" >
<apex:param assignTo="{!accountId}" name="pickPartnerId" value="{!acc.id}"/>
<apex:param assignTo="{!selectedAccountName}" name="pickPartnerName" value="{!acc.Name}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!acc.Name}"/>
<apex:column value="{!acc.Website}"/>
<apex:column value="{!acc.Partner__c}"/>
</apex:pageBlockList>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
<apex:pageBlock mode="detail" id="selectedAccBlock" rendered="{!pickedAccountVisibility}">
<apex:pageBlockSection>
<apex:pageBlockSectionItem>

<apex:outputPanel id="selectedAccount" styleClass="tableDetail">
<apex:outputText id="selectedAccountText" value="You have selected Account : ">
</apex:outputText>
<apex:outputText id="selectedAccountName" style="font-weight:bold;font-size:1.2em" value="{0}">
<apex:param value="{!selectedAccountName}"/>
</apex:outputText><br/><br/>
<apex:outputText id="selectedRole" style="" value="Please select the partner's role : ">
</apex:outputText>
<apex:form>
<apex:selectList id="chooseRole" value="{!partnerRoleValue}" multiselect="false" size="1">
<apex:selectOption itemValue="Source Lead" itemLabel="Source Lead"/>
<apex:selectOption itemValue="Joint Sales" itemLabel="Joint Sales"/>
<apex:selectOption itemValue="Reseller" itemLabel="Reseller"/>
<apex:selectOption itemValue="Referral" itemLabel="Referral"/>
<apex:selectOption itemValue="Technology" itemLabel="Technology"/>

</apex:selectList>

<p>
<apex:commandButton value="Save" action="{!saveToOppty}" rerender="out" status="statusSave"/>
</p>
</apex:form>
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>

 
Code:
public class AddPartnerController{

private List<Account> results = new List<Account>();
private Map<Id,Account> accMap = new Map<Id,Account>();
private Boolean dataTableVisibility = false;
private String searchText;
private Id accountId;
private String selectedAccountName;
private String action = 'Select';
private Boolean pickedAccountVisibility = false;
private String partnerRoleValue;

public AddPartnerController(){

}

public String getPartnerRoleValue() {
return partnerRoleValue;
}

public void setPartnerRoleValue(String parterRoleValues) {
this.partnerRoleValue = partnerRoleValue;
System.debug('test partner value ' + getPartnerRoleValue());
}

public List<Account> getResults() {return results;}
public Boolean getDataTableVisibility() {return dataTableVisibility;}
public void setDataTableVisibility(Boolean arg) {dataTableVisibility = arg;}
public void setSearchText(String arg){searchText = arg;}
public String getSearchText(){return searchText;}
public Id getAccountId(){return accountId;}
public void setAccountId(Id arg){accountId = arg;}
public String getSelectedAccountName(){return selectedAccountName;}
public void setSelectedAccountName(String arg){selectedAccountName = arg;}
public String getAction(){return action;}
public void setPickedAccountVisibility(Boolean arg){pickedAccountVisibility = arg;}
public Boolean getPickedAccountVisibility(){return pickedAccountVisibility;}


public void search() {
String accName = getSearchText();
setPickedAccountVisibility(false);
setDataTableVisibility(true);
results = [select Id, Name, WebSite, Partner__c, Oracle_Vendor_ID__c from Account Where Partner__c = : true AND Name like : '%' + accName + '%' Limit 10 ];
fillAccountMap(results);
}

public void pickPartner(){
setPickedAccountVisibility(true);
setDataTableVisibility(false);
}

public PageReference saveToOppty(){
Id opptyId = System.currentPageReference().getParameters().get('oppId');
String partnerRole = getPartnerRoleValue();
Alliance_Enrollment__c partnership = partnershipQuery(getAccountId());

Opportunity opp = new Opportunity(id=opptyId,
Lead_Sales_Partner_new__c=getAccountId(),
Lead_Sales_Partner_Role__c=partnerRole,
Partner_Region_new__c=partnership.Region__c,
Oracle_Vendor_Number__c=accMap.get(getAccountId()).Oracle_Vendor_ID__c,
Partner_Type__c=partnership.type_of_partnership__c);
String url;

update opp;

url = '/' + opptyId;

PageReference page = new PageReference(url);
page.setRedirect(true);
return page;
}
public List<SelectOption> getPartnerRoles(){

List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('Sourced Lead','Sourced Lead'));
options.add(new SelectOption('Joint Sales','Joint Sales'));
options.add(new SelectOption('Reseller','Reseller'));
options.add(new SelectOption('Renewal','Renewal'));
options.add(new SelectOption('Technology','Technology'));
return options;
}
public void fillAccountMap(List<Account> accList){
for(Account a : accList){
accMap.put(a.Id,a);
}
}

public Alliance_Enrollment__c partnershipQuery(Id id){
return [select Region__c, type_of_partnership__c from Alliance_Enrollment__c where Account__c = : id Limit 1];
}
public PageReference removePartner(){
Id opptyId = System.currentPageReference().getParameters().get('oppId');


Opportunity opp = new Opportunity(id=opptyId,
Lead_Sales_Partner_new__c=null,
Lead_Sales_Partner_Role__c=null,
Partner_Region_new__c=null,
Oracle_Vendor_Number__c=null,
Partner_Type__c=null);
String url;

update opp;

url = '/' + opptyId;

PageReference page = new PageReference(url);
page.setRedirect(true);
return page;
}


}

 


jwetzlerjwetzler
Whoops.  Typo :)

public void setPartnerRoleValue(String parterRoleValues) {
this.partnerRoleValue = partnerRoleValue;
System.debug('test partner value ' + getPartnerRoleValue());
}

Since you have a partnerRoleValue String in your class, all your code is doing is setting the variable to itself every time.

Jill

mikefmikef
WOW that is it.

Thank you I thought this.partnerRoleValue would reference the class's variable.


Message Edited by mikef on 04-01-2008 05:37 PM
mtbclimbermtbclimber
Just a hunch, but it looks like you are trying to present a picklist for the role field on partner.

Whether you are trying to actually create a partner or just want to leverage the values from that field doesn't really matter but you might get value from actually leveraging the field itself through inputFIeld so it's values are managed dynamically from the field definition under setup.

To do this you just need to construct a dummy partner object. Here's an example:

PAGE:
<apex:page controller="partnerTestCon">
  <apex:form>
    <apex:inputField value="{!partner.role}"/>
  </apex:form>
</apex:page>

 
CONTROLLER:
public class PartnerTestCon {
  Partner p = new partner();
  public Partner getPartner() { return p; }
}

 
It could be that you want to keep these values out of reach of an admin but for those that want to leverage the point & click management of those values this may be a useful approach.

Note: You can also dynamically manage your picklist options in code using the selectOption type and selectOptions component. There was a recent write up on that on the blog with an accompanying page on the wiki.

mikefmikef
Andrew:

Thank you this is exactly what I want todo.

Now I need to write back to salesforce the selection the user picked.

In my controller I have a method that saves an Opportunity record with values the user picked along the way.
I need to populate my partnerRoleValue variable.

How do I do that with the inputField?
And is there a better way?
mtbclimbermtbclimber
Sorry if I missed something (lots of code to digest) but I think all you need to do is something like this.....

Code:
public class PartnerTestCon {
  Partner p = new partner();
  public Partner getPartner() { return p; }

/* method copied from mikef's sample */
public PageReference saveToOppty(){
Id opptyId = System.currentPageReference().getParameters().get('oppId');
String partnerRole = p.role;

//rest of the method snipped for brevity

}

 

mikefmikef
This is the last step in the perfect solution that is the Force.com platform.

Thanks Andrew.