0

Currently, I'm using apex:inputCheckbox and feeding it a boolean value from the controller with a dedicated variable since the Value attribute in the apex:inputCheckbox cannot have a formula expression.

Example:

<tr>
    <td> Info </td>
    <td> <apex:inputCheckbox value="{!isCurrent}" disabled="true" /> {!current.Name} </td>
    <td> <apex:inputCheckbox value="{!isPrevious}" disabled="true" /> {!Prev.Name} </td>
</tr>

The problem with the above approach is, I have around 30 checkboxes and I need to have a dedicated variable for each in the controller.

What I'd like to do is, to calculate true or false within Visualforce using formula expressions.

<tr>
    <td> Info </td>
    <td> <span class="checkbox"> {! NOT(ISNULL(current.Text__c))} </span> {!current.Text__c} </td>
    <td> <span class="checkbox"> {! ISNULL(current.Text__c)} </span> {!Prev.Text__c} </td>
</tr>

Is it possible to output a checkbox without using the <apex:inputCheckbox> component in Visualforce?

1

You can do this with a normal "input", but it's pretty painful. Here's what it would look like:

<apex:outputText rendered="{!NOT(ISNULL(current.Text__c))}">
  <input type="checkbox" checked="checked" disabled="disabled" />
</apex:outputText>
<apex:outputText rendered="{!ISNULL(current.Text__c)}">
  <input type="checkbox" disabled="disabled" />
</apex:outputText>

You might want to just consider writing a VF component so you can consolidate the logic:

<c:outputCheckbox checked="{!NOT(ISNULL(current.Text__c))}" />

The component would look something like this:

<apex:component >
    <apex:attribute name="checked" type="Boolean" default="false" description="checked state" />
    <apex:outputText rendered="{!checked}">
        <input type="checkbox" checked="checked" disabled="disabled" />
    </apex:outputText>
    <apex:outputText rendered="{!not(checked)}">
        <input type="checkbox" disabled="disabled" />
    </apex:outputText>
</apex:component>
  • I considered this approach. But hoping for a simple solution. The task sounds ridiculously simple. But implementation is very complex. I'll wait for some time if anybody has a better solution and mark this as answer if not. – Avinash Feb 13 '18 at 17:34
  • I did end up going this route. – Avinash Feb 13 '18 at 19:00

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.