0

I am working on a Visualforce page that contains address fields for a client. Due to a change in requirements, I need to now create two mutually exclusive output panels and put the address in each of those panels.

Current code:

<div id="customerNameRow>
    <label class="col-3" id="customerNameLabel>Name</label>
    <div class="col-3" id="customerName>{!wrapper.customerName}</div>
</div>
<div id="customerAddressRow1>
    <label class="col-3" id="addressLine1Label>Address</label>
    <div class="col-3" id="addressLine1>{!wrapper.addressLine1}</div>
</div>
<div id="customerAddressRow2>
    <label class="col-3" id="addressLine2Label></label>
    <div class="col-3" id="addressLine2>{!wrapper.addressLine2}</div>
</div>
<div id="customerAddressRow3>
    <label class="col-3" id="addressLine3Label></label>
    <div class="col-3" id="addressLine3>{!wrapper.addressLine3}</div>
</div>

With the change in requirement, it is now possible that the first line of the address data will be the same as the name, so in that case we don't want to show the first line of the address. So here is my modified code:

<div id="customerNameRow>
    <label class="col-3" id="customerNameLabel>Name</label>
    <div class="col-3" id="customerName>{!wrapper.customerName}</div>
</div>
<apex:outputPanel rendered="{!wrapper2.mail1 != wrapper.customerName}">
    <div id="customerAddressWithNameRow1>
        <label class="col-3" id="addressWithNameLine1Label>Address</label>
        <div class="col-3" id="addressWithNameLine1>{!wrapper2.mail1}</div>
    </div>
    <div id="customerAddressWithNameRow2>
        <label class="col-3" id="addressWithNameLine2Label></label>
        <div class="col-3" id="addressWithNameLine2>{!wrapper2.mail2}</div>
    </div>
    <div id="customerAddressWithNameRow3>
        <label class="col-3" id="addressWithNameLine3Label></label>
        <div class="col-3" id="addressWithNameLine3>{!wrapper2.mail3}</div>
    </div>
</apex:outputPanel>
<apex:outputPanel rendered="{!wrapper2.mail1 == wrapper.customerName}">
    <div id="customerAddressWithoutNameRow1>
        <label class="col-3" id="addressWithoutNameLine1Label>Address</label>
        <div class="col-3" id="addressWithoutNameLine1>{!wrapper2.mail2}</div>
    </div>
    <div id="customerAddressWithoutNameRow2>
        <label class="col-3" id="addressWithoutNameLine2Label></label>
        <div class="col-3" id="addressWithoutNameLine2>{!wrapper2.mail3}</div>
    </div>
</apex:outputPanel>

As you can see, I changed the ids for all the fields. For example, instead of addressLine1 I now have addressWithNameLine1 and addressWithoutNameLine1 to distinguish what is basically the same field in both outputPanels.

I have been told that I should leave the ids as they were because changing them would break QA (not here to debate that issue). Under that argument, it would seem that the ids for the fields within the two output panels would have to be the same. For example, the id for address line 1 would be "addressLine1" in both panels.

So my question: if you have two output panels that are mutually exclusive of each other, can you use the same id for a field that is present in both output panels?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.