***** Controller ****************
public class InlineController {
public InlineController(ApexPages.StandardController controller) {
}
public Contact newContact { get; set; }
public Contact editContact { get; set; }
public InlineController () {
newContact = new Contact();
}
public Contact[] getEmployees() {
return [Select c.MailingCountry, c.LastName, c.Id, c.Email From Contact c];
}
public String getParam(String name) {
return ApexPages.currentPage().getParameters().get(name);
}
public PageReference add() {
try {
INSERT newContact;
newContact = new Contact();
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
public PageReference del() {
try {
String delid = getParam('delid');
Contact employee = [SELECT Id FROM Contact WHERE ID=:delid];
DELETE employee;
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
public PageReference editcon() {
String editid = getParam('editid');
editContact = [SELECT Name, LastName, email,MailingCountry FROM Contact WHERE id=:editid];
return null;
}
public PageReference cancelEdit() {
editContact = null;
return null;
}
public PageReference saveEdit() {
try {
UPDATE editContact;
editContact = null;
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
}
********** Visualforce Page ***************************
<apex:page standardController="Contact" extensions="InlineController">
<apex:pageMessages />
<apex:form >
<apex:actionFunction name="saveEdit" action="{!saveEdit}"/>
<apex:pageBlock >
<apex:outputPanel id="employeeList">
<table>
<tr>
<th style="width:40px"> </th>
<th style="width:40px"> </th>
<th style="width:90px">Last Name</th>
<th style="width:90px">Email</th>
<th>Mailing Country</th>
</tr>
<apex:repeat value="{!employees}" var="e">
<tr style="height:20px">
<apex:outputPanel id="editRow" layout="none" rendered="{!e.Id == editContact.Id}">
<td><apex:commandLink action="{!cancelEdit}" rerender="employeeList">Cancel</apex:commandLink></td>
<td><apex:commandLink action="{!saveEdit}" rerender="employeeList">Save</apex:commandLink></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.LastName}"/></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.email}"/></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" onkeypress="if (event.keyCode == 13) saveEdit()" value="{!editContact.MailingCountry}"/></td>
</apex:outputPanel>
<apex:outputPanel id="viewRow" layout="none" rendered="{!e.Id != editContact.Id}">
<td>
<apex:commandLink action="{!del}" onclick="return confirm('Are you sure you want to delete this Employee?')">Del
<apex:param name="delid" value="{!e.Id}"/>
</apex:commandLink>
</td>
<td>
<apex:commandLink action="{!editcon}" rerender="employeeList">Edit <apex:param name="editid" value="{!e.id}"/>
</apex:commandLink>
</td>
<td>{!e.LastName}</td>
<td>{!e.email}</td>
<td>{!e.MailingCountry}</td>
</apex:outputPanel>
</tr>
</apex:repeat>
</table>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Screen shot:
public class InlineController {
public InlineController(ApexPages.StandardController controller) {
}
public Contact newContact { get; set; }
public Contact editContact { get; set; }
public InlineController () {
newContact = new Contact();
}
public Contact[] getEmployees() {
return [Select c.MailingCountry, c.LastName, c.Id, c.Email From Contact c];
}
public String getParam(String name) {
return ApexPages.currentPage().getParameters().get(name);
}
public PageReference add() {
try {
INSERT newContact;
newContact = new Contact();
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
public PageReference del() {
try {
String delid = getParam('delid');
Contact employee = [SELECT Id FROM Contact WHERE ID=:delid];
DELETE employee;
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
public PageReference editcon() {
String editid = getParam('editid');
editContact = [SELECT Name, LastName, email,MailingCountry FROM Contact WHERE id=:editid];
return null;
}
public PageReference cancelEdit() {
editContact = null;
return null;
}
public PageReference saveEdit() {
try {
UPDATE editContact;
editContact = null;
} catch (Exception e) {
ApexPages.addMessages(e);
}
return null;
}
}
********** Visualforce Page ***************************
<apex:page standardController="Contact" extensions="InlineController">
<apex:pageMessages />
<apex:form >
<apex:actionFunction name="saveEdit" action="{!saveEdit}"/>
<apex:pageBlock >
<apex:outputPanel id="employeeList">
<table>
<tr>
<th style="width:40px"> </th>
<th style="width:40px"> </th>
<th style="width:90px">Last Name</th>
<th style="width:90px">Email</th>
<th>Mailing Country</th>
</tr>
<apex:repeat value="{!employees}" var="e">
<tr style="height:20px">
<apex:outputPanel id="editRow" layout="none" rendered="{!e.Id == editContact.Id}">
<td><apex:commandLink action="{!cancelEdit}" rerender="employeeList">Cancel</apex:commandLink></td>
<td><apex:commandLink action="{!saveEdit}" rerender="employeeList">Save</apex:commandLink></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.LastName}"/></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" value="{!editContact.email}"/></td>
<td><apex:inputField rendered="{!e.Id == editContact.Id}" onkeypress="if (event.keyCode == 13) saveEdit()" value="{!editContact.MailingCountry}"/></td>
</apex:outputPanel>
<apex:outputPanel id="viewRow" layout="none" rendered="{!e.Id != editContact.Id}">
<td>
<apex:commandLink action="{!del}" onclick="return confirm('Are you sure you want to delete this Employee?')">Del
<apex:param name="delid" value="{!e.Id}"/>
</apex:commandLink>
</td>
<td>
<apex:commandLink action="{!editcon}" rerender="employeeList">Edit <apex:param name="editid" value="{!e.id}"/>
</apex:commandLink>
</td>
<td>{!e.LastName}</td>
<td>{!e.email}</td>
<td>{!e.MailingCountry}</td>
</apex:outputPanel>
</tr>
</apex:repeat>
</table>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Screen shot:
Comments
Post a Comment