Those who have patience and want to read theory of Custom Visualforce Component, first visit Visualforce Component Theory, then come back here. Others, stay tuned, follow steps and watch it in action.
In just 4 steps we can create a custom visualforce component:
<apex:attribute name="textValue" description="This is the value for the component" type="String" required="true"/>
<apex:attribute name="textColor" description="This is color for the border." type="String" required="true"/>
<apex:outputText value="{!textValue}" style="color:{!textColor};"/>
</apex:component>
</pre>
<apex:pageBlock >
<apex:pageBlockSection title="myComponent Test" collapsible="false">
<c:myComponent textValue="This Text is blue" textColor="blue" />
<c:myComponent textValue="But this is red" textColor="red" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
In just 4 steps we can create a custom visualforce component:
- Create Visualforce Component
- Go to Setup -> Develop -> Visualforce Component -> New
- Enter Label and Name
- Write code for visualforce component and save it
<pre class="brush: js"> function foo() { } </pre>
<pre class = "brush: html">
<apex:component ><apex:attribute name="textValue" description="This is the value for the component" type="String" required="true"/>
<apex:attribute name="textColor" description="This is color for the border." type="String" required="true"/>
<apex:outputText value="{!textValue}" style="color:{!textColor};"/>
</apex:component>
</pre>
- Use our component in Visualforce Page
- Open the VF in which you want to use the component
- Use the <c:componentName > to inject the component. You can give attributes also.
<apex:pageBlock >
<apex:pageBlockSection title="myComponent Test" collapsible="false">
<c:myComponent textValue="This Text is blue" textColor="blue" />
<c:myComponent textValue="But this is red" textColor="red" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
- Save and Preview the page, dear
0 comments :
Post a Comment