2

I was working on a scenario where I had to apply JSENCODE for the Set iterated in apex:pageBlockTable. However it gives me error as incorrect argument for JSENCODE error. Hence i had to add the set into a string and then use the JSENCODE function which worked . I wish to know why it doesnt work with SET but works with List . What corrections should i make to get the below code working

 <apex:pageBlockTable value="{!resultsLst}" var="a" id="tblResults">                        
  <apex:column >
   <apex:facet name="header">
   <apex:outputPanel >Team Name</apex:outputPanel>
  </apex:facet>
  <a href="#" onclick = "setValuesFunction('{!JSENCODE(a)}');"> {!a} </a>  **HERE THE JSENCODE FUNCTION GIVES ERROR AS INCORRECT ARGUMENT**                                             
  </apex:column>
 </apex:pageBlockTable>

In controller

    public with sharing class XYZ{

    public  static Set<String> results{get;set;} 

    public XYZ() 
    {

    results = new Set<String>();
    }




 public static void runSearch() 
    {

        if(searchString != '' && searchString != null )
        {
            results = performSearch(searchString);

        }
    } 


     public static Set<String> performSearch(String searchString1) {

            Set<String> uniqueTeamNameSet = new Set<String>();
          // do something 

            return uniqueTeamNameSet; 
    }

}

PS:

WHEN PAGEBLOCK IS ITERATED OVER LIST I AM ABLE TO USE JSENCODE BT NOT WITH SET

1
  • I can suggest cast it to set, and then back to list
    – kurunve
    Jul 31 '17 at 10:48
5

When set comes to page it's iterated variable will be treated as object. JSENCODE Accepts only string parameter that is why it will not allow to save the code. WorkAround - First convert the value to string on page then use JSENCODE eg -

//I have the set here named Temp
<apex:repeat value="{!temp}" var="setValue">
    //Adding a space just before the iterated value and assigning to new variable. which now is converted to string
    <apex:variable value=" {!setValue}" var="TemporaryVariable"/>
    Printing out temporary variable
    {!JSENCODE(TemporaryVariable)}
</apex:repeat>
0

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.