您可以使用联系人对象的 Wrapper 类来存储联系人的当前和新状态,以检查联系人是否是活动的成员。
public class ContactWrapper
{
public Boolean checked{ get; set; }
public Contact con { get; set;}
public AccountSKUWrapper()
{
con = new Contact();
checked = false;
}
public ContactWrapper(Contact c)
{
con= c;
checked = c.selected;
}
}
使用选定的字段,我们可以识别联系人是否是 Campaign 的成员,并且包装器中的检查变量有助于识别 VF 页面中给出的输入。创建 ContactWrapper 列表并使用重载的构造函数“ContactWrapper(Contact c)”初始化每个 ContactWrapper 对象。
<apex:repeat value="<ContactWrapper Object>" var="cm">
<div class="MailingRow">
<apex:outputText styleClass="CampaignLabel" value="{!cm.con.Name}" ></apex:outputText>
<apex:inputCheckbox styleClass="CampaignCheck" value="{!cm.checked}" />
</div>
</apex:repeat>
在单击保存按钮期间,请执行以下步骤: 检查选中变量的值与所选字段不同。
Create 2 list **CHANGEDCONTACTLIST** and **UNCHANGEDCONTACTLIST** and then Loop through the list of ContactWrapper
begin loop
1.If checked differs then load **CHANGEDCONTACTLIST** with Contact Wrapper object as this need to be updated in Contact object; in order to update selected field of contact.
2.Else load **UNCHANGEDCONTACTLIST**.
end loop
最终使用这两个列表 CHANGEDCONTACTLIST和UNCHANGEDCONTACTLIST。您可以插入或删除 dml。
我相信这里没有使用 ActionSupport 标签,因为所有需要的值都将使用 ContactWrapper 列表的 getter 和 setter 来使用(读/写)。
public List<ContactWrapper> wrapper {get;set;}