function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
thecoldfusionthecoldfusion 

using multiple instances of same component

Hello,

I like the concept of using custom component to encapsulate generalized UI and being able to use in more than one visual force page with different sets of data.

However, I have a situation where I use apex components, within a custom component, with id attributes. This is creating a problem when multiple instances of the custom component is used in same visual force page.

Is this a serious limitation? Something like 'prependId' attribute, of an <apex:form> tag, could help - so that unique child client-ids could be generated for all tags/components inside a custom component and provide some mechanism to refer it in attributes like 'rerender', 'status' etc (just like using {!$Component} object in a javascript DOM to access HTML objects).

My situation:
The controller class IPIBAs guarantees different sets of data with different parameters. The controller used in the page has multiple references to instances of IPIBAs created with different parameters.


Component Code:
<apex:component>
  <apex:attribute required="true" name="ipIBAs" type="IPIBAs" description="" />
  <apex:outputPanel style="height:15px;" layout="block">
    <apex:actionStatus startText="loading..." stopText="" id="panelIPIBAsStatusLoading" />
    <apex:actionStatus startText="saving..." stopText="" id="panelIPIBAsStatusSaving" />
    <apex:actionStatus startText="cancelling..." stopText="" id="panelIPIBAsStatusCancelling" />
    <apex:actionStatus startText="deleting..." stopText="" id="panelIPIBAsStatusDeleting" />
  </apex:outputPanel>
  <apex:outputPanel id="panelIPIBAs" layout="block">
    <apex:form rendered="{!(ipIBAs.viewMode == 1)}">
      <apex:pageBlock title="Activities :: Listings">
        <apex:pageBlockButtons>
          <apex:commandButton value="Edit" rerender="panelIPIBAs" rendered="{!(ipIBAs.ipIBAsCount > 0)}" status="panelIPIBAsStatusLoading">
            <apex:param value="2" assignTo="{!ipIBAs.viewMode}" />
          </apex:commandButton>
        </apex:pageBlockButtons>
<!-- other fields here -->
</apex:pageBlock> </apex:form> <apex:form rendered="{!(ipIBAs.viewMode == 2)}"> <apex:pageBlock title="Activities :: Edit"> <apex:pageBlockButtons> <apex:commandButton value="Save" rerender="panelIPIBAs" action="{!ipIBAs.save}" status="panelIPIBAsStatusSaving" /> <apex:commandButton value="Cancel" rerender="panelIPIBAs" action="{!ipIBAs.cancel}" status="panelIPIBAsStatusCancelling" /> </apex:pageBlockButtons>
<!-- other fields here -->
</apex:pageBlock>
</apex:form>
<apex:form rendered="{!(ipIBAs.viewMode == 3)}">
<apex:pageBlock title="Activities :: New">
<apex:pageBlockButtons>
<apex:commandButton value="Save" rerender="panelIPIBAs" action="{!ipIBAs.saveNewRecord}" status="panelIPIBAsStatusSaving" />
<apex:commandButton value="Cancel" rerender="panelIPIBAs" action="{!ipIBAs.cancelNewRecord}" status="panelIPIBAsStatusCancelling" />
</apex:pageBlockButtons>
<!-- other fields here -->
</apex:pageBlock>
</apex:form>
<apex:form rendered="{!(ipIBAs.viewMode == 4)}">
<apex:pageBlock title="Activities :: Confirm Delete">
<apex:pageBlockButtons>
<apex:commandButton value="Yes" rerender="panelIPIBAs" action="{!ipIBAs.deleteSelected}" status="panelIPIBAsStatusDeleting" />
<apex:commandButton value="No" rerender="panelIPIBAs" action="{!ipIBAs.cancelDelete}" status="panelIPIBAsStatusCancelling" />
</apex:pageBlockButtons>
<!-- other fields here -->
</apex:pageBlock>
</apex:form>
</apex:outputPanel>
</apex:component>

 
Whenever I try to include two or more of this component, I get

Error: Duplicate ids have been detected: 'panelIPIBAsStatusLoading'

How could visualforce ensure unique 'clientid's would be generated for child components of a custom component?

Any suggessions?

Thanks,
TheColdFusion
jwetzlerjwetzler
You've hit on a bug that is very specific to actionStatus, in that it does not construct it's DOM id the same way our other components do, by prepending container ids to it.  You aren't doing anything wrong.

However that bug slipped to the bottom of the pile because we had not really seen a case yet where it couldn't be worked around.  I'll look into getting it fixed but can't promise a timeframe.  Any chance you can do without the actionStatus components for a bit?
thecoldfusionthecoldfusion
Jill, this is my second time encountering such problem. As with the first time, I had created of multiple custom components copied from the original one with different names and ensure unique ids in each of the components. This made me create 7/8 copies for the first one and 4/5 for second one. That was my band-aid solution and has been very difficult to manage.

I really hope this would be solved very soon. My clients like the status display during partial page updates and would like to retain the feature.

Thanks for the reply,
TheColdFusion.
Chris DChris D
Where is this list of bugs? I seem to be running into issues left and right only to find discussions about it in the forums. This does not leave a good taste in a developers mouth.
jeremyyjeremyy
I'm encountering this bug.  What's the workaround for an actionStatus inside a repeat?
TehNrdTehNrd

Looks like this is still an issue.

 

Is the workaround of choice to roll your own status funtionality with javascript onclick and oncomplete events?

 

-Jason

TehNrdTehNrd

I am a ratard. (Reference to the Hangover move, no disrecpt to individuals with learning disabilities ;-).

 

I was passing in an image URL to multiple components on a page for the status icon image but...... I wasn't passing in the url for some of them. Still might be an issue with components in repeat tags, not sure.

akschampakschamp

Hi,

 

There is a solution in below post of how to use multiple instances of component on VF page :

 

http://boards.developerforce.com/t5/Visualforce-Development/Using-same-Visualforce-components-twice/td-p/440877

 

please verify