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
KidNikiKidNiki 

Modifying Visual Force Component Attributes, ie changing rendered value...

Okay, I searched and couldn't find this so Im gonna have to ask.  Im building a VF page and I would like to keep certain things hidden and then unhide them based on the results of SOQL query's or code in the controller. 

 

I have an inputText component that the user uses to search with and a hidden selectList that I only want to be visible if the search returns more than one result.  Can I set this like I would an asp.net component in the controller or do I have to do this via JS somehow?  I have some other lists and fields I would like to do this with as well.

 

here is my code so far:

 

VF:

<apex:selectList id="dealerSelect" value="{!initStr}" size="1" disabled="true" rendered="false">
                <apex:selectOptions value="{!dealers}" />
            </apex:selectList>

 Controller:

if(dealerIDs.Size() > 1){
					//pageRef.
					ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO, 'From Name: ' + dealerIDs[1].Name));
				}
				} catch(Exception e){
				ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING, 'Error' + e));
				}

 The messages are there as references for myself right now.

 

 

Thank you!

 

Best Answer chosen by Admin (Salesforce Developers) 
Chamil MadusankaChamil Madusanka

Hi,

 

You need to define a boolean attribute in your controller class with default getter setter.

 

public class YourClassName{

    public Boolean DisplaySelectList{get;set;} 
//Your code here

}

 Then in VF page, do the changes as highlighted.

 

<apex:selectList id="dealerSelect" value="{!initStr}" size="1" disabled="true" rendered="{!DisplaySelectList}">
<apex:selectOptions value="{!dealers}" />
</apex:selectList>

Then you can changes the boolean value in DisplaySelectList variable at particular place.

 

DisplaySelectList = true;

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

chamil's blog

 

All Answers

aballardaballard

Change the rendered='false' to rendered='{!showList}' and add a boolean controller property  showList that determines whether the list is to be shown or not. 

 

 

Chamil MadusankaChamil Madusanka

Hi,

 

You need to define a boolean attribute in your controller class with default getter setter.

 

public class YourClassName{

    public Boolean DisplaySelectList{get;set;} 
//Your code here

}

 Then in VF page, do the changes as highlighted.

 

<apex:selectList id="dealerSelect" value="{!initStr}" size="1" disabled="true" rendered="{!DisplaySelectList}">
<apex:selectOptions value="{!dealers}" />
</apex:selectList>

Then you can changes the boolean value in DisplaySelectList variable at particular place.

 

DisplaySelectList = true;

 If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

chamil's blog

 

This was selected as the best answer
KidNikiKidNiki

Oh man, thank you both! :)