3

Problem: When utilizing a pageBlockTable to create a calendar, I am unable to conditionally display components in certain locations.

Right now I'm using this set up to populate my calendar:

<apex:pageBlockTable value="{!calendar}" var="a" rules="all" cellpadding="75%">
                <apex:column >
                    <apex:facet name="header">SUNDAY<br/>(Morning)</apex:facet>
                    <apex:outputText value="{!a.Sunday[0].viewDate}"></apex:outputText>
                    <apex:inputCheckbox value="{!a.Sunday[0].isChecked}"></apex:inputCheckbox>
                </apex:column>
                <apex:column >
                    <apex:facet name="header"><br/>(Afternoon)</apex:facet>
                    <apex:outputText value="{!a.Sunday[1].viewDate}"></apex:outputText>
                    <apex:inputCheckbox value="{!a.Sunday[1].isChecked}"></apex:inputCheckbox>
                </apex:column>
</apex:pageBlockTable>

This works well, however it will place checkboxes in every single square, even those without actual dates. Example:

enter image description here

When I attempt to use a flag from the controller and use an apex:variable element paired with render=flag to say whether or not a box should appear, it will remove the checkbox for the entire column rather than just for one row. Like this:

<apex:pageBlockTable value="{!calendar}" var="a" rules="all" cellpadding="75%">
                <apex:column >
                    <apex:facet name="header">SUNDAY<br/>(Morning)</apex:facet>
                    <apex:outputText value="{!a.Sunday[0].viewDate}"></apex:outputText>
                    <apex:variable value="{!foo}" var="bar" rendered="{!a.Sunday[0].displayBox}" >
                        <apex:inputCheckbox value="{!a.Sunday[0].isChecked}"></apex:inputCheckbox>
                    <apex:variable>
                </apex:column>
                <apex:column >
                    <apex:facet name="header"><br/>(Afternoon)</apex:facet>
                    <apex:outputText value="{!a.Sunday[1].viewDate}"></apex:outputText>
                    <apex:variable value="{!foo}" var="bar" rendered="{!a.Sunday[1].displayBox}" >
                        <apex:inputCheckbox value="{!a.Sunday[1].isChecked}"></apex:inputCheckbox>
                    </apex:variable>
                </apex:column>
<apex:pageBlockTable>

enter image description here

How else can I approach this problem? Thanks

4
  • You can try rendered attribute of the checkbox itself like <apex:inputCheckbox rendered="{!Expression}". – Saroj Bera Sep 15 '15 at 17:05
  • What does the code look like which isn't working correctly? Can you edit your question and add that detail? (boolean in the controller and apex:variable element in the table, etc.) Without that detail it is hard to know how to correct the issue. – Mark Pond Sep 15 '15 at 17:12
  • I've edited the question, thanks for pointing that out. – lisolm Sep 15 '15 at 17:33
  • Also, thanks @SarojBera! Your answer is correct, too – lisolm Sep 15 '15 at 18:32
2

It doesn't appear that you need the <apex:variable tag in your use case and you should be able to put the rendered boolean directly on the inputCheckbox.

<apex:pageBlockTable value="{!calendar}" var="a" rules="all" cellpadding="75%">
                <apex:column >
                    <apex:facet name="header">SUNDAY<br/>(Morning)</apex:facet>
                    <apex:outputText value="{!a.Sunday[0].viewDate}"></apex:outputText>
                    <apex:inputCheckbox value="{!a.Sunday[0].isChecked}" rendered="{!a.Sunday[0].displayBox}"></apex:inputCheckbox>
                </apex:column>
                <apex:column>
                    <apex:facet name="header"><br/>(Afternoon)</apex:facet>
                    <apex:outputText value="{!a.Sunday[1].viewDate}"></apex:outputText>
                    <apex:inputCheckbox value="{!a.Sunday[1].isChecked}" rendered="{!a.Sunday[1].displayBox}"></apex:inputCheckbox>
                </apex:column>
<apex:pageBlockTable>

If that markup causes strange layout issues because of a missing element, you might consider wrapping the checkbox in a <span> by using a span tag or an <apex:outputPanel> so that when the checkbox isn't rendered, there is still a sibling element next to the text with the day number.

<apex:column >
    <apex:facet name="header">SUNDAY<br/>(Morning)</apex:facet>
    <apex:outputText value="{!a.Sunday[0].viewDate}"></apex:outputText>
    <apex:outputPanel>
        <apex:inputCheckbox value="{!a.Sunday[0].isChecked}" rendered="{!a.Sunday[0].displayBox}"></apex:inputCheckbox>
    </apex:outputPanel>
</apex:column>
0

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.