Subscribe

Appirio RSS Feed
Subscribe with Bloglines

Add to Google
Subscribe in NewsGator Online

Community

Appirio Technology Blog

Friday, July 25, 2008

Extending Visualforce's UI - Ext JS DataGrid


Roche
In this posting we're going to use the Ext JS library to build out a custom DataGrid in a Visualforce page. Ext JS is a JavaScript library for building richer UI layers with out the need for plug in technologies. Ext JS has some fantastic UI widgets and Open Source licenses are available.


This technique will use the Simple Data Store. In future postings we'll build on this with examples using JSON and other technologies. The first step is to download the latest version of the Ext JS SDK. We're going to upload the archive as a Static Resource so we can reference it from within our Visualforce application. Remember, there's a 5MB per file limit on Static Resources so make sure you remove the sample directory from the SDK before trying to upload it as a Static Resource. Your upload resource should look like this:

StaticResourcesReferencing a Static Resource
Static Resources can be referenced by using the $Resource global variable. Archives are especially interesting because you can reference the full path to a file within an archive saving you countless effort organizing your uploads. We'll be referencing the following resources for this example.

StyleSheet: /ext-2.1/resources/css/ext-all.css
JavaScript: /ext-2.1/adapter/xt/ext-base.js
JavaScript: /ext-2.1/ext-all.js

Creating the Visualforce Page
First, make sure you have development mode enabled. Setup | My Personal Information | Personal Information | Development Mode. Create a new Visualforce page by redirecting your browser to http://server.salesforce.com/apex/ExtJs_DataGrid_Part1. Follow the prompt to create your page. Development mode enables two things in your org. First, you now have the ability to create a page via the URL, as you've just done. Secondly, you now have the ability to edit Visualforce pages from within your browser. In the bottom left of the browser click on Page Editor to open the Visualforce Editor. Add the following code to reference our Static Resources with our Ext JS library.

<link rel="Stylesheet" type="text/css" href="{!$Resource.ExtJs}/ext-2.1/resources/css/ext-all.css" />
<script type="text/javascript" src="{!$Resource.ExtJs}/ext-2.1/adapter/ext/ext-base.js"></script>
<script type="text/javascript" src="{!$Resource.ExtJs}/ext-2.1/ext-all.js"></script>

Click Save. Our page is now referencing the three static resources within the archive we uploaded. Note the use of the $Resource variable in our data binding calls.

Gathering Some Sample Data
Ext JS' "Simple Data Store" is built by constructing a string based Array which we'll bind our DataGrid. Let's create a customer controller to retrieve the data for our Visualforce page. In the Page Editor change the <apex:page> component to read as follows.

<apex:page sidebar="false" controller="ExtJSDataGrid1Controller">

You will see an option above the toolbar in the Editor to create a new APEX Class. After clicking that link you should see a new button next to Page Editor called Controller. Open the code for the Controller and paste in the following. Note the use of the Apex Property in place of the traditional getter and setter methods. This is new to Summer 08.

public class ExtJSDataGrid1Controller {
public List<Contact> myContacts {
get {
if (myContacts == null) {
myContacts = [SELECT Id, FirstName, LastName FROM Contact LIMIT 10];
}
return myContacts;
}
set;
}
}

Adding Ext JS to our Visualforce Page
Now that we have our SOQL query returning 10 Contact records we're going to add the JavaScript to generate our Ext JS DataGrid. Paste the code below into the Page Editor. Note our use of the <apex:repeat> component to build out our DataStore. Typically, the use case for the <apex:repeat> component would be to build out repeating UI elements. In this situation we're using it to build out our <script> for the rendered page.

