Hey Gang!
I did post this elsewhere, hoping I get some hits from you...
Looks like I should be able to treat Xpages pretty much like JSF when writing beans and so on...
I am concerned about a certain JavaBean that works well in App built on Eclispe Ganymede (personal project), but does not work in Xpages. Would you have a look and see what I may be missing.
I will simply post the URL where I got the code, below has been modifed to look at Notes data. Kudos by the way to the person who wrote: [url=http://srikanthtechnologies.com/blog/java/xml_jsf_datatable.html]http://srikanthtechnologies.com/blog/java/xml_jsf_datatable.html[/url]
Here is the XML:
[CODE]
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:dataTable rows="5" id="bookTable" var="currentBook" value="#{Books.books}"
style="width:50%">
<xp:this.facets>
<xp:pager layout="Previous Group Next" xp:key="header"
id="pager1" for="bookTable">
</xp:pager>
<xp:pager layout="Previous Group Next" xp:key="footer"
id="pager2" for="bookTable" partialRefresh="true">
</xp:pager>
</xp:this.facets>
<xp:column id="titleColumn">
<xp:text escape="true" id="titleField"
value="#{currentBook.title}">
</xp:text>
</xp:column>
<xp:column id="authorColumn">
<xp:text escape="true" id="authorField"
value="#{currentBook.author}">
</xp:text>
</xp:column>
<xp:column id="priceColumn">
<xp:text escape="true" id="priceField"
value="#{currentBook.price}">
</xp:text>
</xp:column>
</xp:dataTable>
</xp:view>
[/CODE]
JavaBean
+++++++++++++++++++++++++++++++++++++++++++++++++++>>
[CODE]
public class Book {
private String title, author;
private int price;
public Book() {}
public Book(String title, String author, int price) {
this.title= title;
this.author = author;
this.price = price;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
}
[/CODE]
Backing Bean
+++++++++++++++++++++++++++++++++++++++++++++>>
[CODE]
import java.io.File;
import java.util.ArrayList;
import javax.faces.context.FacesContext;
import javax.servlet.ServletContext;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Books {
public ArrayList<Book> getBooks() {
ArrayList<Book> al = new ArrayList<Book>();
Book b;
// read data from XML file
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Document document;
try {
DocumentBuilder builder = factory.newDocumentBuilder();
// get physical path for BOOKS.XML. First get access to ServletContext using FacesContext
ServletContext context = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String filepath = context.getRealPath("books.xml"); // get physical path for /books.xml
document = builder.parse( new File(filepath));
Element root = document.getDocumentElement();
NodeList books = root.getChildNodes();
for (int i = 0 ; i < books.getLength(); i ++)
{
// skip the rest if node is not an elemtn
if ( books.item(i).getNodeType() != Node.ELEMENT_NODE)
continue;
NodeList bookdetails = books.item(i).getChildNodes();
// create a book with the data from book element in XML document
b = new Book( bookdetails.item(1).getTextContent(),
bookdetails.item(2).getTextContent(),
Integer.parseInt(bookdetails.item(3).getTextContent())) ;
al.add(b); // add book to ArrayList
}
return al;
}
catch (Exception e) {
System.out.println("\n** Parsing error" + ", line " + e.getMessage());
return null;
}
}
}
[/CODE]
WebXML
++++++++++++++++++++++++++++++++++++++++++++++++>>
[CODE]
<managed-bean>
<managed-bean-name>Books</managed-bean-name>
<managed-bean-class>com.osc.blackberry.test.Books</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
</managed-bean>
[/CODE]
What are your thoughts, I tried everything; could be my lack of Xpages knowledge here... Any help you can provide is helpful...
Köll
PS. tried to make this look pretty with code tags, to no avail:-)