198 Lotus blogs updated hourly. Who will post next? Home | Blogs | Search | About 
 
Latest 7 Posts
Top 10


The Social Business Toolkit – First Project
Twitter Google+ Facebook LinkedIn Addthis Email Gmail Flipboard Reddit Tumblr WhatsApp StumbleUpon Yammer Evernote Delicious
schmhen    

In the first two posts in this series I talked about the Social Business Toolkit (SBT) in general and showed how to install all necessary items in order to use the SBT in XPages.

  1. The Social Business Toolkit (SBT)
  2. The Social Business Toolkit – Getting Started

Today we are going to build an XPage, pull data from IBM Connections and show this data in a Data Table control. So let’s go. First we have to define our endpoint. The endpoint in SBT terms is the definition of the data connection to IBM Connections. We are going to use Basic Authentication in this example. Open you faces-config.xml and add the following lines:

<managed-bean>
	<managed-bean-name>connections</managed-bean-name>
	<managed-bean-class>com.ibm.sbt.services.endpoints.ConnectionsBasicEndpoint</managed-bean-class>
	<managed-bean-scope>session</managed-bean-scope>
	<managed-property>
		<property-name>url</property-name>
		<value>https://your-connections-url.com:444</value>
	</managed-property>
	<managed-property>
		<property-name>authenticationService</property-name>
		<value>communities/service/atom/communities/my</value>
	</managed-property>
	<managed-property>
		<property-name>authenticationPage</property-name>
		<value>your_nsf.nsf/_BasicLogin.xsp?endpoint=tapStageConnections4</value>
	</managed-property>
	<managed-property>
		<property-name>forceTrustSSLCertificate</property-name>
		<value>true</value>
	</managed-property>
</managed-bean>

You can copy the “_BasicLogin.xsp” XPage from the XPagesSBT.nsf that comes with the Social Business Toolkit. The next step is to create a Bean that establishes a connection and reads some data. So create a bean named ServiceBean and copy the following code:

package de.hedersoft.controller.impl;
import com.ibm.sbt.services.client.connections.files.FileList;
import com.ibm.sbt.services.client.connections.files.FileService;
import com.ibm.sbt.services.client.connections.files.FileServiceException;

public class ServcieBean implements Serializable {  
	private static final long serialVersionUID = 1L;  

	public FileList getMyFiles() {    
		FileService service = new FileService();    
		try {      return service.getMyFiles();    
		} catch (FileServiceException e) 
		{      return null;    }  
	}
}

What this code does is pretty straight-forward, isn’t it. It get’s a handle to the FileService object (line 9) that the SBT provides and calls a function to get all files I have stored in the Connections file application (line 11). Then it returns a FileList object to the caller. We will use this FileList object later in our DataTable in order to iterate through the files. But first we have to register our Bean in order to access it. So open you faces-config.xml again and add the following lines:

<managed-bean>
	<managed-bean-name>ServiceBean</managed-bean-name>
	<managed-bean-class>de.hedersoft.controller.impl.ServiceBean</managed-bean-class>
	<managed-bean-scope>session</managed-bean-scope>
</managed-bean>

The last thing we need is a page that shows all files that the ServiceBean returns from IBM Connections. So create a new XPage and name it “xpShowFiles”. Here is the XML to copy and paste into the Source Tab of your new page:

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
	xmlns:xe="http://www.ibm.com/xsp/coreex">

	<xp:dataTable id="dataTable1" rows="30" var="entry"
		styleClass="table table-striped table-condensed full-table-width">
		<xp:this.value><![CDATA[#{javascript:ServiceBean.getMyFiles();
		}]]></xp:this.value>
		<xp:column id="column1">
			<xp:this.facets>
				<xp:label value="File Name" id="label1"
					xp:key="header">
				</xp:label>
			</xp:this.facets>
			<xp:image id="image1">
				<xp:this.url><![CDATA[#{javascript:var docType:String = entry.getLabel().substring(entry.getLabel().lastIndexOf(".")+1,entry.getLabel().length);
if (docType.equals("pdf")) {
	return "/icon_pdf.png";
} else if (docType.equals("xls") || docType.equals("xlsx")) {
	return "/icon_spreadsheet.png";
} else if (docType.equals("doc") || docType.equals("docx")) {
	return "/icon_text.png";
} else if (docType.equals("ppt") || docType.equals("pptx")) {
	return "/icon_presentation.png";
} else if (docType.equals("jpg") || docType.equals("jpeg") || docType.equals("gif") || docType.equals("png")) {
	return "/icon_image.png";
} else {
	return "";
}}]]></xp:this.url>
			</xp:image>
			<xp:link escape="true" text="#{javascript:' ' + entry.getLabel()}"
				id="link1">
				<xp:this.value><![CDATA[#{javascript:return "./xsp/.proxy/files/connections/connections/"+entry.getLabel()+
"?type=connections&id="+entry.getFileId()+"&repId="+entry.getLibraryId()+"&fileName="+entry.getLabel()+"&endpointName=connections";}]]></xp:this.value>
			</xp:link>
		</xp:column>
		<xp:column id="column2">
			<xp:this.facets>
				<xp:label value="Author" id="label2" xp:key="header"></xp:label>
			</xp:this.facets>
			<xp:text escape="true" id="computedField2"
				value="#{javascript:entry.getAuthor().getName()}">
			</xp:text>
		</xp:column>
		<xp:column id="column3">
			<xp:this.facets>
				<xp:label value="Created" id="label3" xp:key="header"></xp:label>
			</xp:this.facets>
			<xp:text escape="true" id="computedField3"
				value="#{javascript:entry.getCreated()}">
			</xp:text>
		</xp:column>
		<xp:column id="column4">
			<xp:text escape="true" id="computedField4"
				value="#{javascript:entry.getSize()/1000}">
				<xp:this.converter>
					<xp:convertNumber type="number"
						integerOnly="false">
					</xp:convertNumber>
				</xp:this.converter>
			</xp:text>
			<xp:this.facets>
				<xp:label value="Size (KB)" id="label4"
					xp:key="header">
				</xp:label>
			</xp:this.facets>
		</xp:column>
	</xp:dataTable>

</xp:view>

That’s it! Now what exactly is happening here? Well, first of all we define the data source for our data table in line 7. This data source comes straight from our Bean and is our FileList object. We define a variable called “entry” in line 5 that allows us to access all methods the FileList object provides. We then use the entry variable to access the file values like getLabel() – Filename and getAuthor() – Person who submitted the file. Check the SBT API documentation to find out which methods each and every object provides. The documentation comes with the SBT. The data table does the rest and iterates through all files. Here is what it looks like with a little bit of css Ashampoo_Snap_2013.12.20_14h28m04s_008_



---------------------
http://www.schmhen.de/2014/02/18/first-project/
Feb 18, 2014
3 hits



Recent Blog Posts




Created and Maintained by Yancy Lent - About - Planet Lotus Blog - Advertising - Mobile Edition