<script type="text/javascript">
Ext.onReady(function(){
Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
var myDataString = 'var myData = [ ';
<apex:repeat value="{!myContacts}" var="con" id="ContactRepeat">
myDataString += "['{!con.Id}','{!con.FirstName}','{!con.LastName}'],";
</apex:repeat>
myDataString += "['','',''] ];";
eval(myDataString);
var store = new Ext.data.SimpleStore({fields:[{name:'ID'},{name:'FirstName'},{name:'LastName'}]});
store.loadData(myData);
// CREATE THE GRID
var grid = new Ext.grid.GridPanel({store: store, columns: [
{id: 'ID', header: "ID", width: 50, sortable: true, dataIndex: 'ID'},
{id: 'FirstName', header: "First Name", width: 150, sortable: true, dataIndex: 'FirstName'},
{id: 'LastNme', header: "Last Name", width: 150, sortable: true, dataIndex: 'LastName'}
],stripeRows:true, autoExpandColumn: 'ID', height: 500, width: 1000, title: 'MY EXT JS CONTACT LIST'});

grid.render('myContactList-grid');
grid.getSelectionModel().selectFirstRow();
});
</script>

Don't Forget the DataGrid

Add the following <div> tag and click Save to view your new Ext JS driven DataGrid.
<div id="myContactList-grid"></div>


ExtJSDataGrid_Part1_Complete

Extending Visualforce's UI - Series Intro

Kyle
Roche


Welcome to the first in an on-going series of postings exploring the several approaches that are available for extending the Visualforce UI using different sets of 3rd party components. We'll look at technologies like Flex, Ext JS, YUI, and Google's Chart API to name a few.

Overview of Visualforce
Visualforce allows you to abstract the user interface layer from your standard Salesforce org and create something completely unique. Visualforce is the gateway to PaaS on the Force.com platform. Visualforce is built on the MVC Design pattern and leverages APEX define UI behaviors and navigation routines.

Extending Visualforce's UI Layer
In many cases the standard Visualforce UI elements available at GA don't meet every need. Instead of reverting to client side technologies and making calls back through the AJAX Toolkit we're going to walk you through some techniques to integrate 3rd party UI libraries and still leverage the server side power of Visualforce!

Static Resources in Visualforce
With Summer 08, we have a new kind of Salesforce storage designed specifically with Visualforce in mind, called Static Resources. You can upload files to Static Resources via Setup | Develop | Static Resources. Libraries or files uploaded to Static Resources can become items that you reference in your Visualforce pages. Things like stylesheets, JavaScript, images and even archives can be linked to through the $Resource global variable. For more information on Static Resources see the Visualforce Developer's Guide. Organize your Static Resources by compiling the items needed for your Visualforce Application into archive files (Remember, there is a 5MB per file limit). Visualforce can bind to files within the archive so there's no need to upload each file individually!

Stay tuned for our next posting where we'll integrate a DataGrid from Ext JS into a Visualforce Page.

Salesforce Customer Portal CSS Modifications

Michael
McLaughlin


The Problem: How do I modify my Customer Portal implementation to match my public facing website?


The Salesforce Customer Portal is a great extension to Salesforce.com that allows companies to open up certain areas of their Salesforce organization to designated customer users for self-servicing their accounts. The Portal lets customers make account changes, log and view status on a case and provides answers to common customer questions...all without involving a support representative and inherent response delay.

Out of the box, the customer portal retains the standard Salesforce.com look and feel we have all grown accustomed to. End user of the portal (the customer's customers) however, will most likely be unfamiliar with this user interface. In addition, since most Customer Portal implementations hang off of the main website of a customer, there could be confusion for end users if they encounter the standard salesforce.com look and feel.

The Solution: Customer Portal CSS Mods

One solution to this problem is to format salesforce.com Customer Portal to match the style of organization's website. This gives the customer's end user the impression that he is still on the organization's site.

Customer Portal allows minimal customization of fonts and colors through a simple administration interface. This also allows you to supply a custom header and footer. In order to do more than this and complete the visual transformation of your Customer Portal implementation you can use Cascading Style Sheets (CSS).

Salesforce does not produce documentation explaining what CSS classes define which Customer Portal screen elements. This allows them to change these style elements in future releases. As a result, unlike supported salesforce.com customizations, you may need to verify your changes still work with future salesforce.com releases. In other words, be careful with the below :-)

