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
Supper_KentSupper_Kent 

How to show specific value of the element in the Arraylist in a Visualforce page?

Hi,

   First, i added some values to the List, and then I return the entire list to visualforce page, my problem is that i can not show specific value of element in the visualforce page but only can show all the elements together once. Anybody has this experience, welcome.

 

Best Answer chosen by Admin (Salesforce Developers) 
Cool_DevloperCool_Devloper

Kent,

Is the index (of list element), which you want to display always static or does it dynamically change?

In case, it has to change dynamically, you need to set a value in the controller itself, to the index which you want to display. Basically, you need to define a getter!

on the other hand, if the index value to be shown is fixed, then you can use an "<apex:variable>" component to make a count of the iterations within the <apex:repeat> and display the value inside it only if the count comes equal to your index value!

 

<apex:variable value="{!0}" var="temp"/>

<apex:repeat value="{!list}" var="val">

<apex:outputText value="{!val}" rendered="{!IF(temp==index,true,false)}"/>

<apex:variable var="temp" value="{!(temp)+1}"/>

</apex:repeat> 

 

Cool_D

All Answers

Cool_DevloperCool_Devloper

Well, not sure how you are rendering the list on your VF page:(

Basically, you need to iterate through your list to show each value seperately! See below-

 

<apex:repeat value="{!list}" var="val">

{!val}

</apex:repeat>

 

So, here each value will be shown seperately and you can set the style/display the way you want to!!

Cool_D

Supper_KentSupper_Kent
Thanks for your reply, and this really works well, but my request is to show any specified value of the element. For example, arraylist list= [1,2,3,4], then I only want to show the value '2' in visualforce page. can I specify it? just like use list[1], but i know this doesn't work in the page.
Cool_DevloperCool_Devloper

Kent,

Is the index (of list element), which you want to display always static or does it dynamically change?

In case, it has to change dynamically, you need to set a value in the controller itself, to the index which you want to display. Basically, you need to define a getter!

on the other hand, if the index value to be shown is fixed, then you can use an "<apex:variable>" component to make a count of the iterations within the <apex:repeat> and display the value inside it only if the count comes equal to your index value!

 

<apex:variable value="{!0}" var="temp"/>

<apex:repeat value="{!list}" var="val">

<apex:outputText value="{!val}" rendered="{!IF(temp==index,true,false)}"/>

<apex:variable var="temp" value="{!(temp)+1}"/>

</apex:repeat> 

 

Cool_D

This was selected as the best answer
Supper_KentSupper_Kent

Hi bro,

 

        This is a very smart way, thanks for your help. So, we can not use the index to get the value directly, can we? Anyway, this solved my problem.:smileyvery-happy:

David Roberts 4David Roberts 4
You can also use Output panel to render (or not) a whole section:
<apex:variable value="{!0}" var="temp"/>
        <apex:outputPanel rendered="{!IF(temp==index, true, false)}">
            <apex:repeat value="{!list}" var="repval">
                <apex:outputText value="{!repval"/><br/>
                <!-- other data -->
                <apex:variable var="temp" value="{!(temp)+1}"/>
            </apex:repeat> 
            
            <br/>
        </apex:outputPanel>