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
sf ostsf ost 

return strings in array in a specifed format

Hi all,
  • Create a class
  • Declare and populate array of string containing month names viz. January, February ….
  • Create a method to return a string in below format :
January > February > …
Show it on VF page.

I am output result as [January,February,March]. but here i need output result on vf page as January > February>March. How to achive this.

Apex Code:
public class months{
  String[] arrayItems;

   public PageReference myArrayItems()
    {
       arrayItems = new String[] {'January','February','March','April','May','June','July','August','September','November','December'};
       return null;
    }

    public String[] getitems()
     {
       return arrayItems ;
     }  
}

VF page:
<apex:page showHeader="false" controller="months">
<apex:form >
        
        <apex:outputText value="{!items}" id="mn"/> <br/>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

how to acheive this ?
Best Answer chosen by sf ost
Pankaj_GanwaniPankaj_Ganwani
I have tried below code in my dev org and it is working fine. You can use it as it is:
 
<apex:page showHeader="false" controller="months">
<apex:form >
      <apex:outputPanel id="mn">  
      <apex:repeat value="{!items}" var="item">
        <apex:outputText value="{!item}"/> 
        <span style="{!IF(item!='December','','display:none;')}">&gt;</span>
     </apex:repeat>
     </apex:outputPanel>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

 

All Answers

Pankaj_GanwaniPankaj_Ganwani
Hi,

Do following changes in your vf page:
 
<apex:page showHeader="false" controller="months">
<apex:form >
        
      <apex:repeat value="{!items}" var="item">
        <apex:outputText value="{!item}"/> 
        <apex:outputText value=">" rendered="item!='December'"/>
     </apex:repeat>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

 
sf ostsf ost
no output when button is cliked @Pankaj Ganwani
Pankaj_GanwaniPankaj_Ganwani
Wrap the code in output panel and rerender it on click of button.
sf ostsf ost
all strings are concatinated.. my code below
 
<apex:page showHeader="false" controller="months">
<apex:form >
      <apex:outputPanel id="mn">  
      <apex:repeat value="{!items}" var="item">
        <apex:outputText value="{!item}"/> 
        <apex:outputText value=">" rendered="items!='December'"/>
     </apex:repeat>
     </apex:outputPanel>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

 
sf ostsf ost
output is like this: JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberNovemberDecember
Pankaj_GanwaniPankaj_Ganwani
<apex:page showHeader="false" controller="months">
<apex:form >
      <apex:outputPanel id="mn">  
      <apex:repeat value="{!items}" var="item">
        <apex:outputText value="{!item}"/> 
        <apex:outputText value=">" rendered="item!='December'"/>
     </apex:repeat>
     </apex:outputPanel>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

Try with this.
sf ostsf ost
Output is same as previous: JanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberNovemberDecember
Pankaj_GanwaniPankaj_Ganwani
I have tried below code in my dev org and it is working fine. You can use it as it is:
 
<apex:page showHeader="false" controller="months">
<apex:form >
      <apex:outputPanel id="mn">  
      <apex:repeat value="{!items}" var="item">
        <apex:outputText value="{!item}"/> 
        <span style="{!IF(item!='December','','display:none;')}">&gt;</span>
     </apex:repeat>
     </apex:outputPanel>
        <apex:commandButton value="Click" action="{!myArrayItems}" rerender="mn"/>

</apex:form>
</apex:page>

 
This was selected as the best answer
sf ostsf ost
Thats great man.. it worked.. Thanks.
Pankaj_GanwaniPankaj_Ganwani
Please mark it as the best answer so that others can also refer it who got stuck in similar kind of issue.