You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-user@incubator.apache.org by "Edmond B. Mulemangabo" <ed...@uclouvain.be> on 2007/04/20 14:20:40 UTC

how do I refresh a table component after selecting and deleting one or more rows ?

I'm using trinidad-1.1.6-SNAPSHOT. I've got a table component (eg
"<tr:table>"). As I select and delete one or more rows, looking at my
database, the delete operation is actually carried out successfully but
the page isn't being refreshed accordingly: the deleted rows remain
displayed.
Is there a way to delete rows, keep displaying the same page but just
refresh it, removing any deleted rows ?

Thanks.

--
Edmond/

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by Simon Lessard <si...@gmail.com>.
Hello,

Even if the row is deleted in the database, maybe it still exists in the
DataModel, can you provide a small code snip of your bean please? Also, are
you using PPR or is it a full submit delete?


Regards,

~ Simon

On 4/20/07, Edmond B. Mulemangabo <ed...@uclouvain.be> wrote:
>
> Ritchie Francis wrote:
> > What scope is the bean that populates the table?
> > If the bean is session
>
> Thank you for replying.
>
> The bean is session scoped and I'd like to keep it session scoped.
>
> --
> Edmond/
>

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by "Edmond B. Mulemangabo" <ed...@uclouvain.be>.
Ritchie Francis wrote:
> What scope is the bean that populates the table?
> If the bean is session

Thank you for replying.

The bean is session scoped and I'd like to keep it session scoped.

--
Edmond/

Re: how do I refresh a table component after selecting and deletingone or more rows ?

Posted by "Edmond B. Mulemangabo" <ed...@uclouvain.be>.
Luka Surija wrote:
> If you want to use PPR you can add on actionListener method following
> lines to resolve the problem:
> 
> public void myAction(ActionEvent event){
> 
>    // action code
> 
>    RequestContext requestContext = RequestContext.getCurrentInstance();
>   
> requestContext.addPartialTarget(event.getComponent().findComponent("trTableId"));
> 
> }
> 
> and this action will refresh only tr:table with id="trTableId".

I appreciate your help; thanks.

--
Edmond/

Re: how do I refresh a table component after selecting and deletingone or more rows ?

Posted by Luka Surija <lu...@iytim.hr>.
If you want to use PPR you can add on actionListener method following 
lines to resolve the problem:

public void myAction(ActionEvent event){

    // action code

    RequestContext requestContext = RequestContext.getCurrentInstance();
    
requestContext.addPartialTarget(event.getComponent().findComponent("trTableId"));
}

and this action will refresh only tr:table with id="trTableId".

Edmond B. Mulemangabo wrote:
> Problem solved; thank you.
>
> Simon Lessard wrote:
>
>   
>> Add "table:discard_selected" as partialTarget, tr:table is a naming
>> container, and I don't think we have a children trigger detection algorithm
>> implemented yet.
>>     
>
> Thank you for the information.
> I didn't have to use partialTarget; I , instead, added an "action"
> attribute to my commandButton component to force page refresh.
>
>   
>> Also, you should not keep a a bound component in session (using binding
>> attribute). I read that you want to keep the bean session scoped, so you'll
>> have to split it in two beans:
>>     
>
> I've removed the binding attribute from the table component.
>
> regards.
>
> --
> Edmond/
>
>   


Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by "Edmond B. Mulemangabo" <ed...@uclouvain.be>.
Problem solved; thank you.

Simon Lessard wrote:

> Add "table:discard_selected" as partialTarget, tr:table is a naming
> container, and I don't think we have a children trigger detection algorithm
> implemented yet.

Thank you for the information.
I didn't have to use partialTarget; I , instead, added an "action"
attribute to my commandButton component to force page refresh.

> Also, you should not keep a a bound component in session (using binding
> attribute). I read that you want to keep the bean session scoped, so you'll
> have to split it in two beans:

I've removed the binding attribute from the table component.

regards.

--
Edmond/

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by Simon Lessard <si...@gmail.com>.
Hello,

Add "table:discard_selected" as partialTarget, tr:table is a naming
container, and I don't think we have a children trigger detection algorithm
implemented yet.

Also, you should not keep a a bound component in session (using binding
attribute). I read that you want to keep the bean session scoped, so you'll
have to split it in two beans:

Bean 1: TableStateBean, session scoped, contains listOfSimpleBeans attribute
Bean 2: TableControllerBean, request scoped, contains a reference to
TableStateBean, component and discardSelectedRowHandler action listener
method. You can inject the state as a managed-property and maybe provide a
getListOfSimpleBeans() method that delegate the call to the tableStateBean
object so you don't have to change the page to reflect that structural
change.


