You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by Alex Burton <gr...@gmail.com> on 2006/05/23 03:26:32 UTC

datatable and selecting a row event

Hi all,

I'm trying to use a datagrid as a way to quickly find and select a
particular item from a large list of items. The items have several
attributes I wish to display and can number in the 100's, so a drop down
list isn't the right way to go...

So... I have my datagrid displaying beautifully... but am now stumped on how
to throw an even to catch a row selection... I know there are the
rowOnClick="javascript" attributes in the datagrid, but how do i bind that
to something useful?

Anyone have any pointers? Ideally I'd like to get the "forceIdIndexFormula"
value (or object it represents in my backing bean).

Thanks in advance,
Alex.

-- 
"We should move forwards, not backwards, upwards, not sideways, and always
twirling, twirling towards victory!"

Re: datatable and selecting a row event

Posted by Cosma Colanicchia <co...@gmail.com>.
A quick solution is to nest an <t:updateActionListener> inside your
commandLink to update a property of your backing bean.

There is another approach that I use with a dataTable, maybe it works also
for a dataGrid: if your list is loaded using a DataModel, you can simply ask
that object the current row in your backing bean.


Cosma


2006/5/23, Alex Burton <gr...@gmail.com>:
>
> Thanks Volker.
>
> How do you catch the 'row id' though?
>
> Cheers,
> Alex.
>
>
> On 5/23/06, Volker Weber <we...@googlemail.com> wrote:
> >
> > Hi Alex,
> >
> > we do this by using h:commandlink, with parameter, for displaying the
> > row data.
> > But you need to hit the text when clicking on a row.
> >
> > regards,
> >
> >   Volker
> >
> > 2006/5/23, Alex Burton < grumpy.burton@gmail.com>:
> > > Hi all,
> > >
> > >  I'm trying to use a datagrid as a way to quickly find and select a
> > > particular item from a large list of items. The items have several
> > > attributes I wish to display and can number in the 100's, so a drop
> > down
> > > list isn't the right way to go...
> > >
> > >  So... I have my datagrid displaying beautifully... but am now stumped
> > on
> > > how to throw an even to catch a row selection... I know there are the
> > > rowOnClick="javascript" attributes in the datagrid, but how do i bind
> > that
> > > to something useful?
> > >
> > >  Anyone have any pointers? Ideally I'd like to get the
> > "forceIdIndexFormula"
> > > value (or object it represents in my backing bean).
> > >
> > >  Thanks in advance,
> > >  Alex.
> > >
> > > --
> > > "We should move forwards, not backwards, upwards, not sideways, and
> > always
> > > twirling, twirling towards victory!"
> >
>
>
>
> --
>
> "We should move forwards, not backwards, upwards, not sideways, and always
> twirling, twirling towards victory!"
>

Re: datatable and selecting a row event

Posted by Alex Burton <gr...@gmail.com>.
Thanks! that worked a treat!

On 5/23/06, Jeff Bischoff <jb...@klkurz.com> wrote:
>
> Here is how I catch the 'row id' in my application:
>
> <t:dataTable id="TheDataTable" var="data">
>    <h:column>
>      <f:facet name="header"><h:outputText value="Sequence #"/></f:facet>
>      <h:commandLink action="#{navigation.reload}">
>        <h:outputText value="#{data.sequenceNum}"/>
>        <t:updateActionListener property="#{bean.currentSequenceNum}"
> value="#{data.sequenceNum}" />
>      </h:commandLink>
>    </h:column>
> </t:dataTable>
>
> This is generalized, stripped-down code - obviously I have other columns
> and such. The user will see in the first column a list of numbers. If
> they click a number, the <t:updateActionListener> will update the
> property on the bean with the value they clicked (data.sequenceNum).
> Then the <h:commandLink> tells navigation to reload the page. We use
> somewhat odd navigation on our site, so don't get confused by that.
>
> This works because
> * I have a sequence number stored in each bean of the collection that
> dataTable is displaying
> * I can access that bean in the jsp by using the "var" attribute in
> dataTable
>
> If your data doesn't actually have a row id property, perhaps you should
> add one.
>
> Regards,
>
> Jeff Bischoff
> Kenneth L Kurz & Assoc, Inc.
>
> Alex Burton wrote:
> > Thanks Volker.
> >
> > How do you catch the 'row id' though?
> >
> > Cheers,
> > Alex.
> >
> > On 5/23/06, *Volker Weber* <weber.volker@googlemail.com
> > <ma...@googlemail.com>> wrote:
> >
> >     Hi Alex,
> >
> >     we do this by using h:commandlink, with parameter, for displaying
> >     the row data.
> >     But you need to hit the text when clicking on a row.
> >
> >     regards,
> >
> >       Volker
> >
> >     2006/5/23, Alex Burton < grumpy.burton@gmail.com
> >     <ma...@gmail.com>>:
> >      > Hi all,
> >      >
> >      >  I'm trying to use a datagrid as a way to quickly find and select
> a
> >      > particular item from a large list of items. The items have
> several
> >      > attributes I wish to display and can number in the 100's, so a
> >     drop down
> >      > list isn't the right way to go...
> >      >
> >      >  So... I have my datagrid displaying beautifully... but am now
> >     stumped on
> >      > how to throw an even to catch a row selection... I know there are
> the
> >      > rowOnClick="javascript" attributes in the datagrid, but how do i
> >     bind that
> >      > to something useful?
> >      >
> >      >  Anyone have any pointers? Ideally I'd like to get the
> >     "forceIdIndexFormula"
> >      > value (or object it represents in my backing bean).
> >      >
> >      >  Thanks in advance,
> >      >  Alex.
> >      >
> >      > --
> >      > "We should move forwards, not backwards, upwards, not sideways,
> >     and always
> >      > twirling, twirling towards victory!"
> >
> >
> >
> >
> > --
> > "We should move forwards, not backwards, upwards, not sideways, and
> > always twirling, twirling towards victory!"
>
>
>


