+ Start a Discussion
Jigar TrivediJigar Trivedi 

Variable value with get and set gets re-initialised when constructor is called

<apex:page id="pg" sidebar="false" showHeader="false" standardStylesheets="false" applyHtmlTag="false" 
    controller="MultipleSalarySlips" renderAs="{!if(isRender == true, "PDF", '')}">
    <html>
        <head>
        </head>
    <apex:form id="frm">
        <table style = "margin-left: 560px;border: 2px solid;padding: 19px;border-radius:5px;background-color:#f1d1bf;display:{!if(isRender == true, 'None','')}" id = "firstTable">
            <!--Table 1 code-->
        </table>
        

        <table style="width:100%;margin-top: 50px;border-collapse: collapse;page-break-after:always;">
                  <!--Table 2 code with repeate-->
        </table>
public with sharing class MultipleSalarySlips {
    public String selectedToMonth{get;set;}
    public String selectedFromMonth{get;set;}
    public String selectedToYear{get;set;}
    public String selectedFromYear{get;set;}
    public List<Monthly_Salary_Details__c> monthlySalaryDetails{get;set;}
    public List<WrpSalaryDetail> wrpSalaryDetails{get;set;}
    public Monthly_Salary_Details__c msd{get;set;}
    public Boolean isRender{get;set;}
    public static Integer iq = 1;
    
    public MultipleSalarySlips(){
        wrpSalaryDetails = new List<WrpSalaryDetail>();
        msd = new Monthly_Salary_Details__c();
        isRender = false;
    }


Hi,
I am facing very unusual and silly issue. I have a vf page with render as pdf based on a condition. The page contains two tables. I am hiding first table conditionally so that second table can generate with proper pdf format. Here is what should happen: On button click of first table a new tab should open and first table should be hidden and second table should be visible in pdf format. What happens is a new tab opens but first table does not get hidden as the condition (isRender remains false) remains true. Above is the code for more understanding.

 
Best Answer chosen by Jigar Trivedi
Jigar TrivediJigar Trivedi

This is how I did it. I used <apex:actionFunction> to call the method. This way it directly called the method.

VF Page
<apex:actionFunction id="downloadSlips" name="downloadSlips" action="{!downloadSlip}"/>
<apex:commandButton title="Download" value="Download" onclick="downloadFunc(); return false;"/>
<script>            
function downloadFunc() {
    downloadSlips();
}

 

All Answers

Nitin Wader 21Nitin Wader 21
Check with below small change  -
​ <table style = "margin-left: 560px;border: 2px solid;padding: 19px;border-radius:5px;background-color:#f1d1bf;display:{if(isRender == true, 'None','')}" id ="firstTable">

Removed "!" before If condition. Check and let me know.

Thanks,
Jigar TrivediJigar Trivedi
Hi Nitin. Thanks for replying. It still does not render as PDF. I think on new tab, constructor gets called and isRender is set to false again. 
Nitin Wader 21Nitin Wader 21
Yes right.. thats what I was having on mind.. why are using getter setter for isRender.. cant it be done inside or some static variable..
Jigar TrivediJigar Trivedi
I am using that variable in vf page to conditionally render tables as well as to render page as pdf or as normal. Am I missing something? Is there another way to do this?
FernandFernand
Hi there!
The problem is the 1st table is not hidden?

then change the display condition to display: {!if(isRender == true, '','None')}
<table style = "margin-left: 560px;border: 2px solid;padding: 19px;border-radius:5px;background-color:#f1d1bf;display:{!if(isRender == true, '','None')}" id = "firstTable">

 
Jigar TrivediJigar Trivedi
Hi! Thanks for the reply. That will hide the first table on page load only. I want to hide first table when isRender is set to true after clicking button on first table (on new tab). But what happens is after clicking on button of first table a new tab opens, constructor gets called and the variable is set to false again.
Jigar TrivediJigar Trivedi

This is how I did it. I used <apex:actionFunction> to call the method. This way it directly called the method.

VF Page
<apex:actionFunction id="downloadSlips" name="downloadSlips" action="{!downloadSlip}"/>
<apex:commandButton title="Download" value="Download" onclick="downloadFunc(); return false;"/>
<script>            
function downloadFunc() {
    downloadSlips();
}

 
This was selected as the best answer