0

I have incident report. If the user types in 3, 3 rows appear to describe each incident.

enter image description here

The two columns to the write of the page, "Employee" and "Opportunity (Patient)". I want neither of the fields to display if the "Affected Population" value in the row is selected to "--None---",

Only the employee field to display if "Affected Population" value in the row is set to "Employee",

etc

Here is the visualforce code for those Affected Population and two columns on the right

<!--Infection Incidents Section -->         
<apex:pageBlockSection title="Infection Incidents : {!InfectionCount}" columns="1" id="infecIncidentsec" showHeader="false"> 

<apex:pageBlockTable style="width:100%" value="{!Infections}" var="item" rendered="{!Infections.size > 0}">  

 <apex:column style="width:11%;" headerValue="Date of Incident">  
     <apex:inputField value="{!item.DateOfIncident__c}" required="true"/> 
 </apex:column> 

 <apex:column style="width:11%;" headerValue="Affected Population">  
     <apex:inputField value="{!item.Affected_Population__c}" required="true" onchange="showFields(this)" styleClass="affecPopulateList">
         <apex:actionSupport event="onchange" rerender="colEmp, colOpp"/>
     </apex:inputField>
 </apex:column>

 <apex:column style="width:11%;" headerValue="Infected on Admission">
             <apex:OutputPanel layout="block" styleClass="requiredInput infecInItem patient" >
                 <span>
                     <apex:OutputPanel styleClass="requiredBlock"/>
                     <apex:inputField value="{!item.Infection_Present_on_Admission__c}" styleClass="infecInInputItem patientinfecInInputItem infecRequired"/>
                     <div class="errorMsg" style="display:none">
                         <strong></strong>
                         You must enter a value.
                     </div>
                 </span>
             </apex:OutputPanel> 
 </apex:column>


 <apex:column style="width:11%"  headerValue="Employee" id="colEmp">  
             <apex:OutputPanel layout="block" styleClass="requiredInput infecInItem employee" >
                 <span>
                     <apex:OutputPanel styleClass="requiredBlock" />
                     <apex:inputField style="width:80%"  value="{!item.Employee__c}" styleClass="infecInInputItem employeeinfecInInputItem infecRequired" rendered="{!item.Affected_Population__c == 'Employee' }"/>
                     <div class="errorMsg" style="display:none">
                         <strong></strong>
                         You must enter a value.
                     </div>
                 </span>
             </apex:OutputPanel>                               
 </apex:column>

 <apex:column style="width:56%;" headerValue="Opportunity (Patient)" id="colOpp">  
             <apex:OutputPanel layout="block" styleClass="requiredInput infecInItem patient" >
                 <span>
                     <apex:OutputPanel styleClass="requiredBlock"/>
                     <apex:inputField style="width:15%" value="{!item.Opportunity__c}" styleclass="infecInInputItem patientinfecInInputItem infecRequired" rendered="{!item.Affected_Population__c != '' }"/>
                     <div class="errorMsg" style="display:none">
                         <strong></strong>
                         You must enter a value.
                     </div> 
                 </span>
             </apex:OutputPanel>                               
 </apex:column>

I know there is a rendered property for the apex:column component, but my if statement doesn't appear to be working

rendered="{! If(item.Affected_Population__C == "Employee",true,false) }"
  • Probably would be a lot more straightforward if you move the row layout to a component. – Adrian Larson Aug 24 '16 at 23:07
  • Sorry I don't understand. Still new to VF, only worked on lightning stuff – Tyler Zika Aug 24 '16 at 23:11
  • You may be able to use the <apex:component> tag to make the logic more modular. Just a thought. – Adrian Larson Aug 24 '16 at 23:14
  • 2
    did you try to move the rendered to the outputpanel instead of the apex:column ? Also try {!item.Affected_Population__C == "Employee"} Way more simple! – Cloud Ninja Aug 24 '16 at 23:18
  • I tried using rendered in outputPanel. No luck – Tyler Zika Aug 24 '16 at 23:21
1

Your rendered args needs to be on the input fields. Also, you haven't shown us the onchange args in the 'Affected Population' field.

So I made some assumptions and wrote this (using Contact object, you can change to suit...)

<apex:page standardController="Contact" extensions="Test1" sidebar="true" showHeader="true">
    <apex:form >

    <apex:pageBlock >
        <apex:pageBlockSection columns="1" showHeader="false">

            <apex:pageBlockTable value="{!contacts}" var="o">

                <apex:column headerValue="Date of Incident">
                    <apex:inputField value="{!o.Date_of_Incident__c}" />
                </apex:column>

                <apex:column  headerValue="Affected Population" >
                    <apex:inputField value="{!o.Affected_Population__c}">
                        <apex:actionSupport event="onchange" rerender="colEmp,colOpp" />
                    </apex:inputField>
                </apex:column>

                <apex:column headerValue="Infected on Admission" >
                    <apex:inputField value="{!o.Infected_on_Admission__c}" />
                </apex:column>

                <apex:column headerValue="Employee" id="colEmp">
                    <apex:inputField value="{!o.Employee__c}" rendered="{!o.Affected_Population__c == 'Employee'}" />
                </apex:column>

                <apex:column headerValue="Opportunity (Patient)" id="colOpp">
                    <apex:inputField value="{!o.Opportunity_Patient__c}" rendered="{!o.Affected_Population__c != ''}" />
                </apex:column>

            </apex:pageBlockTable>
        </apex:pageBlockSection>
    </apex:pageBlock>

    </apex:form>
</apex:page>

Note how the Affected Population input field has the child tag 'actionSupport'. This is where we can define an onchange and rerender events.

When that picklist changes, VF will rerender (recalc and redisplay) the two columns Employee and Opportunity (Patient).

HTH.

| improve this answer | |
  • I appreciate you answer, but it doesn't appear to work for me. I'll keep tinkering and see if I'm doing something wrong – Tyler Zika Aug 25 '16 at 16:28
  • I updated my post with the Affected Population code, including your code recommendation – Tyler Zika Aug 25 '16 at 17:17
  • The fields are not displaying at all using your method. It appears the rerender isn't working on the apex:actionSupport – Tyler Zika Aug 25 '16 at 17:33
  • did you put an id arg in the two columns? The rerender args are references tag ids. <apex:column headerValue="Employee" id="colEmp"> <apex:column headerValue="Opportunity (Patient)" id="colOpp"> If it's not this, can you paste your VF page into a pastebin or something? Difficult to debug in snippets. I did test the above code I posted, so it does work :) – vorno Aug 26 '16 at 0:15
  • My code in my post is updated to with your solution. Still not working, but maybe you can see what I'm doing wrong. – Tyler Zika Aug 26 '16 at 15:38

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.