Knowledge Sharing:
JavaBean/Backing Bean
Search NSF with Links on form
Xpages
System Requirements:
Download Domino Designer 8.5.2 Environment (DDE)
http://www.ibm.com/developerworks/downloads/ls/dominodesigner/
Introduction:
Build a connection to a Lotus Notes Domino Database located on C Drive using a JavaBean, Backing Bean. Once connection is established, grab view data and load to Xpages form. Search for unique documents using links on the page.
Disclaimer:
Information contained in the following is presented as is. This tutorial assumes you have basic programming knowledge. All tutorials are based on an Eclipse/Eclipse-based software. Should you need to familiarize yourself with a certain Eclipse environment, prior to continuing this tutorial, please stop now and see our Tutorials page...
Build Results into Xpages
At this point we assume Domino Designer 8.5.2 is downloaded/installed and a new JavaBean, Backing Bean, and the Xpage are already created. Copy and paste below code to your environment for each code samples.
Keyword.java
[CODE]
/**
*Copyright2012 DököllSolutions,Inc.
Licensedunder theApacheLicense,Version 2.0(the"License");
youmay notuse thisfile exceptincompliancewith theLicense.
Youmay obtaina copyof theLicense at
http://www.apache.org/licenses/LICENSE-2.0
Unlessrequired byapplicablelaw oragreed toin writing,software
distributedunder theLicense isdistributedon an"ASIS"BASIS,
WITHOUTWARRANTIESORCONDITIONSOF ANYKIND,eitherexpress orimplied.
Seethe Licensefor thespecificlanguagegoverningpermissionsand
limitationsunder theLicense.
*
*@AppName:Docu.nsf
*Program:Keyword.java
*Created:2011.02.10.9.21.AM
*JavaBeanClass toload viewdata toXpages
*
*Modified:2011.11.27.7.24.PM
*Addingactual datafrom aview
*
*Modified toaddadditionalfield'BrowserURL'
*2012.03.01.12.30.PM
*/
packagecom.dokoll.solutions.inc.JavaBeans;
/**
*@authorDököllSolutions,Inc.
*@version:2011.02.10.9.17.AM
*/
publicclassKeyword {
privateString Category;
privateString Topic;
privateString BrowserURL;
// getter/setter methods
/**
* @returnthetopicName
*/
publicString getTopic() {
returnTopic;
}
/**
* @paramtopicName
*thetopicNameto set
*/
publicvoidsetTopic(String topic) {
this.Topic= topic;
}
/**
* @paramcategoryName
*thecategoryNameto set
*/
publicvoidsetCategory(String category) {
this.Category= category;
}
/**
* @returnthecategoryName
*/
publicString getCategory() {
returnCategory;
}
/**
* @returnthebrowserURL
*/
publicString getBrowserURL() {
returnBrowserURL;
}
/**
* @parambrowserURL
*thebrowserURLto set
*/
publicvoidsetBrowserURL(String browserURL) {
BrowserURL= browserURL;
}
//call this method from the backing bean
publicKeyword(String Category, String Topic, String BrowserURL) {
this.Category= Category;
this.Topic= Topic;
this.BrowserURL= BrowserURL;
}
}
Backing Bean it!
Your JavaBean has been created, and we assume it compiles okay. You are now ready to plug in a Backing Bean to load data to Xpages. Copy and paste below to your environment, areas of interest have been highlighted for your convenience.
RetrieveNewNoticeBackingBean.java
/**
*Copyright2012 DököllSolutions,Inc.
Licensedunder theApacheLicense,Version 2.0(the"License");
youmay notuse thisfile exceptincompliancewith theLicense.
Youmay obtaina copyof theLicense at
http://www.apache.org/licenses/LICENSE-2.0
Unlessrequired byapplicablelaw oragreed toin writing,software
distributedunder theLicense isdistributedon an"ASIS"BASIS,
WITHOUTWARRANTIESORCONDITIONSOF ANYKIND,eitherexpress orimplied.
Seethe Licensefor thespecificlanguagegoverningpermissionsand
limitationsunder theLicense.
*Program:RetrieveNewNoticeBackingBean.java
*Created:2011.01.28.3.31.PM
*NewRetrievalBean forXpages
*Modified:2011.01.31.2.22.PM
*Modified toadd Debugvariables
*Modified toadd URLreference,additionalfield'BrowserURL',UniversalIDcall
*2012.03.01.12.37.PM
*Modified toAdd Servercalls toensure therightserver isloaded
*this alsohelps inthe casethe appis viewedin theClient sideof Notes
*TO DO:Add:ClientTypeto ensurewhere usersare comingfrom
*2012.03.02.3.49.PM
*
*/
packagecom.osc.its.bulletin.board.JavaBeans;
importjavax.faces.context.FacesContext;
importjavax.servlet.http.HttpServletRequest;
importlotus.domino.View;
importlotus.domino.local.Database;
importlotus.domino.local.Document;
importcom.dokoll.solutions.inc.JavaBeans.Keyword;
/**
*@authorDököll Solutions, Inc.
*@version2011.01.28.3.31.PM
*
*/
publicclassRetrieveNewNoticeBackingBean {
// declare variables
finalString DB_LOAD= "Docu.nsf/";
// Added Server calls
// 2012.03.02.3.44.PM
// declare variable for localhost Server
finalString LOCAL_LOAD= "http://localhost/";
finalString ViewName= "By Category";
// Get Keyword collection
publicKeyword[] getKeywords() {
// Declare Keyword Array
Keyword[] keywords = null;
try{
// 2011.02.10.9.37.AM
// get the current database being used
Database database = (Database) FacesContext.getCurrentInstance()
.getApplication().getVariableResolver().resolveVariable(
FacesContext.getCurrentInstance(),"database");
// Call HTTP ServletClass to render a Server Name
// 2012.03.02.4.00.PM
HttpServletRequest httpServletRequest = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
// declare String to hold the ServerName
StringDB_SERVER = httpServletRequest.getServerName();
// Get the full URL and join it with the current document to grab
// from Notes back-end
// 2012.03.02.8.47.PM
HttpServletRequest req = (HttpServletRequest) FacesContext
.getCurrentInstance().getExternalContext().getRequest();
StringbaseURL = req.getRequestURL().toString().replace(
req.getRequestURI().substring(1), req.getContextPath());
// Above does not work in Notes Client, we get below error
// Error 404: ProxyServlet:
// //xsp/Docu.nsf/By%20Category/464A7E820B12313A85257849005B8BFE
// 2012.03.02.9.05.PM
// TO DO: Call the right server via facesContext and tack that
// onto the URL... pull up folders as well (hasNext)
// 2012.03.02.4.08.PM
// Grab a collection of all Keyword documents
View view = database.getView(ViewName);
System.out.println("View Obtained..." + view);
Document sDoc;
Document ndoc;
sDoc = (Document) view.getFirstDocument();
System.out.println("Document Obtained..." + sDoc);
// Begin initialization of the Keywords Array
// load documents count
keywords = newKeyword[view.getEntryCount()];
// Run through Keyword document collection
intdocount = 0;
while(sDoc != null) {
Keyword keyword = newKeyword(null,null,null);
// render document values to variables of
// Keyword object
keyword.setCategory(sDoc.getItemValueString("Categories"));
keyword.setTopic(sDoc.getItemValueString("Subject"));
// TO DO: Alternatively, add baseURL variable in the place of
// DB_LOAD and LOCAL_LOAD. This works best in a web Browser...
keyword.setBrowserURL(LOCAL_LOAD+DB_LOAD+view+"/"+sDoc.getUniversalID()
+"?OpenDocument");
// Send Keyword object into Keywords Array
keywords[docount] = keyword;
// increment counts
docount += 1;
// load next doc
ndoc = (Document) view.getNextDocument(sDoc);
sDoc = ndoc;
}
// return the Array
returnkeywords;
}catch(Exception e) {
e.printStackTrace();
}
returnnull;
}
}
Build Xpage file
Full code added below, jump ahead if necessary, but do read the steps, we will be using a link component and throw an URL underneath to allow unique documents to be viewed. Areas of interest have been highlighted for your convenience.
Steps:
Go to DDE's Database Navigator to your upper left
Double-click XPages, then click New XPage button
Code is generated, drag a link component from Core Controls Window
Select the link, Go to Properties Tab below to modify/add items
Your code should look bellow sample, (image at your choosing)...
Code to be modified
<xp:linkescape="true"text="Link"id="link1"title="Testing Links"
value="http://dokollsolutionsinc.com">
<xp:imageid="image1"url="/act_scheduler.gif"></xp:image>
</xp:link>
Go to the Backing Bean, try to understand how the URL is created
Make a note of the variable 'browserURL' to see how it connects to the Xpages form
// declare variables
finalString DB_LOAD= "Docu.nsf/";
finalString LOCAL_LOAD= "http://localhost/";
…
…
view = database.getView(ViewName);
Document sDoc;
…
…
setBrowserURL(LOCAL_LOAD+DB_LOAD+view+"/"+sDoc.getUniversalID()
+"?OpenDocument");
TIP:browserURLvariable was declared in the Keyword JavaBean:
Keyword keyword = newKeyword(null,null,null);
Modify test Xpage, remove information entered earlier
Copy dataSource and field name from Topic column '#{categoryTable.topic}'
Replace Link in text="Link"with the dataSource
Copy #{javascript:categoryTable.browserURL}dataSource
Replace value="http://dokollsolutionsinc.com"
*Your code should look as below...
Code modified
<xp:linkescape="true"text="#{categoryTable.topic}"id="link2"
value="#{javascript:categoryTable.browserURL}"/>
See original code for added information.
xpbycategory.xsp
<?xmlversion="1.0"encoding="UTF-8"?>
<xp:viewxmlns:xp="http://www.ibm.com/xsp/core">
<xp:dataTablerows="15"id="dataTable1"var="categoryTable"
value="#{javascript:RetrieveNewNoticeBackingBean.getKeywords()}"
style="width:80.0%;background-color:rgb(220,237,237)">
<xp:this.facets>
<xp:pagerpartialRefresh="true"
layout="FirstImage PreviousImage SeparatorPage Group NextImage LastImage"
xp:key="header"id="pager1"for="dataTable1"
style="color:rgb(0,64,64);font-weight:bold;background-position:top center" />
<xp:pagerpartialRefresh="true"
layout="FirstImage PreviousImage SeparatorPage Group NextImage LastImage"
xp:key="footer"id="pager2"for="dataTable1"title="By Category"
style="color:rgb(0,64,64);font-weight:bold;background-position:top center" />
</xp:this.facets>
<xp:columnid="column3">
<xp:this.facets>
<xp:labelid="label1"xp:key="header"
style="font-weight:bold;font-family:Arial Black;font-size:14pt;background-color:rgb(220,237,237);color:rgb(0,64,0)"for="image1"value="File"/>
</xp:this.facets>
<xp:linkescape="true"id="link1"
style="text-align:center;background-position:center center;width:88.0px">
<xp:this.value>
<![CDATA[#{javascript:categoryTable.browserURL}]]>
</xp:this.value>
<xp:imageid="image1"url="/search.gif"alt="View File"
style="align:center"/>
</xp:link>
</xp:column>
<xp:columnid="column1">
<xp:this.facets>
<xp:labelvalue="Subject"id="topic1"xp:key="header"style="font-weight:bold;font-family:Arial Black;font-size:14pt;background-color:rgb(220,237,237);color:rgb(0,64,0)"/>
</xp:this.facets>
<xp:textescape="true"id="computedField3"value="#{categoryTable.topic}"
style="color:rgb(64,0,0)"/>
</xp:column>
<xp:columnid="column2">
<xp:this.facets>
<xp:labelvalue="Category"id="category1"xp:key="header"style="font-weight:bold;font-family:Arial Black;font-size:14pt;background-color:rgb(220,237,237);color:rgb(0,64,0)"/>
</xp:this.facets>
<xp:textescape="true"id="computedField2"value="#{categoryTable.category}"
style="color:rgb(64,0,0)"/>
</xp:column>
</xp:dataTable>
</xp:view>
Conclusion:
You can now essentially have user clicks on an image from the Xpage to load unique documents or you can make links with the unique dataSource values returned.
Added info:You will need to reference RetrieveNewNoticeBackingBean.java in your faces-config.xml file