1

I have created a visualforce page which lists records from my News custom object, I have designed it to take URL parameters to filter by category if nessessary. The problem I am having is that when pressing any of the pagination buttons, it will say loading but not refresh the page or items with the correct items, it will simply say 'loading' for a second and then nothing happens.

Page:

<apex:page showheader="false" controller="NewsController" title="News Archive" >
<apex:composition template="{!$Site.Template}">
<apex:define name="body">  

<h2>News</h2>

<apex:form id="pgBlock">
        <apex:repeat value="{!newsitems}" var="article" id="theRepeat">

        <h4>
            <strong>
                <apex:outputLink styleClass="article-header block" value="/News?id={!article.id}">{!article.Title__c}</apex:outputLink>
            </strong>
        </h4>

        <div class="row">
            <div class="col-md-10 col-xs-12">
                <apex:outputText styleClass="text-excerpt" value="{!left(article.Content__c,500)}" />

                <div class="text-right">
                    <a href="/News?id={!article.id}" class="btn btn-default btn-sm pull-right"><span class="glyphicon glyphicon-eye-open"></span> Read More</a>
                </div>

            </div>
        </div>
        <br />
        <div class="row">
            <div class="col-xs-12">
                <apex:outputText styleClass="text-muted" value="Published: {0,date,dd'/'MM'/'yyyy}">
                <apex:param value="{!article.Publish_Date__c}" /> 
                </apex:outputText>
            </div>
            <div class="col-xs-12 margin-tp">
                <apex:outputText value="{!article.Category__c}" styleClass="label label-default" />
            </div>
        </div>

        <hr/>
        </apex:repeat>

        <apex:commandButton value="Newer" action="{!Previous}" rerender="pgTable,pgBlock"
                            status="status" disabled="{!DisablePrevious}" />
        <apex:commandButton value="Older" action="{!Next}" reRender="pgTable,pgBlock"
                            status="status" disabled="{!DisableNext}" />
        <apex:actionStatus id="status" startText="loading..."/>
        </apex:form>

    </div>

</div>

</apex:define>
</apex:composition>
</apex:page>

Controller:

public with sharing class NewsController {

    public NewsController (){
        CountTotalRecords= [SELECT COUNT() FROM News__c];
    }

    public Integer CountTotalRecords{get;set;}
    public String QueryString {get;set;}
    public Integer OffsetSize = 0;
    private Integer QueryLimit = 2;
    public string excerpt;
    public list<News__c> lstItem {get;set;}
    public map<id,string> newsmap{get;set;}


    public list<News__c> getNewsItems(){
        lstItem = new list<News__c>();

        String category = Apexpages.currentPage().getParameters().get('cat');
        String query = 'SELECT Id, Name, Title__C, Content__c, Publish_Date__c, Category__c,  ';
        query += '(Select Id, Name, LastModifiedDate From Attachments Order By LastModifiedDate DESC) ';
        query += 'FROM News__c ';

        if (category != null)
        {
            query += 'WHERE Category__c = :category ';
        }

        query += 'ORDER BY Publish_Date__c DESC, Name DESC LIMIT :QueryLimit OFFSET :OffsetSize';

        lstItem = Database.query(query);
        return lstItem;
    }

    public Boolean getDisablePrevious(){
        if(OffsetSize>0){
            return false;
        }
        else return true;
    }

    public Boolean getDisableNext() {
        if (OffsetSize + QueryLimit < countTotalRecords){
            return false;
        }
        else return true;
    }

    public PageReference Next() {
        OffsetSize += QueryLimit;
        return null;
    }

    public PageReference Previous() {
        OffsetSize -= QueryLimit;
        return null;
    }
}
  • 2
    The rerender ID values pgTable,pgBlock don't appear to be present in the page. Add one of them to e.g. the ` apex:form` . – Keith C Oct 13 '14 at 14:20
  • Ok that has done something... but now when pressing 'Older', the age returns to a "Error occured while loading a Visualforce page". – Deployment Failure Oct 13 '14 at 14:44
  • I don't see anything obviously wrong. Easiest way to get more error detail is to check "Development Mode" on the User you are testing under. – Keith C Oct 13 '14 at 15:03
  • @KeithC This is a public page which requires no login, can I still use Development Mode? – Deployment Failure Oct 13 '14 at 15:04
  • 1
    Perhaps not. You can go to Setup -> Logs -> Debug Logs and add a new "Monitored User" for the site guest user. You can find that user's name using Setup -> Sites then select your Site then click the "Public Access Settings" button then click the "Assigned Users" button. – Keith C Oct 13 '14 at 15:08
0

The rerender ID values pgTable,pgBlock don't appear to be present in the page. Add one of them to e.g. the apex:form.

|improve this answer|||||

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.