FAQ
Hi to all,

I am a newbie (sorry :)).
I spend two days to learn something about jsf and myfaces component.
I have some problem with resultset object and dataTable with dataScroller.
I get an error about division by zero.
May be mysql driver problem?

Many thanks in advance

regards Lorenzo

Search Discussions

  • Lorenzo Sicilia at May 23, 2005 at 8:31 am
    sorry , it's monday. :)
    I forget some info:
    - I get the error about division by zero if I use jstl recordset.
    - I tried with result too but in my x:dataTable I can see any result.

    my faces-config.xml:
    <managed-bean>
    <description>userComunity table</description>
    <managed-bean-name>userComunity</managed-bean-name>
    <managed-bean-class>it.kemen.jsf.UserComunity</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

    my test class:

    package it.kemen.jsf;

    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;

    import javax.faces.component.UIData;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;

    public class UserComunity {
    private DataSource ds;
    private UIData userComunityTable;

    public UserComunity() {

    System.out.println("UserComunity start" );
    try {
    Context context = new InitialContext();
    ds = (DataSource) context.lookup("java:comp/env/croxit");
    } catch (NamingException e) {
    ds = null;
    System.out.println("NamingException" + e);
    }

    }

    public ResultSet getList() {
    ResultSet result = null;
    try {

    System.out.println("UserComunity getList" );
    Connection conn = ds.getConnection();
    Statement stmt =
    conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    result = stmt.executeQuery("SELECT * FROM `user_comunity`");
    } catch (Exception e) {
    System.out.println("sql Exception: " + e);
    }
    return result;
    }

    public UIData getUserComunityTable()
    {
    return userComunityTable;
    }

    public void setUserComunityTable(UIData userComunityTable)
    {
    this.userComunityTable = userComunityTable;
    }

    }


    my jsf snippets:

    <x:dataTable id="myTable2" var="row" value="#{userComunity.list}" >
    <h:column>
    <h:outputText value="#{row.nick_name}"/>
    </h:column>
    <h:column>
    <h:outputText value="#{row.firstname}"/>
    </h:column>
    <h:column>
    <h:outputText value="#{row.lastname}"/>
    </h:column>
    </x:dataTable>

    any idea or link with a good howto about jdbc result?

    tks

    Lorenzo
  • Sylvain Vieujot at May 23, 2005 at 5:32 pm
    I think it may have something to do with the ResultSetDataModel class
    not being implemented yet :

    http://svn.apache.org/viewcvs.cgi/myfaces/trunk/src/jsfapi/javax/faces/model/ResultSetDataModel.java?view=markup

    Sylvain.
    On Mon, 2005-05-23 at 10:31 +0200, Lorenzo Sicilia wrote:

    sorry , it's monday. :)
    I forget some info:
    - I get the error about division by zero if I use jstl recordset.
    - I tried with result too but in my x:dataTable I can see any result.

    my faces-config.xml:
    <managed-bean>
    <description>userComunity table</description>
    <managed-bean-name>userComunity</managed-bean-name>
    <managed-bean-class>it.kemen.jsf.UserComunity</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>

    my test class:

    package it.kemen.jsf;

    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;

    import javax.faces.component.UIData;
    import javax.naming.Context;
    import javax.naming.InitialContext;
    import javax.naming.NamingException;
    import javax.sql.DataSource;

    public class UserComunity {
    private DataSource ds;
    private UIData userComunityTable;

    public UserComunity() {

    System.out.println("UserComunity start" );
    try {
    Context context = new InitialContext();
    ds = (DataSource) context.lookup("java:comp/env/croxit");
    } catch (NamingException e) {
    ds = null;
    System.out.println("NamingException" + e);
    }

    }

    public ResultSet getList() {
    ResultSet result = null;
    try {

    System.out.println("UserComunity getList" );
    Connection conn = ds.getConnection();
    Statement stmt =
    conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
    result = stmt.executeQuery("SELECT * FROM `user_comunity`");
    } catch (Exception e) {
    System.out.println("sql Exception: " + e);
    }
    return result;
    }

    public UIData getUserComunityTable()
    {
    return userComunityTable;
    }

    public void setUserComunityTable(UIData userComunityTable)
    {
    this.userComunityTable = userComunityTable;
    }

    }


    my jsf snippets:

    <x:dataTable id="myTable2" var="row" value="#{userComunity.list}" >
    <h:column>
    <h:outputText value="#{row.nick_name}"/>
    </h:column>
    <h:column>
    <h:outputText value="#{row.firstname}"/>
    </h:column>
    <h:column>
    <h:outputText value="#{row.lastname}"/>
    </h:column>
    </x:dataTable>

    any idea or link with a good howto about jdbc result?

    tks

    Lorenzo

  • Lorenzo Sicilia at May 24, 2005 at 4:13 am

    Sylvain Vieujot wrote:
    I think it may have something to do with the ResultSetDataModel class
    not being implemented yet :

    http://svn.apache.org/viewcvs.cgi/myfaces/trunk/src/jsfapi/javax/faces/model/ResultSetDataModel.java?view=markup
    thanks Sylvain for the answer.
    Anyway if I need get some data from a database with jsf I have any chance?

    Or I need a translator class from ResultSet to List?

    many thanks in advance

    Regards Lorenzo
  • Alex at May 24, 2005 at 5:39 am

    Lorenzo Sicilia wrote:

    Anyway if I need get some data from a database with jsf I have any chance?
    Or I need a translator class from ResultSet to List?
    Hi,

    you could either use jdbc or jdo. With jdbc you would have to iterate
    over the resultset, create an object and put this in a list and then
    return the list. JDO returns a collection instead of a resultset. I use
    JDO at the moment. Maybe have a look at www.jpox.org

    Regards
    Alex
  • Lorenzo Sicilia at May 24, 2005 at 6:03 am

    alex wrote:
    you could either use jdbc or jdo. With jdbc you would have to iterate
    over the resultset, create an object and put this in a list and then
    return the list.
    ok, I understand.
    JDO returns a collection instead of a resultset. I use
    JDO at the moment. Maybe have a look at www.jpox.org
    Can I do this task with hibernate, too?

    regards Lorenzo
  • Alex at May 24, 2005 at 6:18 am

    Lorenzo Sicilia wrote:

    Can I do this task with hibernate, too?

    Although I've never worked with hibernate, I think you can. A friend of
    mine did so. Depends on the design of your application :)
  • Lorenzo Sicilia at May 24, 2005 at 6:48 am

    alex wrote:
    Lorenzo Sicilia wrote:
    Can I do this task with hibernate, too?


    Although I've never worked with hibernate, I think you can. A friend of
    mine did so. Depends on the design of your application :)
    ok, I will try :)

    many thanks for usefull the answers

    regards Lorenzo
  • Ricardo R. Ramírez Valenzuela at May 24, 2005 at 2:15 pm
    I think per the specification you should be able to use the resultset
    directly into the datatable.
    Not that it is a good idea, tough.
    Hi,

    you could either use jdbc or jdo. With jdbc you would have to iterate
    over the resultset, create an object and put this in a list and then
    return the list. JDO returns a collection instead of a resultset. I
    use JDO at the moment. Maybe have a look at www.jpox.org

    Regards
    Alex
  • Martin Marinschek at May 24, 2005 at 6:15 pm
    Well, if the ResultSetDataModel was implemented, this would work...

    regards,

    Martin
    On 5/24/05, "Ricardo R. Ramírez Valenzuela" wrote:
    I think per the specification you should be able to use the resultset
    directly into the datatable.
    Not that it is a good idea, tough.
    Hi,

    you could either use jdbc or jdo. With jdbc you would have to iterate
    over the resultset, create an object and put this in a list and then
    return the list. JDO returns a collection instead of a resultset. I
    use JDO at the moment. Maybe have a look at www.jpox.org

    Regards
    Alex
  • Balaji Saranathan at May 26, 2005 at 2:59 pm
    Hi,

    I'm having a trouble running the myfaces examples in tomcat 5.5.4.
    Does anyone have the same issue?. I just get a blank screen.

    Thanks




    Confidentiality Notice

    The information contained in this electronic message and any attachments to this message are intended
    for the exclusive use of the addressee(s) and may contain confidential or privileged information. If
    you are not the intended recipient, please notify the sender at Wipro or Mailadmin@wipro.com immediately
    and destroy all copies of this message and any attachments.
  • Bruno Aranda at May 26, 2005 at 3:13 pm
    Balaji,
    As pointed in the myfaces FAQ (jsp-2.0.jar and commons-el.jar of the
    folder WEB-INF/lib),
    remove jsp-2.0.jar and commons-el.jar of the folder WEB-INF/lib of the
    examples war...

    Bruno

    2005/5/26, Balaji Saranathan <balaji.saranathan@wipro.com>:

    Hi,

    I'm having a trouble running the myfaces examples in tomcat 5.5.4.
    Does anyone have the same issue?. I just get a blank screen.

    Thanks

    Confidentiality Notice

    The information contained in this electronic message and any attachments
    to this message are intended
    for the exclusive use of the addressee(s) and may contain confidential or
    privileged information. If
    you are not the intended recipient, please notify the sender at Wipro or
    Mailadmin@wipro.com immediately
    and destroy all copies of this message and any attachments.
  • Bruno Aranda at May 26, 2005 at 3:14 pm
    Well, my Ctr+C mistake, the FAQ is in
    http://myfaces.apache.org/docs/faq.html...

    Bruno

    2005/5/26, Bruno Aranda <brunoaranda@gmail.com>:
    Balaji,
    As pointed in the myfaces FAQ (jsp-2.0.jar and commons-el.jar of the
    folder WEB-INF/lib), remove jsp-2.0.jar and commons-el.jar of the folder WEB-INF/lib
    of the examples war...

    Bruno

    2005/5/26, Balaji Saranathan <balaji.saranathan@wipro.com>:

    Hi,

    I'm having a trouble running the myfaces examples in tomcat 5.5.4.
    Does anyone have the same issue?. I just get a blank screen.

    Thanks

    Confidentiality Notice

    The information contained in this electronic message and any attachments
    to this message are intended
    for the exclusive use of the addressee(s) and may contain confidential
    or privileged information. If
    you are not the intended recipient, please notify the sender at Wipro or
    Mailadmin@wipro.com immediately
    and destroy all copies of this message and any attachments.
  • Alex at May 23, 2005 at 8:42 am

    Lorenzo Sicilia wrote:

    I get an error about division by zero.
    Hi Lorenzo,

    you have to set the rows-attribute in the x:dataTable, so that the table
    knows, how much rows to display for every scrolled page. If the rows are
    not set, you get the above described error.

    <x:dataTable value="bean.someValue" var="item" rows="10">
    ....

    </x:dataTable>

    Rgds Alex
  • Lorenzo Sicilia at May 23, 2005 at 8:58 am

    alex wrote:
    Lorenzo Sicilia wrote:
    I get an error about division by zero.
    Hi Lorenzo,

    you have to set the rows-attribute in the x:dataTable, so that the table
    knows, how much rows to display for every scrolled page. If the rows are
    not set, you get the above described error.

    <x:dataTable value="bean.someValue" var="item" rows="10">
    ....

    </x:dataTable>
    tks, now with jstl resultset it works fine.

    I try with jdbc result set:
    <x:dataTable id="myTable1" var="row" value="#{userComunity.list}"
    rows="10" >
    <h:column>
    <h:outputText value="#{row.nick_name}"/>
    </h:column>
    </x:dataTable>

    but my html it's empty.I am sure that my sql works because getList() it
    called.

    About "division by zero" maybe a default value it'a good idea.

    regards Lorenzo
  • Alex at May 23, 2005 at 9:28 am

    Lorenzo Sicilia wrote:

    but my html it's empty.I am sure that my sql works because getList()
    it called.
    *ResultSetDataModel* is a convenience implementation of |DataModel|
    <http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/javax/faces/model/DataModel.html>
    that wraps a |ResultSet| of Java objects. Note that the specified
    ResultSet| *MUST* be scrollable. In addition, if input components (that
    will be updating model values) reference this object in value binding
    expressions, the specified |ResultSet| *MUST* be updatable.

    have a look at the api, sometimes this helps ;)

    http://java.sun.com/j2ee/javaserverfaces/1.1_01/docs/api/index.html

    Rgds
    Alex

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupusers @
categoriesmyfaces
postedMay 23, '05 at 8:22a
activeMay 26, '05 at 3:14p
posts16
users7
websitemyfaces.apache.org

People

Translate

site design / logo © 2019 Grokbase