Salesforce 如何根据其他字段中的值显示字段
我有一个难题,我似乎找不到解决办法 我正在做一个VF页面,我想根据用户在其他字段中插入的数字显示字段。例如,如果用户在字段“A”中插入2,则会在同一页面中显示两个字段Salesforce 如何根据其他字段中的值显示字段,salesforce,apex-code,visualforce,Salesforce,Apex Code,Visualforce,我有一个难题,我似乎找不到解决办法 我正在做一个VF页面,我想根据用户在其他字段中插入的数字显示字段。例如,如果用户在字段“A”中插入2,则会在同一页面中显示两个字段 // Page <apex:page standardController="Assure__c" extensions="insEnfant" standardStylesheets="true"> <apex:sectionHeader title="Ajouter un assuré" subtit
// Page
<apex:page standardController="Assure__c" extensions="insEnfant"
standardStylesheets="true">
<apex:sectionHeader title="Ajouter un assuré"
subtitle="{!$User.FirstName}" help="/help/doc/user_ed.jsp?loc=help"></apex:sectionHeader>
<apex:form>
<apex:pageBlock title="Nouveau assuré" 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:pageBlockSection title="General Information" columns="2">
<apex:pageBlockSection id="liste1" columns="1">
<apex:inputField value="{!Assure__c.Civilite__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Nom__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Prenom__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Nom_de_jeune_fille__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Date_de_naissance__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Lieu_de_naissance__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Pays_de_naissance__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Nationalit__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Situation_Familiale__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Numero_de_securit_sociale__c}"></apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection id="liste2" columns="1">
<apex:inputField value="{!Assure__c.Telephone_bureau__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Telephone_personnel__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Portable__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Adresse_e_mail__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Adresse__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Code_postal__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Ville__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Pays__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Pays__c}"></apex:inputField>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Nombre d'enfants" />
<apex:outputPanel>
<apex:inputField value="{!Assure__c.Nombre_enfants__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="statut1" />
</apex:inputField>
<apex:actionStatus startText="Application..." id="statut1" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputLabel
value="{!$ObjectType.Assure__c.fields.Etudes_superieures__c.label}" />
<apex:outputPanel>
<apex:inputField value="{!Assure__c.Etudes_superieures__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="statut2" />
</apex:inputField>
<apex:actionStatus startText="Application..." id="statut2" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem>
<apex:outputLabel value="Service militaire" />
<apex:outputPanel>
<apex:inputField value="{!Assure__c.Service_militaire__c}">
<apex:actionSupport event="onchange" rerender="thePageBlock"
status="statut3" />
</apex:inputField>
<apex:actionStatus startText="Application..." id="statut3" />
</apex:outputPanel>
</apex:pageBlockSectionItem>
</apex:pageBlockSection>
</apex:pageBlockSection>
<apex:pageBlockSection
title="Entrez le niveau d'études supérieures atteint" columns="1"
rendered="{!(Assure__c.Etudes_superieures__c)}">
<apex:inputField value="{!Assure__c.Type_etudes__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Diplome_obtenu__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Nombre_annees__c}"></apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection
title="Entrez les informations concernant le service militaire"
columns="1" rendered="{!(Assure__c.Service_militaire__c)}">
<apex:inputField value="{!Assure__c.Type_de_service__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Date_de_debut__c}"></apex:inputField>
<apex:inputField value="{!Assure__c.Date_de_fin__c}"></apex:inputField>
</apex:pageBlockSection>
<apex:pageBlockSection title="Liste des enfants" columns="1"
rendered="{!IF(Assure__c.Nombre_enfants__c > 0, true, false)}">
<apex:pageBlockTable value="{!accts}" var="a" id="table">
<apex:facet name="footer">
<apex:commandLink value="Ajouter" action="{!addRow}"
rerender="table,error" />
</apex:facet>
<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:pageBlockSection>
</apex:pageblock>
</apex:form>
</apex:page>
// Controller
public class insEnfant{
public List<Enfants__c> accts {get; set;}
public insererEnfant(){
accts = new List<Enfants__c>();
accts.add(new Enfants__c());
}
public void addrow(){
accts.add(new Enfants__c());
}
public PageReference save(){
insert accts;
PageReference home = new PageReference('/home/home.jsp');
home.setRedirect(true);
return home;
}
}
//第页
//控制器
公共类插入{
公共列表帐户{get;set;}
公共教育(儿童){
accts=新列表();
账户添加(新儿童);
}
public void addrow(){
账户添加(新儿童);
}
公共页面引用保存(){
插入账户;
PageReference home=新的PageReference('/home/home.jsp');
home.setRedirect(true);
回家;
}
}
有人能帮我吗
谢谢 如果您想以友好的方式添加Html,我认为您应该使用Javascript或类似JQuery的Javascript框架,但我无法理解您的意图 请说得具体一点。您要添加什么类型的文件?这些是输入字段吗?还是将是输出字段?你能事先知道要显示的信息吗
也许您可以使用apex组件,并在执行javascript请求时重新提交它。您是否根据一个字段中的输入查看,是否允许/不允许显示其他字段 您可以使用渲染标记显示所有要显示的字段,并控制该字段的可见性
<apex:outputField value="{!item.field1__c}" >
<apex:actionSupport event="onchange" action="{!displayOtherCols}" rerender="mainBlock2"/>
</apex:outputField>
<apex:column headerValue="Name" >
<apex:outputField value="{!item.field2__c}" rendered="{!(item.field1__c == 'option1')}" />
<apex:outputField value="{!item.field3__c}" rendered="{!(item.field1__c == 'option2')}" />
</apex:column>
您可以使用actionsupport调用一个方法,该方法将处理并设置哪些字段应该由其呈现。在本例中,我直接检查字段的值,您可以这样做,也可以在displayothercols方法中设置布尔变量的值,并使用该变量渲染字段。确保重新启动该块
在此示例中,如果字段1具有“选项1”,则显示另一个字段字段2,如果字段1为“选项2”,则显示字段3
希望这有帮助
祝你好运一个解决方案将涉及使用RERERENDER与表结构相结合。您需要在控制器内建立一个集合(下面标记为“dataCollection”)。此集合驱动显示的内容和将捕获的内容
<apex:actionRegion>
<apex:inputField value="{!controllerObject.NumRows__c}">
<apex:actionSupport event="onchange" action="{!refresh}" rerender="dynamicTablePanel"/>
</apex:inputField>
</apex:actionRegion>
<apex:outputPanel id="dynamicTablePanel">
<apex:pageBlockTable id="dynamicTable" value="{!dataCollection}" var="dataRow"
columns="2">
<apex:column headerValue="Column A" title="">
<apex:inputField value="{!dataRow.ColumnA__c}" />
</apex:column>
<apex:column headerValue="Column B" title="">
<apex:inputField value="{!dataRow.ColumnB__c}" />
</apex:column>
</apex:pageBlockTable>
</apex:outputPanel>
这将需要控制器中的额外工作。必须处理刷新操作,才能根据需要添加或删除收集记录。您还必须处理保存按钮;您必须保存控制器记录,还必须循环查看收集项目并将其保存在某个位置。我建议为集合使用子对象。谢谢,我想显示输入字段,因此我事先不知道要显示的信息。我想显示一个表,其中包含输入字段和字段中数字的行数。感谢您的回答,我想显示一个表,其中包含行数(每个行都有输入字段)在其他字段中删除数字。例如,如果用户在字段中输入2,将显示一个包含两行(输入字段)的表格。我希望您知道我可以如何继续。感谢您的精彩回答,我这样做了,但我仍然有问题,我无法解决,我将编辑我的帖子