1

I have a requirement in which I want to avoid involving extension class. The page shows list of account record present in org. I want to set page size for the list of accounts but I don't want to use extension class for this.
Here goes my code

<apex:page standardController="account" recordSetVar="accs" tabstyle="account" >      
<apex:form >
    <apex:param name="q" value="7" assignTo="{!PageSize}"/>
    <apex:pageBlock id="contacts_list">
        <apex:outputPanel style="float:right">
        Filter: 
        <apex:selectList value="{! filterId }" size="1">
            <apex:selectOptions value="{!listViewOptions}"/>
            <apex:actionSupport event="onchange" reRender="contacts_list"/>
        </apex:selectList><br /><br />
        </apex:outputPanel>

        <apex:pageBlockTable value="{!accs}" var="ac" >   
            <apex:column headerValue="name">
                <apex:inputField value="{!ac.name}" />  
            </apex:column>

            <apex:column headerValue="Account Number">
                <apex:inputField value="{!ac.AccountNumber}" />   
            </apex:column>

            <apex:column headerValue="account source">
                <apex:inputField value="{!ac.AccountSource}" />  
            </apex:column>

            <apex:column headerValue="Site">
                <apex:inputField value="{!ac.site}" />
            </apex:column>
        </apex:pageBlockTable>

        <!-- Pagination --><br />
        <table style="width: 100%"><tr> 
            <td>
                Page: <apex:outputText value=" {!IF(CEILING(ResultSize/PageSize)==0,0,PageNumber)} of {!CEILING(ResultSize/PageSize) }"/>               
            </td>            

            <td align="center">
                <apex:commandButton value="|<" action="{!first}" disabled="{!!hasPrevious}"  />         
                <apex:commandButton value="<<" action="{!previous}" disabled="{!!hasPrevious}" />   
                <apex:commandButton value=">>" action="{!next}" disabled="{!!hasNext}"/>            
                <apex:commandButton value=">|" action="{!last}" disabled="{!!hasNext}" />     
            </td>

            <td align="right">
                <apex:outputText value="Records per page :" rendered="{!CEILING(ResultSize/PageSize)!=0}" />
                <apex:selectList value="{! PageSize }" size="1" rendered="{!CEILING(ResultSize/PageSize)!=0}">
                    <apex:selectOption itemValue="5" itemLabel="5"/>
                    <apex:selectOption itemValue="20" itemLabel="20"/>
                    <apex:actionSupport event="onchange" reRender="contacts_list"/>
                </apex:selectList>
            </td>
            <td align="right">
                <apex:outputText value="No Records" rendered="{!CEILING(ResultSize/PageSize)==0}" /> 
            </td>           
        </tr></table>
        <apex:pageBlockButtons style="align:left;"> 
            <apex:commandButton value="save" action="{!save}" /> 
        </apex:pageBlockButtons>    
    </apex:pageBlock>
</apex:form>    

As you can see I have used <apex:param name="q" value="7" assignTo="{!PageSize}"/> but this is not serving my purpose. Please Help.Thanks in advance :)

3 Answers 3

1

You might want to make a note of this from the docs.

The <apex:param> component can only be a child of the following components: <apex:actionFunction> <apex:actionSupport> <apex:commandLink> <apex:outputLink> <apex:outputText>

I guess you are trying to default the pageSize to 7 without any button click.

Here is one approach wherein the contacts list is not visible on the page (style.display=hidden), on page load we set the page size to 7 via actionFunction and when that is complete (onComplete attribute of actionFunction is executed) we display the contacts_list pageBlock.

Wrap the <apex:param> with an actionFunction tag

  <apex:actionFunction  name="setPageSizeAsSeven" rerender="contacts_list" onComplete="onCompleteHandler()">
        <apex:param name="q" value="7" assignTo="{! PageSize }"/>
    </apex:actionFunction>

Wrap the contacts_list pageBlock tag with the following div

<div id="contactsListDiv" style="display:none;">

Invoke the actionFunction on pageLoad using javascript:

 <script> var previousOnload = window.onload; 
      window.onload = function() { if (previousOnload) { previousOnload(); }
     setPageSizeAsSeven(); } 
 function onCompleteHandler() { var contactsListDivElem = document.getElementById('contactsListDiv'); contactsListDivElem.style.display ='block'; }

This works but not sure if this is the best approach.

2
  • Hey thanks Rajiv! This logic works fine but the problem is the javascript function is called after the page block with id = "contacts_list" is already loaded. So what happen is at first sight I see all the records in one page then this javascript method is called and after this pageBlock is rerendered, which is not my desired flow ! Apr 28, 2015 at 14:10
  • in that case you can just hide the pageBlock with a div and then make it visible when the pageSize has been set. I have updated the answer with the requested details. Apr 28, 2015 at 14:39
0

I think there are a few missing pieces.

First, you need to create the PageSize variable on your page. It seems like you're trying to pass it as a URL param, so you could do:

<apex:variable name="PageSize" value="{!$CurrentPage.Parameters.q}"

Now you'll have a variable you can use that contains the value in the q parameter.

You then need to set the rows parameter in pageBlockTable according to this value:

<apex:pageBlockTable ... rows="{!PageSize}" />

This should then set the table to display the number of rows based on the PageSize variable.

I think from there the rest of the re-render stuff might work.

3
  • hmm -- OP is trying to set Standard SetController variable pageSize. You are defining a new apex:variable with the same name as the SSC merge field. Be interested to see if this works
    – cropredy
    Apr 28, 2015 at 2:24
  • In my code snippet I am reffering to standardSetController methods - getPageSize() and setPageSize(Integer). Writing {!pageSize} automatically calls getPageSize(). I want to call setPageSize without making use of any extension class. So your solution is not the one I am looking for ! Apr 28, 2015 at 11:17
  • Actually I want to keep this page as simple as possible. I dont want to pass page size as URL param. But certainly it can be a good workaround that I can check with. Thanks ! Apr 28, 2015 at 11:47
0

Have you explored using Visualforce's Enhancedlist componenet (https://www.salesforce.com/docs/developer/pages/Content/pages_compref_enhancedList.htm)

1
  • yea I am aware of enhanced list but this is not the solution I am looking for. As I dont want that much customized look that comes with usage of this tag ! Apr 28, 2015 at 11:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .