checkbox question

Hi,

I have few checkboxes on a dataTable.If I checked a checkbox and click edit button it will take to another page for modification.On this page I have NEXT and PREVIOUS buttons. Now if I click next or previous button then it should get the next record after the checked one on the previous page and for pervious button vise versa.

Please can anyone help to solve this.

any help is appreciated.

[420 byte] By [Ruthera] at [2007-11-27 3:36:18]
# 1

Hi Ruther ...

the first solution that comes to my mind is the following:

1. The action attribute of your edit button must be binded to a method that checks which records were selected, updates a List field of a backing bean in scope session with these records, and returns the String for the navigation to the modification page;

2. The modification page must refer to the backing bean in scope session updated before. This bean must have a counter, so you can control which is the current register. This register must be updated every time you hit NEXT or PREVIOUS.

I didn't test this solution, but I think it will work.

Best regards,

Alexandre

alexandre_correaa at 2007-7-12 8:39:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Hi Alexandre,thanks for your reply, It will be great if you could explain with a small piece of code.Any help is appreciated.thanks and regards.Ruther
Ruthera at 2007-7-12 8:39:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Below is the code for the Backing bean of the dataTable (some parts are not detailed, like the checking for selected records:

public class TableBean {

private List records;

...

public String editAction() {

List selectedRecords = new ArrayList();

/* Gets the selected records */

Iterator it = records.iterator();

while( it.hasNext() ) {

Record tmp = (Record) it.next();

if( tmp.isSelected() ) selectedRecords.add( tmp );

}

/* Updating sessionBean with selectedRecords */

FacesContext context = FacesContext.getCurrentInstance();

context.getApplication().

createValueBinding("#{ModificationBean.list}").setValue( context, selectedRecords );

/* Returns navigation string */

return "EDIT";

}

}

Now the code for the modification backing Bean (many parts are not shown, but I think you can get the point through this):

public class ModificationBean {

private List list;

private int counter = 0;

private Record currentRecord;

...

// ActionListener for NEXT button

public void nextRecord( ActionEvent event ) {

counter++;

record = list.get(counter);

}

// ActionListener for PREVIOUS button

public void previousRecord( ActionEvent event ) {

counter--;

record = list.get(counter);

}

}

As you can see, I didn't put a complete solution. My intent was to show you the main parts of the solution. If this is not sufficient, let me know.

Best regards,

Alexandre

alexandre_correaa at 2007-7-12 8:39:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Hi alexandre,Thanks for your reply,How could I disable the next button when I reach the end of records.
Ruthera at 2007-7-12 8:39:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

Put a method in your sessionBean that returns true if the counter is equal to the record list last position, and false otherwise, and associate it to the rendered attribute of the next button

public boolean isLast() {

return counter == (list.size() -1)

}

<h:commandButton rendered="#{SessionBean.last}" .../>

alexandre_correaa at 2007-7-12 8:39:32 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...