FAQ

[MyFaces-users] Custom DataScroller (t:dataScroller)

Tathagat
Feb 1, 2008 at 3:20 pm
Hi All.
Current data scroller gives a paginator in the following format:
1-100, 101-200, 201-300.. and so on.

What I would like is value of a column (along which the table is sorted),
for example:
AAA-CAT, CAU-FAX, FBC-MPC... and so on.
The advantage is that user sees immediately where the value lies in the
paginator (and does not have to guess).

I implemented my own solution for it.
Extended t:dataScroller classes with my own (regsitering faces-config, new
taglib, entry in web.xml).
I had to override the following method in
org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
protected HtmlCommandLink getLink(FacesContext facesContext,
HtmlDataScroller scroller,
String text, int pageIndex)

Now the problem here was to get the data of the table mentioned in "for"
property of datascroller.
By default dataScroller has only "rows" (property of t:dataTable) amount of
data (which is currently visible to user).
--scroller.getUIData()

So I used the following hack.
Define the same scroller and table with different IDs with rows=total number
of rows and style=display:none;
Causing it not to show on the page but having the second sroller all the
data in it.

Thus I could build a paginator as mentioned above.

My questions is:
Is there a better way to get all the data in the table? All methods which
provide data are protected.

Thanks for your time.
Tathagat
reply

Search Discussions

