You need to sign in to do that
Don't have an account?
Bill Woodson
visualforce auto fill based on lookup result
I want to present a summary of a child object on the VF screen of the parent.
On the parent I select the child using a lookup type input field and up on selection I want to show properties of the child on the screen in a summary div.
Any idea on how to do this?
On the parent I select the child using a lookup type input field and up on selection I want to show properties of the child on the screen in a summary div.
Any idea on how to do this?
Investigate the Rerender attribute of the apex tag outputPanel.
Using the outputPanel, along with re-render you can set it up to update the contents of the panel (essentially a div or span tag) when an action occurs. Your panel should display the details you want to display, and have it setup so that it's re-rendered whenever your lookupfield changes.
<apex:page standardController="Booking__c" extensions="BookingExtensionController">
<h1>Booking for {!theBooking.Opportunity__r.Name} on {!theBooking.Opportunity__r.CloseDate}</h1>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Customer Information" columns="2">
<apex:pageBlockSectionItem >
<apex:inputField id="contact" value="{!theBooking.Contact__c}">
<apex:actionSupport event="oncomplete"
rerender="customerInfo" />
</apex:inputField>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem >
<apex:outputPanel id="customerInfo" rendered="true">
<h1>Provider Info</h1><br/>
{!theBooking.Contact__r.Name}<br/>
{!theBooking.Contact__r.MailingStreet}<br/>
{!theBooking.Contact__r.MailingCity}, {!theBooking.Contact__r.MailingState} {!theBooking.Contact__r.MailingPostalCode}
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Public Class BookingExtensionController{
public Booking__c theBooking { get; set;}
private Apexpages.standardcontroller myController;
Public BookingExtensionController(Apexpages.standardcontroller controller){
myController = controller;
List<String> fields = new List<String>();
fields.add('Contact__c');
fields.add('Contact__r');
fields.add('Contact__r.Name');
fields.add('Contact__r.MailingStreet');
fields.add('Contact__r.MailingCity');
fields.add('Contact__r.MailingState');
fields.add('Contact__r.MailingPostalCode');
fields.add('Opportunity__r');
fields.add('Opportunity__r.Name');
fields.add('Opportunity__r.CloseDate');
myController.addFields(fields);
this.theBooking = (Booking__c)myController.getRecord();
}
}
I have a custom Booking object that has a Contact field on it that is a lookup type to Contact.
<apex:page standardController="Opportunity" extensions="OpportunityExtension">
<h1>Create booking for {!opportunity.Name} on {!opportunity.CloseDate}</h1>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Provider Information">
<apex:actionRegion >
<apex:inputField value="{!theBooking.Contact__c}">
<apex:actionSupport event="onchange" action="{!updateContactInfo}" status="queryStatus" reRender="providerInfo">
<apex:param name="selectedContactId" value="{!theBooking.Contact__r.Id}" />
</apex:actionSupport>
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="providerInfo">
Name: {!theContact.Name}<br/>
</apex:outputPanel>
</apex:pageBlockSection>
<apex:pageBlockSection title="Dates">
<apex:inputField value="{!theBooking.StartDate__c}"/>
<apex:inputField value="{!theBooking.EndDate__c}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:actionStatus id="queryStatus" startText="(Updating...)" stopText="(done)" />
</apex:form>
</apex:page>
Public class OpportunityExtension
{
public Booking__c theBooking { get; set;}
public Contact theContact { get; set;}
private Apexpages.standardcontroller myController;
Public OpportunityExtension(Apexpages.standardcontroller controller){
myController = controller;
theBooking = new Booking__c();
}
Public void updateContactInfo() {
String id = Apexpages.currentPage().getParameters().get('selectedContactId');
system.debug('in updateContactInfo and about to load' + id);
theContact = [SELECT Name FROM Contact WHERE Id = : id];
}
}
<apex:page standardController="Opportunity" extensions="OpportunityExtension">
<h1>Create booking for {!opportunity.Name} on {!opportunity.CloseDate}</h1>
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Provider Information">
<apex:actionRegion >
<apex:inputField value="{!theBooking.Contact__c}">
<apex:actionSupport event="onchange" action="{!updateContactInfo}" status="queryStatus" reRender="providerInfo" />
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="providerInfo">
Name: {!theContact.Name}<br/>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:actionFunction name="reQuery" action="{!updateContactInfo}" onComplete="rerenderprovider();">
<apex:param name="contactId" value="{!theBooking.Contact__r.Id}" assignTo="{!selectedContactId}"/>
</apex:actionFunction>
<apex:actionFunction name="rerenderprovider" reRender="providerInfo" />
<apex:actionStatus id="queryStatus" startText="(Updating...)" stopText="(done)" />
</apex:form>
</apex:page>
Public class OpportunityExtension
{
public Booking__c theBooking { get; set;}
public Contact theContact { get; set;}
private Apexpages.standardcontroller myController;
Public OpportunityExtension(Apexpages.standardcontroller controller){
myController = controller;
theBooking = new Booking__c();
}
Public PageReference updateContactInfo() {
theContact = [SELECT Name FROM Contact WHERE Id = :theBooking.Contact__c];
return null;
}
}