http://cewl-developer-edition.na7.force.com/
Creating the custom object
Create the gbEntry custom object as the database table to store guestbook entries.
gbEntry +Name (text) +Comment(Long Text Area)
I could have used just gbEntry standard controller. However, I want to override the "save" method. By default, the "save" method redirect user to record detail. By overriding this method, I can redirect the user to the list of entries after submitting the guestbook entry.
public with sharing class gbEntryController {
private ApexPages.StandardController controller;
public gbEntryController(ApexPages.StandardController controller) {
this.controller = controller;
}
public PageReference save() {
this.controller.save();
PageReference pageRef = new PageReference('/apex/listEntries');
return pageRef;
}
}This visualforce page displays the list of guest book entries. I use apex:repeat tag to loop through the records.
// listEntries.page
<apex:page showheader="false" standardController="gbEntry__c" recordSetVar="gbEntries">
<div style="width:640px;margin:20px;padding:20px">
<h1>Force.com Powered Guest Book</h1>
<p><a href="submitComment">Leave your comment</a></p>
<p>
<apex:repeat value="{!gbEntries}" var="gbEntry" >
<div style="padding:10px;margin:10px;border:1px dotted silver; background-">
<span >
<apex:outputField style="font-family: Monospace;" value="{!gbEntry.Comment__c}"/>
<br/><br/>
Posted by <strong><apex:outputField value="{!gbEntry.Name__c}"/></strong> at
<apex:outputField value="{!gbEntry.createdDate}"/>
</span>
</div>
</apex:repeat>
</p>
</div>
</apex:page>// listEntries.page
<apex:page standardcontroller="gbEntry__c" extensions="gbEntryController" showHeader="false">
<div style="width:640px;margin:20px;padding:20px">
<h1>Force.com Powered Guest Book</h1>
<p><a href="listEntries">View Comments</a></p>
<hr style="border:1px solid silver"/>
<apex:form >
<table cellpadding="2" cellspacing="3">
<tr>
<td valign="top" colspan="2"><apex:pageMessages /></td>
</tr><tr>
<td valign="top" >Name:</td>
<td><apex:inputText style="width:200px;" value="{!gbEntry__c.Name__c}"/></td>
</tr><tr>
<td valign="top" >Comment:</td>
<td><apex:inputTextArea style="width:300px;" value="{!gbEntry__c.Comment__c}"/></td>
</tr><tr>
<td valign="top" colspan="2"><apex:commandButton value="Save" action="{!Save}" /></td>
</tr>
</table>
</apex:form>
<hr style="border:1px solid silver"/>
</div>
</apex:page>
No comments:
Post a Comment