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
anjuanju 

Create more than one objects in a custom component.

Hi,

 

I am new in Visualforce. So I don’t know whether my question is valid or not.

 

Is it is possible to use more than one objects in a custom component?  

My requirement is I would like to create a custom component with more than one objects like this -  

For e.g.  

 

custom component- myCmp 

<apex:component >


<apex:attribute name="otxt" id="otxt" type="String" description="This is common section template"/>
<apex:outputText value="{!otxt}" />  

 

<apex:attribute name="itxt" id="itxt" type="String" description="This is common section template"/>
<apex:inputText value="{!itxt}" />
   

 

 </apex:component> 

 

 VF Page

In first VF page (VFPage_1) I need to display Output text and In second VF page (VFPage_2) I need to display input text from the component.

I tried the following way but it is not working. Both the pages are displaying both the objects.

 

VFPage_1

<apex:page>

<c:myCmp otxt=“Test Output Text” />

</apex:page>

 

VFPage_2

<apex:page>

<c:myCmp itxt=“” />

</apex:page>

 

 

Could anybody help me solve this issue.

 

JimRaeJimRae

Why not use the rendered attribute on the input and output fields.

You could either drive the values programatically, or by adding attributes.

Here is a simple way that should work:

 

 

<apex:component >
<apex:attribute name="otxt" id="otxt" type="String" description="This is common section template"/>
<apex:attribute name="itxt" id="itxt" type="String" description="This is common section template"/>
<apex:attribute name="renderout" type="string" default="false" description="Should I render the output?" />
<apex:attribute name="renderin" type="string" default="false"

description="Should I render the input?" />


<apex:inputText value="{!itxt}" rendered="{!renderin}"/>
<apex:outputText value="{!otxt}" rendered="{!renderout}"/>

</apex:component>

 

 

VFPage_1 <apex:page> <c:myCmp otxt="Test Output Text" renderout="true"/> </apex:page> VFPage_2 <apex:page> <c:myCmp itxt="" renderin="true"/> </apex:page>

 

 

 

Message Edited by JimRae on 03-13-2009 08:29 AM