This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal



Apr 27, 2011, 3:12 PM
63 Posts
topic has been resolvedResolved

JSF JavaBean does not work for Xpages (What Gives)

  • Category: Managed Beans in NSF
  • Platform: Windows
  • Release: 8.5.2
  • Role: Developer
  • Tags: JSF Vs Xpages JavaBeans
  • Replies: 10

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:-)
May 3, 2011, 5:42 PM
11 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
First of all, I've never used java beans before, but I'm missing something in your code.
 
Your datatable references to 'Books.books'. I would try to change that to 'Books.getBooks()', because your bean does only have a.getBooks()' method.
  
May 6, 2011, 7:15 PM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Thanks Ferry for your input...
 
Yes, I did try your option prior to posting this, and Xpages is unhappy:
 

<xp:dataTable rows="5" id="bookTable" var="book" value="#{Books.getBooks()}"

 
the underline signifies the error.  But I am going to start looking elsewhere, perhaps Xpages wants to load data slighly different from JSF, not sure if that makes sense.
 
In a bit, thanks!
 
Köll 
May 6, 2011, 8:43 PM
39 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)

This would work, but you would have to preface it in the XSP differently.
 
You could say

<xp:dataTable rows="5" id="bookTable" var="book" value="#{javascript:Books.getBooks();}"

But the example below is accurate, if you have a setBooks() method you can use the EL reference.

Let me know if you have any questions, I basically have been trying to treat Xpages as a JSF implementation for Lotus Notes which basically means I almost strictly use Java instead of using SSJS.

Thanks
-Toby

May 7, 2011, 6:14 AM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Toby, you're a person after my own heart...  I am actually gearing towards more Java than SSJS, as an attempt to keep Apps scallable; just in case our organization need to mingle with other platforms.  I have been cheating a little by converting SSJS code to Java, been successful thus far;-)  if you have not tried this, I say give it a whirl.
 
Also toying with the idea of throwing JavaAgents or (Java) Script Libs into a jar files, access them through managed beans or some type, feed data into Xpages that way.  
 
Thanks for your input, not sure why I did not think of this... will give it a go...
 
L8ter! 
May 7, 2011, 11:40 PM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Greetings Toby!
 
Decided to see what XSP has for me, not sure where to look.  Will attempt to add an attachment, which of the libraries should I use from XSP.  I am currently toying with XSPContext to see what I can achieve.
 
Köll 
May 9, 2011, 2:45 PM
39 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Hi,
 
Mark was kind enough to help me out when I was trying to use File Uploads with Managed Beans...He wrote a nice Blog post about it.

http://www.bleedyellow.com/blogs/andyc/entry/intercepting_file_uploads_with_java_example?lang=en
 
This should be enough to get you started.  Let me know if you need some more advice.  Thanks

-Toby
May 10, 2011, 1:00 PM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Very cool Sir...  I can truly use this in the current App...  what I meant was, I was going to add an image attachment of the XSP lib items from DDE to tell me what to use with javascript:Books.getBooks();
 
But you accidentally gave me something I needed...  I do have a need to upload the XML file back into the App.  And incidentally, my next lesson with my sons is 'file uploads' (teaching them Information technology), should help show them what goes into the gui that uploads the file...
 
With the current, javascript:Books.getBooks(); return no data, I think you mentioned having to do soemthing in XSP. 
 
Need help to figure out what to use to get it to work:-)
May 3, 2011, 5:47 PM
1 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
You need to have a 'setBooks' method in order for it to be a bean... Each property must have a getter and a setter.
May 6, 2011, 7:22 PM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)
Hey Dan!
 
Thanks for your input; I get them mixed up now and then...
 
Attended an IBM seminar recently, it sounded like the JSF stuff is not as avaialable to us for Xpages Apps as it is for actual JSF Apps.  Pulling all the stops on this one, especialy that it works as a JSF App. 
 
Since you seem knowledgable, care to throw some sense into, it is probably simple...
 
Have a great week-end! 
 
Köll 
May 18, 2011, 3:46 PM
63 Posts
Re: JSF JavaBean does not work for Xpages (What Gives)

Found a wonderful post, one of many added by Karsten Lehmann, that does a good job bringing JSF to light for Xpages.  I will be working with it to salvage code and resolve the above captioned issue.

 

Just in case of errors, be prepared to modify your ACL...  If the ACL does not have the specific access to Create Docs and so on, the project will not submit, nor can you Edit successfully.

 

Here is the post: 

Have a great week!


This forum is closed to new posts and responses. Individual names altered for privacy purposes. The information contained in this website is provided for informational purposes only and should not be construed as a forum for customer support requests. Any customer support requests should be directed to the official HCL customer support channels below:

HCL Software Customer Support Portal for U.S. Federal Government clients
HCL Software Customer Support Portal