2

In my VF page I have an apex:selectList with a List of Vendors (e.g. Alcatel,Cisco ec..), the last option is "Other".

When the user select "Other" an apex:inputText should be rendered where he can writes the Vendor. I'm not able to render the inputText Field My VF page:

<apex:outputPanel id="vendor2">
<p><b> Vendor: </b></p>
<apex:selectList value="{!vendor}" multiselect="False" size="1">
    <apex:actionSupport event="onchange" action="{!specifyVendor}" rerender="otherPanel"/>
    <apex:selectOptions value="{!vendors}"/>
</apex:selectList><p/>
</apex:outputPanel>
<br/>
<apex:outputPanel id="otherPanel">
    <apex:inputText value="{!otherVendor}" rendered="{!vendor=='Other'}"> Other: </apex:inputText>
</apex:outputPanel>    
<br/><br/> 

The custom controller:

    public with sharing class ExcelPageController {

        public String vendor {get; set;}//Vendor Name
        public String otherVendor {get; set;}//Vendor Name

        public List<SelectOption> getVendors(){
            System.debug('getVendors');    
            List<SelectOption> options = new List<SelectOption>();
            options.add(new SelectOption('Cisco','Cisco'));
            options.add(new SelectOption('Alcatel','Alcatel'));
            options.add(new SelectOption('Tibco','Tibco'));
            options.add(new SelectOption('Other','Other'));
            return options;
        }
    public PageReference specifyVendor(){
        System.debug(vendor);
        return null;
    }
}
5

Place <apex:inputText> in separate outputPanel and try to rerender that panel on actionSupport call.

Also added at <apex:ouputText> to confirm the value is correctly be displayed

<apex:page controller="ExcelPageController">
<apex:form >
    <apex:outputPanel id="vendor2">
        <p><b>Vendor:</b></p>
        <apex:selectList value="{!vendor}" multiselect="False" size="1" onclick="rerender">
            <apex:actionSupport event="onchange" rerender="otherPanel,values" action="{!specifyVendor}"/>
            <apex:selectOptions value="{!vendors}"/>
        </apex:selectList><p/>
    </apex:outputPanel>
    <br/>
    <apex:outputPanel id="otherPanel">
        <apex:inputText value="{!otherVendor}" rendered="{!vendor=='Other'}"> Other: </apex:inputText>
    </apex:outputPanel>
    <br></br>
    You have selected:&nbsp;
    <apex:outputText value="{!displaySelectedText}" label="You have selected:" id="values" />  
</apex:form>

Controller

public with sharing class ExcelPageController {
 public String vendor {get; set;}//Vendor Name
 public String otherVendor {get; set;}//Vendor Name
 public string displaySelectedText {get;set;}

     public List<SelectOption> getVendors(){
         System.debug('getVendors');    
         List<SelectOption> options = new List<SelectOption>();
         options.add(new SelectOption('Cisco','Cisco'));
         options.add(new SelectOption('Alcatel','Alcatel'));
         options.add(new SelectOption('Tibco','Tibco'));
         options.add(new SelectOption('Other','Other'));
         return options;
     }

     public PageReference specifyVendor(){
        displaySelectedText  = vendor;
        System.debug(vendor);
        return null;
    }
 }

It will show like this:

Input field formatting

  • Thank you, I tried your code but the inputText is still not rendered – L.benedettini Nov 18 '16 at 15:27
  • then something you have done wrong. just take this entire code and run at your DE – Santanu Boral Nov 18 '16 at 15:30
  • I copy/pasted your code and I added an action to the apex:actionSupport that contains System.debug(vendor). Looking in the System.debug, vendor seems to not change at all. Further I edit my code so you can see the changes. – L.benedettini Nov 18 '16 at 15:57
  • Updated the code with little addition of outputText which is getting populated from specifyVendor(). Please close this question – Santanu Boral Nov 18 '16 at 16:21
  • I update the cose like you said Santanu, but loking in the System debug seems that specyfyVendor is not fired, i.e. vendor doesn't appear in the System debug anywhere – L.benedettini Nov 18 '16 at 16:48

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.