You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Pichai Ongvasith <pi...@gmail.com> on 2006/01/01 05:21:20 UTC

HtmlTableRendererBase and ResultSetDataModel

Hello,

I tried to use a ResultSetDataModel as the data model for <t:dataTable>, 
with myfaces1.1.1. It turns out that the result never shows up in the table.
My guess is that this might be related to Jira issue MYFACES-278.

Looking into the source code, I guess 
HtmlTableRendererBase.encodeInnerHtml is doing the job to render the 
result set.
this is the excerpt of relevant code.
        int first = uiData.getFirst();
        int rows = uiData.getRows();
        int rowCount = uiData.getRowCount();
        if (rows <= 0)
        {
            rows = rowCount - first;
        }
        int last = first + rows;
        if (last > rowCount)
            last = rowCount;

        for (int i = first; i < last; i++)
        {           
             // render
        }

If that's true, the method might be mishandling the uiData.getRowCount.
The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 
always return -1, which is valid when the row count is unknown at the 
time. So before the rendering loop, last is always -1, and nothing would 
be rendered.
 
Or am I missing something here?

pichai


Re: HtmlTableRendererBase and ResultSetDataModel

Posted by Martin Marinschek <ma...@gmail.com>.
P.S.:

this is out of UIData

regards,

Martin

On 1/1/06, Martin Marinschek <ma...@gmail.com> wrote:
> You are right. There is something broken here.
>
> The encodeInnerHTML method should work just like the following code:
>
>         int first = getFirst();
>         int rows = getRows();
>         int last;
>         if (rows == 0)
>         {
>             last = getRowCount();
>         }
>         else
>         {
>             last = first + rows;
>         }
>         for (int rowIndex = first; last==-1 || rowIndex < last; rowIndex++)
>         {
>             setRowIndex(rowIndex);
>
>             //scrolled past the last row
>             if (!isRowAvailable())
>                 break;
>
>             for (Iterator it = getChildren().iterator(); it.hasNext();)
>             {
>                 UIComponent child = (UIComponent) it.next();
>                 if (child instanceof UIColumn)
>                 {
>                     if (!child.isRendered())
>                     {
>                         //Column is not visible
>                         continue;
>                     }
>                     for (Iterator columnChildIter = child.getChildren()
>                             .iterator(); columnChildIter.hasNext();)
>                     {
>                         UIComponent columnChild = (UIComponent) columnChildIter
>                                 .next();
>                         process(context, columnChild, processAction);
>                     }
>                 }
>             }
>         }
>
> regards,
>
> Martin
> On 1/1/06, Mike <ap...@amcgrath.org> wrote:
> >  Hi Pichai,
> >
> >  I had tried to use a resultset for a Data Table too, but was never able to
> > get it to work. Once I switched to another data model, it worked instantly.
> > The Apache site still says that the ResultSet isn't yet supported.
> >
> >  From:
> > http://myfaces.apache.org/tomahawk/extDataTable.html:
> >
> >  What data types are supported?
> >  To be able to save the state of the DataModel the row objects must be
> > serializable. All standard DataModel types are supported, except ResultSet,
> > which will follow in one of the next releases,
> >
> >  HTH
> >
> >      Mike
> >
> >
> >
> >
> >  Pichai Ongvasith wrote:
> > Hello,
> >
> >  I tried to use a ResultSetDataModel as the data model for <t:dataTable>,
> > with myfaces1.1.1. It turns out that the result never shows up in the table.
> >  My guess is that this might be related to Jira issue MYFACES-278.
> >
> >  Looking into the source code, I guess
> > HtmlTableRendererBase.encodeInnerHtml is doing the job to
> > render the result set.
> >  this is the excerpt of relevant code.
> >         int first = uiData.getFirst();
> >         int rows = uiData.getRows();
> >         int rowCount = uiData.getRowCount();
> >         if (rows <= 0)
> >         {
> >             rows = rowCount - first;
> >         }
> >         int last = first + rows;
> >         if (last > rowCount)
> >             last = rowCount;
> >
> >         for (int i = first; i < last; i++)
> >         {                       // render
> >         }
> >
> >  If that's true, the method might be mishandling the uiData.getRowCount.
> >  The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 always
> > return -1, which is valid when the row count is unknown at the time. So
> > before the rendering loop, last is always -1, and nothing would be rendered.
> >
> >  Or am I missing something here?
> >
> >  pichai
> >
> >
> >
> >
> >
>
>
> --
>
> http://www.irian.at
>
> Your JSF powerhouse -
> JSF Consulting, Development and
> Courses in English and German
>
> Professional Support for Apache MyFaces
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: HtmlTableRendererBase and ResultSetDataModel