-- 
"We should move forwards, not backwards, upwards, not sideways, and always
twirling, twirling towards victory!"

Re: datatable and selecting a row event

Posted by Jeff Bischoff <jb...@klkurz.com>.
Here is how I catch the 'row id' in my application:

<t:dataTable id="TheDataTable" var="data">
   <h:column>
     <f:facet name="header"><h:outputText value="Sequence #"/></f:facet>
     <h:commandLink action="#{navigation.reload}">
       <h:outputText value="#{data.sequenceNum}"/>
       <t:updateActionListener property="#{bean.currentSequenceNum}" 
value="#{data.sequenceNum}" />
     </h:commandLink>
   </h:column>
</t:dataTable>

This is generalized, stripped-down code - obviously I have other columns 
and such. The user will see in the first column a list of numbers. If 
they click a number, the <t:updateActionListener> will update the 
property on the bean with the value they clicked (data.sequenceNum). 
Then the <h:commandLink> tells navigation to reload the page. We use 
somewhat odd navigation on our site, so don't get confused by that.

This works because
* I have a sequence number stored in each bean of the collection that 
dataTable is displaying
* I can access that bean in the jsp by using the "var" attribute in 
dataTable

If your data doesn't actually have a row id property, perhaps you should 
add one.

Regards,

Jeff Bischoff
Kenneth L Kurz & Assoc, Inc.

Alex Burton wrote:
> Thanks Volker.
> 
> How do you catch the 'row id' though?
> 
> Cheers,
> Alex.
> 
> On 5/23/06, *Volker Weber* <weber.volker@googlemail.com 
> <ma...@googlemail.com>> wrote:
> 
>     Hi Alex,
> 
>     we do this by using h:commandlink, with parameter, for displaying
>     the row data.
>     But you need to hit the text when clicking on a row.
> 
>     regards,
> 
>       Volker
> 
>     2006/5/23, Alex Burton < grumpy.burton@gmail.com
>     <ma...@gmail.com>>:
>      > Hi all,
>      >
>      >  I'm trying to use a datagrid as a way to quickly find and select a
>      > particular item from a large list of items. The items have several
>      > attributes I wish to display and can number in the 100's, so a
>     drop down
>      > list isn't the right way to go...
>      >
>      >  So... I have my datagrid displaying beautifully... but am now
>     stumped on
>      > how to throw an even to catch a row selection... I know there are the
>      > rowOnClick="javascript" attributes in the datagrid, but how do i
>     bind that
>      > to something useful?
>      >
>      >  Anyone have any pointers? Ideally I'd like to get the
>     "forceIdIndexFormula"
>      > value (or object it represents in my backing bean).
>      >
>      >  Thanks in advance,
>      >  Alex.
>      >
>      > --
>      > "We should move forwards, not backwards, upwards, not sideways,
>     and always
>      > twirling, twirling towards victory!"
> 
> 
> 
> 
> -- 
> "We should move forwards, not backwards, upwards, not sideways, and 
> always twirling, twirling towards victory!"



Re: datatable and selecting a row event

Posted by Alex Burton <gr...@gmail.com>.
Thanks Volker.

How do you catch the 'row id' though?

Cheers,
Alex.

On 5/23/06, Volker Weber <we...@googlemail.com> wrote:
>
> Hi Alex,
>
> we do this by using h:commandlink, with parameter, for displaying the row
> data.
> But you need to hit the text when clicking on a row.
>
> regards,
>
>   Volker
>
> 2006/5/23, Alex Burton <gr...@gmail.com>:
> > Hi all,
> >
> >  I'm trying to use a datagrid as a way to quickly find and select a
> > particular item from a large list of items. The items have several
> > attributes I wish to display and can number in the 100's, so a drop down
> > list isn't the right way to go...
> >
> >  So... I have my datagrid displaying beautifully... but am now stumped
> on
> > how to throw an even to catch a row selection... I know there are the
> > rowOnClick="javascript" attributes in the datagrid, but how do i bind
> that
> > to something useful?
> >
> >  Anyone have any pointers? Ideally I'd like to get the
> "forceIdIndexFormula"
> > value (or object it represents in my backing bean).
> >
> >  Thanks in advance,
> >  Alex.
> >
> > --
> > "We should move forwards, not backwards, upwards, not sideways, and
> always
> > twirling, twirling towards victory!"
>



-- 
"We should move forwards, not backwards, upwards, not sideways, and always
twirling, twirling towards victory!"

Re: datatable and selecting a row event

Posted by Volker Weber <we...@googlemail.com>.
Hi Alex,

we do this by using h:commandlink, with parameter, for displaying the row data.
But you need to hit the text when clicking on a row.

regards,

  Volker

2006/5/23, Alex Burton <gr...@gmail.com>:
> Hi all,
>
>  I'm trying to use a datagrid as a way to quickly find and select a
> particular item from a large list of items. The items have several
> attributes I wish to display and can number in the 100's, so a drop down
> list isn't the right way to go...
>
>  So... I have my datagrid displaying beautifully... but am now stumped on
> how to throw an even to catch a row selection... I know there are the
> rowOnClick="javascript" attributes in the datagrid, but how do i bind that
> to something useful?
>
>  Anyone have any pointers? Ideally I'd like to get the "forceIdIndexFormula"
> value (or object it represents in my backing bean).
>
>  Thanks in advance,
>  Alex.
>
> --
> "We should move forwards, not backwards, upwards, not sideways, and always
> twirling, twirling towards victory!"