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
Naveed AnwarNaveed Anwar 

Rerendering problem

Hi,

 

I have modified the code from the site : http://blog.jeffdouglas.com/2009/07/14/visualforce-page-with-pagination/comment-page-1/#comment-930


I have one issue that i cannot able to solve. It is not rerendering. When i remove the following piece of code from visualforce page, it works fine


-----------------------------------------------------------------------------
 <apex:pageBlockSection columns="1">



<apex:pageblockSectionItem >


<apex:outputText value="Account" />
<apex:inputField value="{!account.ParentID}" id="LookupAccount" required="true" />

</apex:pageblockSectionItem>

</apex:pageBlockSection>
----------------------------------------------------------------------------

Full Visual force code:

<apex:page controller="PagingController">
<apex:form >
<apex:pageBlock>

<apex:pageBlockSection columns="1">

<apex:pageblockSectionItem >

<apex:outputText value="Account" />
<apex:inputField value="{!account.ParentID}" id="LookupAccount" required="true" />

</apex:pageblockSectionItem>

</apex:pageBlockSection>

<apex:pageBlockButtons location="top">
</apex:pageBlockButtons>
<apex:pageMessages />

<apex:pageBlockSection title="Account Results - Page #{!pageNumber}" columns="1" id="pageblock">

<apex:pageBlockTable value="{!accounts}" var="c">
<apex:column value="{!c.Name}" headerValue="Name"/>
</apex:pageBlockTable>
</apex:pageBlockSection>

</apex:pageBlock>

<apex:panelGrid columns="4">
<apex:commandLink action="{!first}" rerender="pageblock">First</apex:commandlink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}" rerender="pageblock">Previous</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="pageblock">Next</apex:commandlink>
<apex:commandLink action="{!last}" rerender="pageblock">Last</apex:commandlink>
</apex:panelGrid>

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

Controller Code:

public with sharing class PagingController {

public Account getAccount()
{
return [Select a.ParentID From Account a Limit 1];
}

// instantiate the StandardSetController from a query locator
public ApexPages.StandardSetController con {
get {
if(con == null) {
con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Name FROM Account Order By Name limit 100]));
// sets the number of records in each page set
con.setPageSize(5);
}
return con;
}
set;
}

// returns a list of wrapper objects for the sObjects in the current page set
public List<Account> getAccounts() {
return (List<Account>)con.getRecords();
}

// indicates whether there are more records after the current page set.
public Boolean hasNext {
get {
return con.getHasNext();
}
set;
}

// indicates whether there are more records before the current page set.
public Boolean hasPrevious {
get {
return con.getHasPrevious();
}
set;
}

// returns the page number of the current page set
public Integer pageNumber {
get {
return con.getPageNumber();
}
set;
}

// returns the first page of records
public void first() {
con.first();
}

// returns the last page of records
public void last() {
con.last();
}

// returns the previous page of records
public void previous() {
con.previous();
}

// returns the next page of records
public void next() {
con.next();
}


}


Can anyone help me?

Best Answer chosen by Admin (Salesforce Developers) 
SargeSarge

Hi Naveed,

 

      Since you have placed a Lookup field that is required, the controller actions are not executed unless the lookup field has a valid value.

    Hence either you have to make the lookup conditionally required or you have to set the "immediate" attribute to "true" for every component that calls an controller method

e.g.

change <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="pageblock">Next</apex:commandlink>

to

<apex:commandLink action="{!next}"  immediate ="true" rendered="{!hasNext}" rerender="pageblock">Next</apex:commandlink>

This way, the controller bypasses the setter methods and hence the requiredness of lookup field is avoided.

Cheers..

All Answers

SargeSarge

Hi Naveed,

 

      Since you have placed a Lookup field that is required, the controller actions are not executed unless the lookup field has a valid value.

    Hence either you have to make the lookup conditionally required or you have to set the "immediate" attribute to "true" for every component that calls an controller method

e.g.

change <apex:commandLink action="{!next}" rendered="{!hasNext}" rerender="pageblock">Next</apex:commandlink>

to

<apex:commandLink action="{!next}"  immediate ="true" rendered="{!hasNext}" rerender="pageblock">Next</apex:commandlink>

This way, the controller bypasses the setter methods and hence the requiredness of lookup field is avoided.

Cheers..

This was selected as the best answer
Naveed AnwarNaveed Anwar

Hi Sarge,