Posted by Martin Marinschek <ma...@gmail.com>.
You are right. There is something broken here.

The encodeInnerHTML method should work just like the following code:

        int first = getFirst();
        int rows = getRows();
        int last;
        if (rows == 0)
        {
            last = getRowCount();
        }
        else
        {
            last = first + rows;
        }
        for (int rowIndex = first; last==-1 || rowIndex < last; rowIndex++)
        {
            setRowIndex(rowIndex);

            //scrolled past the last row
            if (!isRowAvailable())
                break;

            for (Iterator it = getChildren().iterator(); it.hasNext();)
            {
                UIComponent child = (UIComponent) it.next();
                if (child instanceof UIColumn)
                {
                    if (!child.isRendered())
                    {
                        //Column is not visible
                        continue;
                    }
                    for (Iterator columnChildIter = child.getChildren()
                            .iterator(); columnChildIter.hasNext();)
                    {
                        UIComponent columnChild = (UIComponent) columnChildIter
                                .next();
                        process(context, columnChild, processAction);
                    }
                }
            }
        }

regards,

Martin
On 1/1/06, Mike <ap...@amcgrath.org> wrote:
>  Hi Pichai,
>
>  I had tried to use a resultset for a Data Table too, but was never able to
> get it to work. Once I switched to another data model, it worked instantly.
> The Apache site still says that the ResultSet isn't yet supported.
>
>  From:
> http://myfaces.apache.org/tomahawk/extDataTable.html:
>
>  What data types are supported?
>  To be able to save the state of the DataModel the row objects must be
> serializable. All standard DataModel types are supported, except ResultSet,
> which will follow in one of the next releases,
>
>  HTH
>
>      Mike
>
>
>
>
>  Pichai Ongvasith wrote:
> Hello,
>
>  I tried to use a ResultSetDataModel as the data model for <t:dataTable>,
> with myfaces1.1.1. It turns out that the result never shows up in the table.
>  My guess is that this might be related to Jira issue MYFACES-278.
>
>  Looking into the source code, I guess
> HtmlTableRendererBase.encodeInnerHtml is doing the job to
> render the result set.
>  this is the excerpt of relevant code.
>         int first = uiData.getFirst();
>         int rows = uiData.getRows();
>         int rowCount = uiData.getRowCount();
>         if (rows <= 0)
>         {
>             rows = rowCount - first;
>         }
>         int last = first + rows;
>         if (last > rowCount)
>             last = rowCount;
>
>         for (int i = first; i < last; i++)
>         {                       // render
>         }
>
>  If that's true, the method might be mishandling the uiData.getRowCount.
>  The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 always
> return -1, which is valid when the row count is unknown at the time. So
> before the rendering loop, last is always -1, and nothing would be rendered.
>
>  Or am I missing something here?
>
>  pichai
>
>
>
>
>


--

http://www.irian.at

Your JSF powerhouse -
JSF Consulting, Development and
Courses in English and German

Professional Support for Apache MyFaces

Re: HtmlTableRendererBase and ResultSetDataModel

Posted by Mike <ap...@amcgrath.org>.
*Hi Pichai,

I had tried to use a resultset for a Data Table too, but was never able 
to get it to work. Once I switched to another data model, it worked 
instantly. The Apache site still says that the ResultSet isn't yet 
supported.

