3

Is it possible to add a CSS class to one of the Visualforce page objects from controller? What I want to achieve is to handle one exception in controller. From catch block I want to be able to hide a form (add a CSS class to form with display:hidden).

4

Create a variable in your controller,

public boolean isVisible{gt;set;}

assign it true/false depending on condition(exception in your case)

surround form you want to show by an output panel

<apex:outputPanel rendered="{!isVisible}">
<apex:form>
.
.
.
.
</apex:form>
</apex:outputPanel>
3

You can assign a class name to the variable and then dynamically assign a new value:

Apex Class:

public with sharing class MyController{

    public String myCSSClass {get; set;}

    public MyController(){
        myCSSClass = 'visible';
    }

    public PageReference myMethod{
        try{
            ...
        }
        catch{
            myCSSClass = 'hidden';
        }

            return null;
    }
}

Visualforce page: after user clicks on the "Check" button a method "myMethod" called. If it fails the variable gets a "hidden" class.

<style>
.visible{
    display:block;
}
.hidden{
    display:none;
}
</style>

<apex:commandButton action="{!myMethod}" value="Check" reRender="myPanel">

<apex:outputPanel id="myPanel" styleClass="{!myCSSClass}">
...
</apex:outputPanel>

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.