1

I have an apex:Component and I want to get its attributes value in the page

<apex:component id="Job_Applicant_Details" controller="Job_Applicant_DetailsController">
<apex:attribute name="fName" type="String" assignTo="{!FullName}" description="Fullname of the applicant"/>

<apex:outputpanel id="panel" >
    <apex:form id="frmApplicant">
        <apex:outputlabel value="Name"/><br></br>
        <apex:inputtext id="FullName" value="{!fName}"/>
</apex:form>
</apex:outputpanel>

</apex:component>

I have a VF page and I want to set the fname attribute to the page property. I have couple of other common fields on this component and I want to access values and set it to a property on my VF page, so I can save them.

Here is my apex page

  <c:Job_Applicant_Details/>
        <apex:form >
            <apex:outputpanel >
                        <apex:outputlabel value="Skills"/>
                        <br></br>
                       <apex:inputfield id="Skills" value="{!Job_Applicant_Details__c.Skills}"/>
                        <br></br>
                   <apex:commandbutton id="btn_submit" value="Submit"/>
            </apex:outputpanel>
            </apex:form>

Its a page with a component and other input fields on the page. I want to either pass the components attributes as parameters to the page or get its value and set it to the page properties.

  • can you paste the apex page first line, need to know if you are using the same controller for the page and controller. – Rao Oct 1 '14 at 15:01
  • <apex:page Controller="Job_Applicant_Details__c" extensions="Job_Applicant_DetailsController" showheader="false" sidebar="false"> – Tasnim Oct 1 '14 at 15:18
1

Cannot take credit for this :

How do I pass a parameter from component to a Visualforce page?

Since your component lives separated from the page any change on the component never calls the controller thereby the value of the fullname string is never set. To overcome this we use an action support to call the controller on the input field change event,

controller: ( Add your extra code over this)

public class Job_Applicant_DetailsController {
public string FullName{get;set;}
// This method is nothing but a dummy method to support the action support.
public void updateFname(){
}
}

component:

<apex:component id="Job_Applicant_Details" controller="Job_Applicant_DetailsController">
<apex:attribute name="fName" type="String" assignTo="{!FullName}" description="Fullname of the applicant"/>
<apex:outputpanel id="panel" >
    <apex:form id="frmApplicant">
        <apex:outputlabel value="Name"/><br></br>
        <apex:inputtext id="FullName" value="{!fName}">
            <apex:actionsupport event="onchange" action="{!updateFname}"/>
        </apex:inputtext>
</apex:form>
</apex:outputpanel>

Page:

<apex:page controller="Job_Applicant_DetailsController">
<c:comp_Test fName="{!FullName}"/>
Value passed from component :<b style="color:red">{!Fullname}</b> <br/>
        <apex:form >
            <apex:outputpanel >
                        <apex:outputlabel value="Skills"/>
                        <br></br>
                        <br></br>
                   <apex:commandbutton id="btn_submit" value="Submit"/>
            </apex:outputpanel>
            </apex:form>
</apex:page>

enter image description here

  • Thanks..it works. I added the onchange event. Before that I implemented the code from developer.salesforce.com/page/…. But with this also I had to add the actionsupport onchange event. I believe the latter one can be used when we want to call some methods from the component. But since I just want the values, I can simply use what you suggest. Is my understanding correct on this? – Tasnim Oct 1 '14 at 19:05

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.