From: **http://myfaces.apache.org/tomahawk/extDataTable.html: *
**
/What data types are supported?/*/
To be able to save the state of the DataModel the row objects must be 
serializable. All standard DataModel types are supported, except 
ResultSet, which will follow in one of the next releases,/

HTH

    Mike
*


Pichai Ongvasith wrote:
> Hello,
>
> I tried to use a ResultSetDataModel as the data model for 
> <t:dataTable>, with myfaces1.1.1. It turns out that the result never 
> shows up in the table.
> My guess is that this might be related to Jira issue MYFACES-278.
>
> Looking into the source code, I guess 
> HtmlTableRendererBase.encodeInnerHtml is doing the job to render the 
> result set.
> this is the excerpt of relevant code.
>        int first = uiData.getFirst();
>        int rows = uiData.getRows();
>        int rowCount = uiData.getRowCount();
>        if (rows <= 0)
>        {
>            rows = rowCount - first;
>        }
>        int last = first + rows;
>        if (last > rowCount)
>            last = rowCount;
>
>        for (int i = first; i < last; i++)
>        {                       // render
>        }
>
> If that's true, the method might be mishandling the uiData.getRowCount.
> The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 
> always return -1, which is valid when the row count is unknown at the 
> time. So before the rendering loop, last is always -1, and nothing 
> would be rendered.
>
> Or am I missing something here?
>
> pichai
>
>
>
>

Re: HtmlTableRendererBase and ResultSetDataModel

Posted by Pichai Ongvasith <pi...@gmail.com>.
Thanks you all for the comments and advice.

Now I know that I didn't do anything wrong on my part.
I just patched my own app, using the following code.
        int first = uiData.getFirst();
        int rows = uiData.getRows();
        int rowCount = uiData.getRowCount();
        int last = -1;
        if (rowCount > -1)
        {
            if (rows <= 0)
            {
                rows = rowCount - first;
            }
            last = first + rows;
            if (last > rowCount)
                last = rowCount;
        }
        else
        {
            if (rows > 0)
            {
                last = first + rows;
            }
        }

        for (int i = first; i < last || (last == -1) ; i++)

a bit verbose, but it serves my need and cover all cases I have.
Now everything works well. To be honest, I didn't use a 
ResultSetDataModel directly, but wrote my own DataModel to wrap an 
Iterator returned by Hibernate.  So the code above was not actually 
tested with ResultSetDataModel.
 
Thanks guys.

Simon Kitching wrote:

>On Sun, 2006-01-01 at 11:21 +0700, Pichai Ongvasith wrote:
>  
>
>>Hello,
>>
>>I tried to use a ResultSetDataModel as the data model for <t:dataTable>, 
>>with myfaces1.1.1. It turns out that the result never shows up in the table.
>>My guess is that this might be related to Jira issue MYFACES-278.
>>
>>Looking into the source code, I guess 
>>HtmlTableRendererBase.encodeInnerHtml is doing the job to render the 
>>result set.
>>this is the excerpt of relevant code.
>>        int first = uiData.getFirst();
>>        int rows = uiData.getRows();
>>        int rowCount = uiData.getRowCount();
>>        if (rows <= 0)
>>        {
>>            rows = rowCount - first;
>>        }
>>        int last = first + rows;
>>        if (last > rowCount)
>>            last = rowCount;
>>
>>        for (int i = first; i < last; i++)
>>        {           
>>             // render
>>        }
>>
>>If that's true, the method might be mishandling the uiData.getRowCount.
>>The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 
>>always return -1, which is valid when the row count is unknown at the 
>>time. So before the rendering loop, last is always -1, and nothing would 
>>be rendered.
>> 
>>Or am I missing something here?
>>    
>>
>
>It sure looks to me like the ResultSet support is broken. As you say,
>ResultSetDataModel.getRowCount always returns -1, so I can't see how
>this code would ever work.
>
>Perhaps the HtmlTableRendererBase.encodeInnerHtml method should look
>more like this:
>  uiData.setRowIndex(first);
>  int offset = first;
>  while (uiData.isRowValid()) {
>    // render
>    
>    if (offset > last)
>      break;
>
>    ++offset;
>    uiData.setRowIndex(offset);
>  }
>
>Regards,
>
>Simon
>
>
>  
>

Re: HtmlTableRendererBase and ResultSetDataModel

Posted by Simon Kitching <sk...@apache.org>.
On Sun, 2006-01-01 at 11:21 +0700, Pichai Ongvasith wrote:
> Hello,
> 
> I tried to use a ResultSetDataModel as the data model for <t:dataTable>, 
> with myfaces1.1.1. It turns out that the result never shows up in the table.
> My guess is that this might be related to Jira issue MYFACES-278.
> 
> Looking into the source code, I guess 
> HtmlTableRendererBase.encodeInnerHtml is doing the job to render the 
> result set.
> this is the excerpt of relevant code.
>         int first = uiData.getFirst();
>         int rows = uiData.getRows();
>         int rowCount = uiData.getRowCount();
>         if (rows <= 0)
>         {
>             rows = rowCount - first;
>         }
>         int last = first + rows;
>         if (last > rowCount)
>             last = rowCount;
> 
>         for (int i = first; i < last; i++)
>         {           
>              // render
>         }
> 
> If that's true, the method might be mishandling the uiData.getRowCount.
> The implementation of ResultSetDataModel.getRowCount in myfaces1.1.1 
> always return -1, which is valid when the row count is unknown at the 
> time. So before the rendering loop, last is always -1, and nothing would 
> be rendered.
>  
> Or am I missing something here?

It sure looks to me like the ResultSet support is broken. As you say,
ResultSetDataModel.getRowCount always returns -1, so I can't see how
this code would ever work.

Perhaps the HtmlTableRendererBase.encodeInnerHtml method should look
more like this:
  uiData.setRowIndex(first);
  int offset = first;
  while (uiData.isRowValid()) {
    // render
    
    if (offset > last)
      break;

    ++offset;
    uiData.setRowIndex(offset);
  }

Regards,

Simon