0

I designing a VisualForce PDF page and I am using a controller extension. The generation of the page happens by clicking on an action associated to an Object to show it's different fields' values.

I want to know if it's possible to check the value of some fields before rendering the PDF itself using the extension (is there a lifecycle method to override ? ) or by using a custom controller.

I want to show an error window if there is an issue.

visualfore page

Thanks

1 Answer 1

1

There are a few options. You can use the constructor:

public CoordonneesBancairesMandantExtension(ApexPages.StandardController controller) {
  // Check data here //
}

Or as an action:

public PageReference validateData() {
   // Check data here //
}

Which is added as a page action:

<apex:page action="{!validateData}" ...

This example includes a redirect to an error page, etc, by returning a PageReference.

You can also conditionally render as PDF, or not, using the renderAs attribute:

<apex:page renderAs="{!renderMode}" ...

Where the Apex has a method or variable for this, such as:

public String getRenderMode() {
  if(validated()) {
    return 'pdf';
  } else {
    return ''; // Default rendering mode, HTML
  }
}

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.