You need to use a tool to help you get under the covers to see the interaction of CSS with what the users sees. Users of Mozilla Firefox have access to an excellent free add-on called Firebug. Firebug allows you to "inspect" the content and structure of any web page. Turn Firebug on and navigate to the pages of your Customer Portal implementation. Hover over the screen elements you wish to modify such as table headers, background images, etc. Take note of the CSS classes Firebug says are responsible for the elements' formatting.

Now that you know what out of the box Customer Portal styles are driving the interface elements you wish to change, you can override them using your own style definitions. You must use the same style class names so your browser will use your style definition and not the default one. Do this by:
  • Modifying the style to your liking in CSS syntax
  • Save your changes to a CSS file you store in Static Resources or Documents
  • Reference your CSS file in the Customer Portal header HTML (accessible in the Customer Portal Administration panel) using a <link> tag
    • OR, if your changes are small, simply use a <style> tag and insert your styles as HTML directly into the Customer Portal header
  • View the resulting changes in Customer Portal and tweak as necessary
  • Use Firebug to hover over your screen elements to see if your styles are being properly used
Further reading: Example of the solution in action:
<style type=text/css>
/* Redefining this style for Customer Portal to make the font smaller */
body {
font-size:9pt;
}

/* Redefining this style for Customer Portal to make the listHeader an image */
.listHeader {background-image: url(/dimg/portalTabRight96999C96999C.gif);}

/* Redefining to make sidebar an image. Kept its present color and font definitions. */
.sidebarModuleHeader,
.nestedModule .sidebarModuleHeader {
background-image: url(/dimg/portalTabRight96999C96999C.gif);
color: #505154;
font-family: Arial, Helvetica, sans-serif;
}
...

Screenshot of Firebug inspecting Customer Portal's style elements:

Wednesday, July 16, 2008

Welcome to the Appirio Tech Blog

The team here at Appirio spends a lot of time building innovative plugins, apps and even complete business solutions using Software-as-a-Service (SaaS) and Platform-as-a-Service (PaaS) technologies from Google and salesforce.com. We like how easy it is to build these solutions-- that's what makes cloud computing so different (and so disruptive). But easy isn't automatic (no matter what your boss thinks). That's why we're writing this blog.

Internally, the Appirio team talks a lot about design patterns, issues, work arounds and cool tricks to make it build on use web platforms. It fun to find a new way to solve a problem and a badge of honor to see who can do it with the "least lines of code".

We want you to be a part of our conversation. Why? So that you get as excited as we are about the power of cloud computing and can build your own cool applications. This blog is for you if want to build on the cloud, whether you are a power-admin or an apex wizard, whether you are a longtime Salesforce and Google customer or just getting started, whether you are an individual contributor or are managing an entire team of developers. We won't have code in every post, but we'll definitely be thinking about it.

Here are a few of the topics we're thinking about, feel free to suggest your own.
  • Salesforce's VisualForce allows developers to design any UI on top of the Salesforce data model. What's possible with VisualForce today, and how can you make the most it?
  • Salesforce's Apex programming language gives you a lot of flexibility and power, but using it effectively requires understanding its capabilities and limitations. Where can you find tips and tricks for developing in Apex?
  • Salesforce's Customer and Partner portal lets you share critical business data information with people outside your company. How can you develop effective portal applications?
  • Google's AppEngine lets you build the next great web app, but is still lacking basic features for enterprise use (e.g., support for HTTPS). Where does AppEngine fit for enterprises and how can you use it with that in mind?
  • Everyone wants to use their on-demand applications from mobile devices like the BlackBerry and iPhone. What's the best way to enable these capabilities and finally unchain your users from their desks (e.g. super monkey ball for the enterprise)?
  • Security is top-of-mind for any company looking to move more of their business onto the cloud. What shoudl you know when configuring roles and profiles, establishing authentication and authorization, and setting up single-sign on?
As you can tell, there's a lot of ground to cover. We'll have folks from Appirio and occassionally some guest writers help us get there.