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
Sascha DeinertSascha Deinert 

Rendered doesn't work

Hi,

If I try to rendered the code below it doesn't work.
If I show me size of the list I will get the value 1, but nothing is happen.
Where is the mistake?

I tried it also with != NULL .isempty etc., the same problem.
<div id="accDetailL">

<apex:pageblock title="Unternehmen Detail" id="pbAccDL">
    <apex:pageblocktable value="{!AccDList2}" var="AccD" rendered="{!IF(AccDList2.size != 0, true, false)">
        <apex:column style="font-size:16pt; font-weight: bold" headerValue="" value="{!AccD.Name}"/>
    </apex:pageblocktable>
    <apex:pageblocktable value="{!AccDList2}" var="AccD" columnswidth="50%, 25%, 25%">
        <apex:column value="{!AccD.BillingStreet}"/>
        <apex:column value="{!AccD.BillingPostalCode}"/>        
        <apex:column value="{!AccD.BillingCity}"/>     
    </apex:pageblocktable>  
</apex:pageblock>

Thanks,
Sascha
Best Answer chosen by Sascha Deinert
Arthur ImirzianArthur Imirzian
Hi Sascha, you can try to rerender an outputPanel instead of rerendering the pageBlock :
 
<apex:outputPanel id="pbAcc">
    <apex:pageblock title="Accounts" rendered="{! AccList2.size>0 }">
        // your code here
    </apex:pageBlock>
</apex:outputPanel>


 

All Answers

Arunkumar RArunkumar R
Hi Sascha,

Just try the below code,
 
<div id="accDetailL">

<apex:pageblock title="Unternehmen Detail" id="pbAccDL">
    <apex:pageblocktable value="{!AccDList2}" var="AccD" rendered="{!AccDList2.size>0}">
        <apex:column style="font-size:16pt; font-weight: bold" headerValue="" value="{!AccD.Name}"/>
    </apex:pageblocktable>
    <apex:pageblocktable value="{!AccDList2}" var="AccD" columnswidth="50%, 25%, 25%">
        <apex:column value="{!AccD.BillingStreet}"/>
        <apex:column value="{!AccD.BillingPostalCode}"/>        
        <apex:column value="{!AccD.BillingCity}"/>     
    </apex:pageblocktable>  
</apex:pageblock>
Dilip Singhd62Dilip Singhd62
Hi Sascha,

Is rendering needs to happen on page load ?

Thanks,
Singh
Sascha DeinertSascha Deinert
@Arunkumar,
doesn't work.

@Dilip,
Ok, but how can I do that? 
I add the line RETURN ApexPage.CurrentPage, but the block is not rerendered.
Public List <Account> getAccDList2() {
    List <Account> AccD =  [SELECT Id, Name, RecordTypeId, Status__c, Kunde_seit__c, Billingstreet, BillingPostalCode, BillingCity FROM Account WHERE Id = :SelectedAccountId];
    RETURN AccD;
} 

Public pageReference getAccDList() {
  getAccDList2(); 
  //RETURN NULL; 
  RETURN ApexPages.CurrentPage(); 
}


But I don't know why it not works, because I have in the same page the code below in it works fine.
Just one is different, I can use NULL this is with the code above not possible.
<div id="accList">

<apex:pageblock title="Accounts" id="pbAcc" rendered="{!IF(AccList2.size != NULL,true,false)}">
    <apex:pageblockButtons location="top">
        <apex:commandButton value="Seite 1" rerender="pbAcc" action="{!FirstPage}" disabled="{!prev}"/>
        <apex:commandButton value="vorherige Seite" rerender="pbAcc" action="{!previous}" disabled="{!prev}"/>
        <apex:commandButton value="nächste Seite" rerender="pbAcc" action="{!next}" disabled="{!nxt}"/>
        <apex:commandButton value="Letzte Seite" rerender="pbAcc" action="{!LastPage}" disabled="{!nxt}"/>
    </apex:pageblockButtons>
        <apex:pageblocktable value="{!AccList2}" var="Acc" columnswidth="5%, 70%, 15%, 10%>
            <apex:column headervalue="LINK">
                <apex:outputLink target="_blank" value="/{!Acc.Id}">Details</apex:outputLink>
            </apex:column>
            <apex:column headervalue="Accountname">
                <apex:outputField value="{!Acc.Name}" />
                <apex:actionSupport event="onclick" action="{!getOppList}" rerender="pbOpp, pbAccDL, pbAccDR, pbOppD">
                    <apex:param assignTo="{!SelectedAccountId}" value="{!Acc.Id}" name="SelectedAccountId"/>
                </apex:actionSupport>
            </apex:column>
            <apex:column headervalue="City">
                <apex:outputField value="{!Acc.BillingCity}"/>
            </apex:column>             
            <apex:column headervalue="Employees">          
                <apex:outputField value="{!Acc.NumberOfEmployees}"/>
            </apex:column>                     
        </apex:pageblocktable>   
