Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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).

share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

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>
share|improve this answer
add comment

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>
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.