我正在尝试创建我的第一个 VF 页面。这是一个单项输入表单,允许用户在单击保存之前输入多个子记录 (Enfants_c)。现在,我正在从父级(Assure _c)上的自定义按钮打开 VF 页面。但是,当页面打开时,父项的查找字段未填充 - 因此用户必须单击查找以从 Assure__c 中选择父项。有没有办法将上一页的父 id 传递给 VF 页面上的新子记录?
//page
<apex:page standardController="Enfants__c" extensions="insererEnfants" standardStylesheets="true">
<apex:sectionHeader title="Ajouter un enfant"
subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form >
<apex:pageBlock title="Nouveau enfant" id="thePageBlock" mode="edit">
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Enregistrer"></apex:commandButton>
<apex:commandButton action="{!cancel}" value=" Annuler "></apex:commandButton>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!accts}" var="a" id="table">
<apex:facet name="footer">
<apex:commandLink value="Ajouter" action="{!addRow}" rerender="table,error"/>
</apex:facet>
<apex:facet name="header">
<apex:commandLink value="Supprimer" action="{!deleteRow}" rerender="table,error"/>
</apex:facet>
<apex:column headerValue="Nom">
<apex:inputField/> value="{!a.Parent__c}"/>
</apex:column>
<apex:column headerValue="Nom">
<apex:inputField value="{!a.Name}"/>
</apex:column>
<apex:column headerValue="Prénom">
<apex:inputField value="{!a.Prenom__c}"/>
</apex:column>
<apex:column headerValue="Né le">
<apex:inputField value="{!a.Date_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Lieu de naissance">
<apex:inputField value="{!a.Lieu_de_naissance__c}"/>
</apex:column>
<apex:column headerValue="Situation">
<apex:inputField value="{!a.Situation__c }"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</apex:page>
//Controller
public class insererEnfants{
public List<Enfants__c> accts {get; set;}
public insererEnfants(ApexPages.StandardController controller){
accts = new List<Enfants__c>();
accts.add(new Enfants__c();
}
public void addrow(){
accts.add(new Enfants__c());
}
public PageReference deleteRow(){
if (accts.size()>1)
{
accts.remove(accts.size()-1);
}
return null;
}
public PageReference save()
{
insert accts;
Assure__c theParent = new Assure__c(id=accts[0].Parent__c);
PageReference acctPage = new ApexPages.StandardController(theParent).view();
acctPage.setRedirect(true);
return acctPage;
}
}