Regards,

~ Simon

On 4/20/07, Edmond B. Mulemangabo <ed...@uclouvain.be> wrote:
>
> Simon Lessard wrote:
> > Ok so this is a PPR delete then,
>
> That's correct.
>
> > I assume you placed the delete button on
> > each row of the table?
>
> I used "rowSelection" attribute o achieve that. I'm using myFaces +
> Trinidad + Facelets; so my script is "xhtml". Here are parts of my
> script including the start the table tag and the commandButton that
> actually deletes selected rows :
>
> <tr:table
>    id="table"
>    immediate="true"
>    binding="#{backingBean.component}"
>    emptyText="#{bundle['empty_text']}"
>    rowSelection="multiple"
>    allDetailsEnabled="true"
>    var="row"
>    rows="#{bundle['table_nr_of_rows']}"
>    value="#{backingBean.listOfSimpleBeans}"
>    rendered="#{!empty ackingBean.listOfSimpleBeans}"
>    verticalGridVisible="true"
>    horizontalGridVisible="true">
>    ...
>    <tr:commandButton
>        id="discard_selected"
>        immediate="true"
>        text="#{bundle['button.discard_selected']}"
>        shortDesc="#{bundle['tooltip.discard_selected']}"
>        actionListener="#{backingBean.discardSelectedRowHandler}"/>
>    ...
>
> Here is the method called by the above commandButton using
> "actionListener" attribute :
>
> public void discardSelectedRowHandler(ActionEvent action)
> {
>         UIXTable table = (UIXTable)getComponent();
>         Object oldKey = table.getRowKey();
>         for (Object rowKey : table.getSelectedRowKeys()) {
>             table.setRowKey(rowKey);
>             E row = clazzE.cast(table.getRowData());
>             row.setChecked(true);
>         }
>         // remove selected rows from the list
>         table.getSelectedRowKeys().removeAll();
>         // restore the old key:
>         table.setRowKey(oldKey);
> }
>
> I tried adding 'partialTriggers="discard_selected"' to "tr:table"; that
> didn't solve my problem.
>
> --
> Edmond/
>

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by "Edmond B. Mulemangabo" <ed...@uclouvain.be>.
Simon Lessard wrote:
> Ok so this is a PPR delete then,

That's correct.

> I assume you placed the delete button on
> each row of the table?

I used "rowSelection" attribute o achieve that. I'm using myFaces +
Trinidad + Facelets; so my script is "xhtml". Here are parts of my
script including the start the table tag and the commandButton that
actually deletes selected rows :

<tr:table
   id="table"
   immediate="true"
   binding="#{backingBean.component}"
   emptyText="#{bundle['empty_text']}"
   rowSelection="multiple"
   allDetailsEnabled="true"
   var="row"
   rows="#{bundle['table_nr_of_rows']}"
   value="#{backingBean.listOfSimpleBeans}"
   rendered="#{!empty ackingBean.listOfSimpleBeans}"
   verticalGridVisible="true"
   horizontalGridVisible="true">
   ...
   <tr:commandButton
       id="discard_selected"
       immediate="true"
       text="#{bundle['button.discard_selected']}"
       shortDesc="#{bundle['tooltip.discard_selected']}"
       actionListener="#{backingBean.discardSelectedRowHandler}"/>
   ...

Here is the method called by the above commandButton using
"actionListener" attribute :

public void discardSelectedRowHandler(ActionEvent action)
{
        UIXTable table = (UIXTable)getComponent();
        Object oldKey = table.getRowKey();
        for (Object rowKey : table.getSelectedRowKeys()) {
            table.setRowKey(rowKey);
            E row = clazzE.cast(table.getRowData());
            row.setChecked(true);
        }
	// remove selected rows from the list
        table.getSelectedRowKeys().removeAll();
        // restore the old key:
        table.setRowKey(oldKey);
}

I tried adding 'partialTriggers="discard_selected"' to "tr:table"; that
didn't solve my problem.

--
Edmond/

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by Simon Lessard <si...@gmail.com>.
Ok so this is a PPR delete then, I assume you placed the delete button on
each row of the table? If so then you have to add a partial target on the
table to the button.

