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
Helen Y.Helen Y. 

VF: How to render different outputlabel name in a repeat tage?

Hi,

I got lost here, so my work is to give several labels each a differernt name.

Till now, all upload attachment buttons with one name "Upload Vehicle Photo" in front:
<apex:repeat value="{!newAttachments}" var="att"  >
                   <apex:pageBlockSectionItem >
                   <apex:outputLabel value="Upload Vehicle Photo"/>
                   <apex:inputfile value="{!att.body}" filename="{!att.Name}" />
                   </apex:pageBlockSectionItem>
                   <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
                       <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
                   </apex:commandlink>
                </apex:repeat>

But now I need to revise the name from "Upload Vehicle Photo"  to:
-- "Upload Vehicle Photo" for first row;
-- "Upload Old Photo" for second row;
-- "Upload New Photo" for third row.
It looks like have to revise the passing value from my controller to the page, but cannot figure it out.

Any help will be appreciated!Sample
ClintLeeClintLee
You could use an apex:variable as an index and change the wording of the label accordingly.  

Like this:
 
<apex:variable value="1" var="index"/> <!-- initialize the variable to 1 -->

<apex:repeat value="{!newAttachments}" var="att"  >
    <apex:pageBlockSectionItem >

        <!-- change the second word of the label depending on the variable -->
        <apex:outputLabel value="Upload {!IF(VALUE(index) = 1, "Vehicle", IF(VALUE(index) = 2, "Old", IF(VALUE(index) = 3, "New")))} Photo" />

        <apex:inputfile value="{!att.body}" filename="{!att.Name}" />
    </apex:pageBlockSectionItem>

    <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
        <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
    </apex:commandlink>

    <apex:variable var="index" value="{!VALUE(index) + 1}"/>  <!-- increment the variable by 1 -->

</apex:repeat>

Hope that helps,

Clint
Helen Y.Helen Y.
Thank you, Clint. Tried your reply but got this error:
[Error] Error: Incorrect number of parameters for function 'IF()'. Expected 3, received 2
Helen Y.Helen Y.
@billyclint, never mind, found out the third para. We are close, but still now the buttons are not aligning well, attached result. Could you share some insights? User-added image
ClintLeeClintLee
Can you post your updated VF page code?
Helen Y.Helen Y.
Sure, have done some more changes, code:
<apex:pageBlock title="Upload Images" >
            <apex:pageBlockSection >
            <apex:variable value="0" var="index"/> <!-- initialize the variable to 1 -->
                <apex:repeat value="{!newAttachments}" var="att"  >
                   <apex:pageBlockSectionItem > 
                    <apex:outputLabel for="activationCounter" value="Upload {!IF(VALUE(index) = 0, "Vehicle",  IF(VALUE(index) = 1, "Old", IF(VALUE(index) = 2, "New",(IF(VALUE(index) = 3, "One", (IF(VALUE(index) = 4, "TWO", "Three")))))))} Photo" />
                   <apex:outputPanel >
                   <!-- change the second word of the label depending on the variable -->
                   <apex:inputfile value="{!att.body}" filename="{!att.Name}" id="activationCounter" /> 
                   <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
                       <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
                   </apex:commandlink>
                   </apex:outputPanel>
              </apex:pageBlockSectionItem>
                   <apex:variable var="index" value="{!VALUE(index) + 1}"/>  <!-- increment the variable by 1 -->
                </apex:repeat>

hmm, i need more spaces between two buttons Choose File and Upload, any suggestion?
ClintLeeClintLee
It looks like your original question of wanting to get the labels changed is working now.  That's good.

As for the changes you've made to the VF page, apex:pageBlockSectionItems work best when there are only 2 elements in them.  Your apex:outputPanel is just placing a <span> tag around its contents. 

Try using an apex:panelGrid like this.
 
<apex:variable value="0" var="index"/> <!-- initialize the variable to 1 -->
<apex:repeat value="{!newAttachments}" var="att"  >
    <apex:pageBlockSectionItem > 
        <!-- change the second word of the label depending on the variable -->
        <apex:outputLabel for="activationCounter" value="Upload {!IF(VALUE(index) = 0, "Vehicle",  IF(VALUE(index) = 1, "Old", IF(VALUE(index) = 2, "New",(IF(VALUE(index) = 3, "One", (IF(VALUE(index) = 4, "TWO", "Three")))))))} Photo" />
        <apex:panelGrid columns="2">
            <apex:inputfile value="{!att.body}" filename="{!att.Name}" id="activationCounter" /> 
            <apex:commandlink value="Upload" action="{!insertatt}" styleClass="btn" style="padding:1px 10px 2px 5px; text-decoration:none;">
                <apex:param name="attNameAdd" value="{!att.id}" assignTo="{!attNameAdd}"/>
            </apex:commandlink>
        </apex:panelGrid>
    </apex:pageBlockSectionItem>
    <apex:variable var="index" value="{!VALUE(index) + 1}"/>  <!-- increment the variable by 1 -->
</apex:repeat>

 
Helen Y.Helen Y.
The label is looking good, thanks Clint. Tried your new solution but has no change. What do you think the possible?