</apex:pageBlock>


Thanks,
Sascha
Dilip Singhd62Dilip Singhd62
Hi Sascha,

There is no need of the two methods, try something like this:

 <apex:pageBlock >
        <apex:pageBlockTable value="{!acclist}" var="acc" rendered="{!acclist.size != 0}">
            <apex:column value="{!acc.Name}"/>

        </apex:pageBlockTable>
    </apex:pageBlock>

public List<Account> acclist {get; set;}
    public vfRenderedExtension(ApexPages.StandardController controller) {
         acclist = [Select Id, Name from Account Limit 1];       
    }

There is no need of IF condition in the Rendered attribute and also no need of pageRef as well. just make sure the list is declared as property.
Sascha DeinertSascha Deinert
@Dilip,

If I add the code to my controller I get the error 

Invalid constructor name: vfRenderedExtension

All my classes and methods are in a customcontroller.
 
Dilip Singhd62Dilip Singhd62
@Sascha,
vfRenderedExtension is constructor in my class.

You modify that according to your class name 
Sascha DeinertSascha Deinert
I think the page must be reloaded if I select an Account. How can I quickly reload/refresh the page If I select an Account
<apex:pageblock title="Accounts" id="pbAcc" rendered="{!IF(AccList2.size != NULL,true,false)}">
    <apex:pageblockButtons location="top">
        <apex:commandButton value="Seite 1" rerender="pbAcc" action="{!FirstPage}" disabled="{!prev}"/>
        <apex:commandButton value="vorherige Seite" rerender="pbAcc" action="{!previous}" disabled="{!prev}"/>
        <apex:commandButton value="nächste Seite" rerender="pbAcc" action="{!next}" disabled="{!nxt}"/>
        <apex:commandButton value="Letzte Seite" rerender="pbAcc" action="{!LastPage}" disabled="{!nxt}"/>
    </apex:pageblockButtons>
        <apex:pageblocktable value="{!AccList2}" var="Acc" columnswidth="5%, 70%, 15%, 10%>
            <apex:column headervalue="LINK">
                <apex:outputLink target="_blank" value="/{!Acc.Id}">Details</apex:outputLink>
            </apex:column>
            <apex:column headervalue="Accountname">
                <apex:outputField value="{!Acc.Name}" />
                <apex:actionSupport event="onclick" action="{!getOppList}" rerender="pbOpp, pbAccDL, pbAccDR, pbOppD">
                    <apex:param assignTo="{!SelectedAccountId}" value="{!Acc.Id}" name="SelectedAccountId"/>
                </apex:actionSupport>
            </apex:column>
            <apex:column headervalue="City">
                <apex:outputField value="{!Acc.BillingCity}"/>
            </apex:column>             
            <apex:column headervalue="Employees">          
                <apex:outputField value="{!Acc.NumberOfEmployees}"/>
            </apex:column>                     
        </apex:pageblocktable>   
</apex:pageBlock>

 
Sascha DeinertSascha Deinert
Please help, any ideas?
Rerender doesn't work, but the size of the list is 1, but nothing is happen. 
Arthur ImirzianArthur Imirzian
Hi Sascha, you can try to rerender an outputPanel instead of rerendering the pageBlock :
 
<apex:outputPanel id="pbAcc">
    <apex:pageblock title="Accounts" rendered="{! AccList2.size>0 }">
        // your code here
    </apex:pageBlock>
</apex:outputPanel>


 
This was selected as the best answer