On 4/20/07, Edmond B. Mulemangabo <ed...@uclouvain.be> wrote:
>
> Mike Kienenberger wrote:
> > When you delete the row, you would also update the dataTable's backing
> > list.   It won't matter what the scope of the list is.
>
> Thank you Mike.
>
> I did update the dataTable's backing list as well as the underlying
> database; I was able to monitor the delete operation using a debugger.
> Still the page isn't refreshed unless I reload it completely using a
> navigation rule that forces the page to reload. My application is built
> in such way that forcing the page to reload completely using a
> navigation rule would lead to some valuable data getting lost; I'd like
> to keep the page as is and just refresh the table component to make it
> reflect the actual state after deleting rows.
> Note : the dataTable's backing bean is session scoped.
>
>
> --
> Edmond/
>

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by "Edmond B. Mulemangabo" <ed...@uclouvain.be>.
Mike Kienenberger wrote:
> When you delete the row, you would also update the dataTable's backing
> list.   It won't matter what the scope of the list is.

Thank you Mike.

I did update the dataTable's backing list as well as the underlying
database; I was able to monitor the delete operation using a debugger.
Still the page isn't refreshed unless I reload it completely using a
navigation rule that forces the page to reload. My application is built
in such way that forcing the page to reload completely using a
navigation rule would lead to some valuable data getting lost; I'd like
to keep the page as is and just refresh the table component to make it
reflect the actual state after deleting rows.
Note : the dataTable's backing bean is session scoped.


--
Edmond/

Re: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by Mike Kienenberger <mk...@gmail.com>.
When you delete the row, you would also update the dataTable's backing
list.   It won't matter what the scope of the list is.

On 4/20/07, Ritchie Francis <Ri...@focus-solutions.co.uk> wrote:
> What scope is the bean that populates the table?
> If the bean is session or application scoped then once you've populated
> the table that's it until a new session is created or you stop/start the
> server.
>
> In this instance I've declared mytable as request scoped, so when the
> page is re-drawn the values method which goes to the database is called
> as the bean is loaded.
>
> This obviously results in more db traffic but at least the start of the
> table is consistent with the underlying database.
>
> Here may be other solutions but this works for me.
>
>   <tr:table    emptyText="#{bundle['mytable_empty.message']}"
>
>                                      value="#{mytable.values}" var="row"
>                                      rows="#{mytable.totalRows}"
>                                      binding="#{mytable.table1}"
>
>
>
>
>                         >
>
> -----Original Message-----
> From: Edmond B. Mulemangabo [mailto:edmond.mulemangabo@uclouvain.be]
> Sent: 20 April 2007 15:21
> To: adffaces-user@incubator.apache.org
> Subject: how do I refresh a table component after selecting and deleting
> one or more rows ?
>
> I'm using trinidad-1.1.6-SNAPSHOT. I've got a table component (eg
> "<tr:table>"). As I select and delete one or more rows, looking at my
> database, the delete operation is actually carried out successfully but
> the page isn't being refreshed accordingly: the deleted rows remain
> displayed.
> Is there a way to delete rows, keep displaying the same page but just
> refresh it, removing any deleted rows ?
>
> Thanks.
>
> --
> Edmond/
>

RE: how do I refresh a table component after selecting and deleting one or more rows ?

Posted by Ritchie Francis <Ri...@focus-solutions.co.uk>.
What scope is the bean that populates the table?
If the bean is session or application scoped then once you've populated
the table that's it until a new session is created or you stop/start the
server.

In this instance I've declared mytable as request scoped, so when the
page is re-drawn the values method which goes to the database is called
as the bean is loaded.

This obviously results in more db traffic but at least the start of the
table is consistent with the underlying database.

Here may be other solutions but this works for me.

  <tr:table    emptyText="#{bundle['mytable_empty.message']}"
                                   
                                     value="#{mytable.values}" var="row"
                                     rows="#{mytable.totalRows}"
                                     binding="#{mytable.table1}"

                                     
                                    
                                     
                        >

-----Original Message-----
From: Edmond B. Mulemangabo [mailto:edmond.mulemangabo@uclouvain.be] 
Sent: 20 April 2007 15:21
To: adffaces-user@incubator.apache.org
Subject: how do I refresh a table component after selecting and deleting
one or more rows ?

I'm using trinidad-1.1.6-SNAPSHOT. I've got a table component (eg
"<tr:table>"). As I select and delete one or more rows, looking at my
database, the delete operation is actually carried out successfully but
the page isn't being refreshed accordingly: the deleted rows remain
displayed.
Is there a way to delete rows, keep displaying the same page but just
refresh it, removing any deleted rows ?

Thanks.

--
Edmond/