6 responses

  • Martin Marinschek at Feb 6, 2008 at 7:50 pm
    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading. Why should
    the second scroller have all data then? I really don't get your explanation.

    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering faces-config, new
    taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned in "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of t:dataTable) amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller all the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All methods which
    provide data are protected.

    Thanks for your time.
    Tathagat


    --

    http://www.irian.at

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

    Professional Support for Apache MyFaces
  • Tathagat at Feb 7, 2008 at 11:58 am
    Hi Martin.
    Let me re-word my question.

    I need all the data associated with a dataTable in my java code to do some
    stuff with it. If you somehow get hold of this dataTable object - it's not
    possible to get data out of it as all such methods are protected.
    BUT a dataScroller has a method - getUIData() - which gives the data on the
    "active" page.
    So if I associate a dummy scroller with our dataTable (also dummy - copy of
    original with rows=all data) (but hide it) having just 1 page, I have access
    to all data in dataTable (indirectly using dataScroller). This is the hack I
    was talking about.

    Is it clearer?

    I wanna know if there is a better way to get all data associated with the
    table on java level?

    Why I wanna do this - or where am I headed - to get a custom scroller.

    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    To do this.. I need all the data in the dataTable on java level.

    Hope I was clearer????

    Thanks for your time.
    Tathagat

    On 2/6/08, Martin Marinschek wrote:

    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading. Why should
    the second scroller have all data then? I really don't get your explanation.

    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted), for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering faces-config,
    new taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned in "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of t:dataTable) amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller all the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All methods
    which provide data are protected.

    Thanks for your time.
    Tathagat


    --

    http://www.irian.at

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

    Professional Support for Apache MyFaces
  • Martin Marinschek at Feb 7, 2008 at 12:01 pm
    Hi Tathagat,

    you could bind the <h:dataTable/> with the binding attribute to a
    backing-bean - or you could set the value to a data-model, then you
    have access to the full data-model.

    regards,

    Martin
    On 2/7/08, Tathagat wrote:
    Hi Martin.
    Let me re-word my question.

    I need all the data associated with a dataTable in my java code to do some
    stuff with it. If you somehow get hold of this dataTable object - it's not
    possible to get data out of it as all such methods are protected.
    BUT a dataScroller has a method - getUIData() - which gives the data on the
    "active" page.
    So if I associate a dummy scroller with our dataTable (also dummy - copy of
    original with rows=all data) (but hide it) having just 1 page, I have access
    to all data in dataTable (indirectly using dataScroller). This is the hack I
    was talking about.

    Is it clearer?

    I wanna know if there is a better way to get all data associated with the
    table on java level?

    Why I wanna do this - or where am I headed - to get a custom scroller.

    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    To do this.. I need all the data in the dataTable on java level.

    Hope I was clearer????

    Thanks for your time.
    Tathagat

    On 2/6/08, Martin Marinschek wrote:

    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading. Why should
    the second scroller have all data then? I really don't get your
    explanation.
    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted), for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering faces-config,
    new taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned in "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of t:dataTable) amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller all the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All methods
    which provide data are protected.

    Thanks for your time.
    Tathagat


    --

    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
  • Tathagat at Feb 7, 2008 at 3:59 pm
    Hi again Martin.

    I want to access the data from my custom dataScroller Renderer Class.
    public class MaeHtmlDataScrollerRenderer extends HtmlDataScrollerRenderer

    This means even if I use the binding property for dataTable, I am stuck.
    Cause of the protected methods I cannot get the data out.

    What do you mean by set the value to a data-model? As in a new property to
    the custom dataScroller?

    Thanks again
    Tathagat
    On 2/7/08, Martin Marinschek wrote:

    Hi Tathagat,

    you could bind the <h:dataTable/> with the binding attribute to a
    backing-bean - or you could set the value to a data-model, then you
    have access to the full data-model.

    regards,

    Martin
    On 2/7/08, Tathagat wrote:
    Hi Martin.
    Let me re-word my question.

    I need all the data associated with a dataTable in my java code to do some
    stuff with it. If you somehow get hold of this dataTable object - it's not
    possible to get data out of it as all such methods are protected.
    BUT a dataScroller has a method - getUIData() - which gives the data on the
    "active" page.
    So if I associate a dummy scroller with our dataTable (also dummy - copy of
    original with rows=all data) (but hide it) having just 1 page, I have access
    to all data in dataTable (indirectly using dataScroller). This is the hack I
    was talking about.

    Is it clearer?

    I wanna know if there is a better way to get all data associated with the
    table on java level?

    Why I wanna do this - or where am I headed - to get a custom scroller.

    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    To do this.. I need all the data in the dataTable on java level.

    Hope I was clearer????

    Thanks for your time.
    Tathagat

    On 2/6/08, Martin Marinschek wrote:

    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading. Why
    should
    the second scroller have all data then? I really don't get your
    explanation.
    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted), for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in
    the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering
    faces-config,
    new taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned in
    "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of t:dataTable)
    amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with
    rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller all
    the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All methods
    which provide data are protected.

    Thanks for your time.
    Tathagat


    --

    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
  • Martin Marinschek at Feb 8, 2008 at 12:32 am
    Hi Tathagat,

    <h:dataTable value="#{bean.dataModel}"/>

    Bean

    {
    public DataModel getDataModel();
    }

    Like this, you can wrap the corresponding list in a DataModel and do
    more than just extract data - DataModel is a powerful interface. As
    for concrete implementations, DataModel can be of type ListDataModel,
    e.g. Is this what you want? I still don't understand what you mean by
    getting the data - the data is in the value, so you can call
    getValue() on the component, and this is not protected. Do you need
    anything more?

    regards,

    Martin
    On Feb 7, 2008 4:59 PM, Tathagat wrote:
    Hi again Martin.

    I want to access the data from my custom dataScroller Renderer Class.
    public class MaeHtmlDataScrollerRenderer extends HtmlDataScrollerRenderer

    This means even if I use the binding property for dataTable, I am stuck.
    Cause of the protected methods I cannot get the data out.

    What do you mean by set the value to a data-model? As in a new property to
    the custom dataScroller?

    Thanks again
    Tathagat


    On 2/7/08, Martin Marinschek wrote:
    Hi Tathagat,

    you could bind the <h:dataTable/> with the binding attribute to a
    backing-bean - or you could set the value to a data-model, then you
    have access to the full data-model.

    regards,

    Martin
    On 2/7/08, Tathagat wrote:
    Hi Martin.
    Let me re-word my question.

    I need all the data associated with a dataTable in my java code to do
    some
    stuff with it. If you somehow get hold of this dataTable object - it's
    not
    possible to get data out of it as all such methods are protected.
    BUT a dataScroller has a method - getUIData() - which gives the data on
    the
    "active" page.
    So if I associate a dummy scroller with our dataTable (also dummy - copy
    of
    original with rows=all data) (but hide it) having just 1 page, I have
    access
    to all data in dataTable (indirectly using dataScroller). This is the
    hack I
    was talking about.

    Is it clearer?

    I wanna know if there is a better way to get all data associated with
    the
    table on java level?

    Why I wanna do this - or where am I headed - to get a custom scroller.

    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in the
    paginator (and does not have to guess).

    To do this.. I need all the data in the dataTable on java level.

    Hope I was clearer????

    Thanks for your time.
    Tathagat

    On 2/6/08, Martin Marinschek wrote:

    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading. Why
    should
    the second scroller have all data then? I really don't get your
    explanation.
    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted), for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in
    the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering
    faces-config,
    new taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned in
    "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of t:dataTable)
    amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with
    rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller all
    the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All methods
    which provide data are protected.

    Thanks for your time.
    Tathagat


    --

    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


    --

    http://www.irian.at

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

    Professional Support for Apache MyFaces
  • Tathagat at Feb 8, 2008 at 1:38 pm
    Stupid me. Why didn't I call getValue() before :).

    This works fine:
    ListDataModel listDataModel =
    (ListDataModel)scroller.getUIData().getValue();
    ArrayList dataList = (ArrayList)listDataModel.getWrappedData();

    Mission accomplished.

    Thanks a ton again.

    Tathagat
    On 2/8/08, Martin Marinschek wrote:

    Hi Tathagat,

    <h:dataTable value="#{bean.dataModel}"/>

    Bean

    {
    public DataModel getDataModel();
    }

    Like this, you can wrap the corresponding list in a DataModel and do
    more than just extract data - DataModel is a powerful interface. As
    for concrete implementations, DataModel can be of type ListDataModel,
    e.g. Is this what you want? I still don't understand what you mean by
    getting the data - the data is in the value, so you can call
    getValue() on the component, and this is not protected. Do you need
    anything more?

    regards,

    Martin
    On Feb 7, 2008 4:59 PM, Tathagat wrote:
    Hi again Martin.

    I want to access the data from my custom dataScroller Renderer Class.
    public class MaeHtmlDataScrollerRenderer extends
    HtmlDataScrollerRenderer
    This means even if I use the binding property for dataTable, I am stuck.
    Cause of the protected methods I cannot get the data out.

    What do you mean by set the value to a data-model? As in a new property to
    the custom dataScroller?

    Thanks again
    Tathagat


    On 2/7/08, Martin Marinschek wrote:
    Hi Tathagat,

    you could bind the <h:dataTable/> with the binding attribute to a
    backing-bean - or you could set the value to a data-model, then you
    have access to the full data-model.

    regards,

    Martin
    On 2/7/08, Tathagat wrote:
    Hi Martin.
    Let me re-word my question.

    I need all the data associated with a dataTable in my java code to
    do
    some
    stuff with it. If you somehow get hold of this dataTable object -
    it's
    not
    possible to get data out of it as all such methods are protected.
    BUT a dataScroller has a method - getUIData() - which gives the data
    on
    the
    "active" page.
    So if I associate a dummy scroller with our dataTable (also dummy -
    copy
    of
    original with rows=all data) (but hide it) having just 1 page, I
    have
    access
    to all data in dataTable (indirectly using dataScroller). This is
    the
    hack I
    was talking about.

    Is it clearer?

    I wanna know if there is a better way to get all data associated
    with
    the
    table on java level?

    Why I wanna do this - or where am I headed - to get a custom
    scroller.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted),
    for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies in
    the
    paginator (and does not have to guess).

    To do this.. I need all the data in the dataTable on java level.

    Hope I was clearer????

    Thanks for your time.
    Tathagat

    On 2/6/08, Martin Marinschek wrote:

    Hi Tathagat,

    I am very sorry, but I do not understand where you are heading.
    Why
    should
    the second scroller have all data then? I really don't get your
    explanation.
    regards,

    Martin
    On Feb 1, 2008 4:18 PM, Tathagat wrote:

    Hi All.
    Current data scroller gives a paginator in the following format:
    1-100, 101-200, 201-300.. and so on.

    What I would like is value of a column (along which the table is
    sorted), for example:
    AAA-CAT, CAU-FAX, FBC-MPC... and so on.
    The advantage is that user sees immediately where the value lies
    in
    the
    paginator (and does not have to guess).

    I implemented my own solution for it.
    Extended t:dataScroller classes with my own (regsitering
    faces-config,
    new taglib, entry in web.xml).
    I had to override the following method in
    org.apache.myfaces.custom.datascroller.HtmlDataScrollerRenderer
    protected HtmlCommandLink getLink(FacesContext facesContext,
    HtmlDataScroller scroller,
    String text, int pageIndex)

    Now the problem here was to get the data of the table mentioned
    in
    "for"
    property of datascroller.
    By default dataScroller has only "rows" (property of
    t:dataTable)
    amount
    of data (which is currently visible to user).
    --scroller.getUIData()

    So I used the following hack.
    Define the same scroller and table with different IDs with
    rows=total
    number of rows and style=display:none;
    Causing it not to show on the page but having the second sroller
    all
    the
    data in it.

    Thus I could build a paginator as mentioned above.

    My questions is:
    Is there a better way to get all the data in the table? All
    methods
    which provide data are protected.

    Thanks for your time.
    Tathagat


    --

    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


    --

    http://www.irian.at

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

    Professional Support for Apache MyFaces

Related Discussions

Discussion Navigation
viewthread | post

2 users in discussion

Tathagat: 4 posts Martin Marinschek: 3 posts