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
dai.odaharadai.odahara 

picklist tag for visual force

Hi, I'm coding visualforce page.

I want to implement picklist item by visualforce but I cant see picklist tag element with visualforce reference guide..

Does anyone know how to code it or Should I write picklist code by javascript in <script> tag??

Thank you very much
jwetzlerjwetzler
If you want to bind to a picklist field on a salesforce object, you can just use inputField (for example, apex:inputField value="{!account.industry}") and it will appear the way the field does on the account edit page.

But if you want to make your own picklist with your own data, use the selectList component.  Give it a size of 1 to make it a dropdown.

Jill
dchasmandchasman
... and sometimes you want to combine the 2 concepts, leverage the cool automagic apex:inputField picklist (or date picker is another common request) behavior when you don't have an Sobject. For that you just create a surrogate or proxy, in memory only, SObject instance that you can bind to - basically using the SObject purely as a data transfer object.
dai.odaharadai.odahara
Thanks, what I'm trying to implement is my own pick list (such as profile dropdown list on User information) on a custom object. As jwetzler described, I gave its size 1 in order to show dropdown list like this.

Page Code:
<apex:pageBlockSection title="Info" columns="2">
  <apex:selectList value="{!profiles}" size="1" required="true">
    <apex:selectOptions value="{!items}"/>
  </apex:selectList>
</apex:pageBlockSection>

 
Controller Code:
public class MyController {

  String[] ps= new String[]{};

  public String[] getProfiles() {
    return ps;
  }

  public void setProfiles(String[] ps) {
    this.ps = ps;
  }

  public List<SelectOption> getItems() {
    List<SelectOption> op = new List<SelectOption>();
    for(Profile p : [SELECT Id, Name FROM Profile]) op.add(new SelectOption(p.Id, p.Name));
    return op;
  }

public void save() {

update ...
}
}

 Now I want to insert a profile name into a name field (this is mandatory field, so I've added 'required') on custom object..
Please let me know if you know how to do the followings..

1. how to display red vertical line next to required item. I've coded like above ' <apex:selectList value="{!profiles}" size="1" required="true">' but no red line has been displayed. What should I do fot it...in order to show like name field of Account, Contact..(make sense?)

2. how to refer to data from controller. Also I atemp to add a save button, I'd like to reflect a select value of the dropdown list.
    Should I do it via javascript..? ( page -> javascript -> controller )

Thank you so much,
dai.odaharadai.odahara
OK...I could do it.. thank you so much
samdsamd
Hi

I'm having a similar problem with getting required fields to be displayed with a red bar and was wondering whether you found a solution to your question. 

I have a VF page to customise the process of creating a new task.  If I use the following

Code:
<apex:inputField value={!Task.Subject}" />

then I get a lookup link that allows users to select some commonly used options for the subject (eg. Call, Send Letter, Send Quote etc.).  I don't want this lookup link to appear, so I have used the code below instead

Code:
<apex:inputText value="{!Task.Subject}" required="true" ><b>Subject</b>&nbsp;&nbsp;&nbsp;</apex:inputText>

 
However, even though the required="true" is set, there is no red bar displayed on this field.  On clicking "Save" without providing a value for this field, no error message is displayed but the record is not saved and the user is returned to the task creation page.  Do you have any ideas what I'm doing wrong?

Many thanks in advance

Sam





mba75mba75

Hi Doug ,

I create some dependant dropdown from of 3 fields and I even create my last dropdown from a webservice without Sobject behind . I a reaaly happy with that .

But now I want to include in my page some sobject with dependant picklist behaviour in the standard ( I mean a non visualforce or scontrol layout) opportunity product edit layout. The 3 following input filed are dependant in Salesforce but this behaviour does not work in My visualforce page .

<apex:inputField id="OliRevenue_Type" value="{!OpportunityLineItem.Revenue_Type__c}"/>

<apex:inputField id="OliFrequency" value="{!OliFrequency}" /> "depends on Revenue type"

<apex:inputField id="OliBilling_Term" value="{!OpportunityLineItem.Billing_Term__c}" /> "depends on Frequency"

 So I have 2 question :

1 - Can I activate the dependant picklist  property  ?

2 - if not  how can I filter my picklist value ? (

3 - I read somewhere that the picklist value are not accessible from the API is tht mean that I have to hard code my picklist valu in my code ?

 

 

 

 

 

Krishna SambarajuKrishna Sambaraju
Hi Samd,

To make the inputText field required and the red bar to appear, you need to do the following.

<apex:outputLabel value="Subject:" for="inputText"/>
<apex:outputPanel styleClass="requiredInput" layout="block">
        <apex:outputPanel styleClass="requiredBlock" layout="block"/>
        <apex:inputText value="{!Task.Subject}" required="true" id="inputText"/>
 </apex:outputPanel>

Hope this helps.

Regards,
Krishna.