Issues with table row selection

Hi,
I am currently developing an application using Vaadin 7 where I am fetching data from a database and displaying it in a table using a BeanItemContainer object. the data is getting displayed properly.
Now I want to process the data when the user clicks on the table row. But the problem is that, the ItemClickListener event is not getting the call when I select(click) on the row. Instead, it gets called when I deselect(second click) row.
I have tried to do this using a double click event(isDoubleClick()), but again the event is generating when the row is deselected, but not when its in selected mode.[ Try to do this by clicking on the row once and when the row is in selected mode, try double clicking on it. The event never gets a call]
.



Here is the code:

tblCards.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent itemClickEvent) {

            Object selectedRow =tblCards.getValue();
                if(selectedRow!=null){
                    selectedCardId[0]

= tblCards.getContainerProperty(selectedRow,“id”).getValue().toString();
cmbCardType.select(tblCards.getContainerProperty(selectedRow, “cardType”).getValue().toString());
txtCardBarcode.setValue(tblCards.getContainerProperty(selectedRow,“barcode”).getValue().toString());
dtDateOfIssue.setValue((java.util.Date) tblCards.getContainerProperty(selectedRow,“issueDate”).getValue());
dtDateOfExp.setValue((java.util.Date) tblCards.getContainerProperty(selectedRow,“expiryDate”).getValue());
cmbStatus.select(tblCards.getContainerProperty(selectedRow,“status”).getValue().toString());
}
}
});



Here is my code for double click event:

tblMemberList.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent event) {
if(event.isDoubleClick()){
Object rowId =tblMemberList.getValue();
if(rowId!=null){
Long memberPrimaryKey = (Long)tblMemberList.getContainerProperty(rowId,“id”).getValue();

                    final Window window = new Window("Edit Member Details");
                    window.setModal(true);
                    TabSheet content = getEditMemberWindowComponents(memberPrimaryKey);
                    window.setWidth("65%");
                    window.setHeight("70%");
                    window.setContent(content);
                    UI.getCurrent().addWindow(window);

                    Window.CloseListener closeListner=new Window.CloseListener() {
                        @Override
                        public void windowClose(Window.CloseEvent e) {
                            memberBeanItemContainer.removeAllItems();
                            btnSearch.click();
                        }
                    };
                    window.addCloseListener(closeListner);
                }
            }
        }
    });

I think its a bug.
Please give me a solution as soon as possible,

Thanks,
Kishor
13004.png
13005.png

Is the table immediate?

I never saw such a behaviour when i had a itemclicklistener on my tables.

I think it has nothing to do with setImmediate . I tried setting it to both true and false. No change.

Ok. I just tried out my Vaadin 7 app and saw a similar behaviour (although in my case it didn’t work at all). If i find some time i will try out some stuff and if i get it to work i will post my solution. If not it might be a bug although i would like to hear what the Vaadin dev’s have to say to this topic before posting a ticket.

This problem sounds to major to not be recognized until now.

So i made some more tests and it seems like my ItemClickListener work without a problem. The reason they didn’t work when i tried it before was because i they caused some nullpointerexceptions.

My Table is set up pretty basic with setSizeFull, setSelectable(true), setPageLength and Immediate mode isn’t set at all.

I didn’t tried/used the double-click event yet so i don’t know whether this might be the cause of this issue.

The problem is not about the ClickListner , but it is about the event firing. The ClickListner doesnt fire when I click(select) on the row, but it gets fired when deselect the row.(i.e when I click on the same row for the second time).

I don’t quite understand.

So if you’re having something like this…:

tblCards.addItemClickListener(new ItemClickEvent.ItemClickListener() {
  @Override
  public void itemClick(ItemClickEvent itemClickEvent) {
     //Do stuff
  }
});

… the part in //Do stuff only gets called when you deselect the row?

This doesn’t happen in my test environment. Also is the DoubleClickListener necessary or did you try to fix something using it? I’m not quite sure from reading your text.

OK…I have to make a small correction to the title of my question now. The problem was not with the clickListner, but it was with the table itself. The clickListner fires properly. But in my code I was continuing only when the table returns a selected row. But it is actually returning a value when the table row is deselected, which should not happen.
Please check the code below,

tblCards.addItemClickListener(new ItemClickEvent.ItemClickListener() {
@Override
public void itemClick(ItemClickEvent itemClickEvent) {

                       [b]

Object selectedRow =tblCards.getValue();
[/b]

                       [b]

if(selectedRow!=null){
[/b]
selectedCardId[0]
= tblCards.getContainerProperty(selectedRow,“id”).getValue().toString();
cmbCardType.select(tblCards.getContainerProperty(selectedRow, “cardType”).getValue().toString());
txtCardBarcode.setValue(tblCards.getContainerProperty(selectedRow,“barcode”).getValue().toString());
dtDateOfIssue.setValue((java.util.Date) tblCards.getContainerProperty(selectedRow,“issueDate”).getValue());
dtDateOfExp.setValue((java.util.Date) tblCards.getContainerProperty(selectedRow,“expiryDate”).getValue());
cmbStatus.select(tblCards.getContainerProperty(selectedRow,“status”).getValue().toString());
}
}
});

Here the table returns a value when the row is deselected, but not when it is selected. So the problem is with the table.getValue() method. This is why I was getting such a problem this whole time. Again this looks like a bug to me, because the table should return a proper value when the row is in selected mode, but instead it returns null.
Please check it yourself, put some dummy rows and try to get the selected row value.

Thanks for the response,
Kishor

Why dont u do it this way?:

public void itemClick(ItemClickEvent event) {
	if (event.getItem() != null) {
	    //HERE YOU HAVE YOUR CLICKED ELEMENT
            Object selectedItemInTheRow = event.getItemId();
	}
}

This way u get your element directly, and dont need to know when table sets his selectedElement with value, so u could table.getValue();

I actually think that table sets his seleceted element just after click listener done his work. This is why u dont have any getValue() inside the click method. And this is why u get your value by unlick event, or by one more click on table.

So it works as intended me thinks.

Long live vaadin!

Hi all,
I got the answer for this problem. We can get the selected row from the event variable by calling event.getItemId(), this is similar to table.getValue(). In the begining I didnt know that event.getItemId() actually returns the selected row. Some of the Vaadin methods named such way that, sometimes its hard to understand their true purpose. Perhaps it should have been named something like event.getSelectedRow().
Anyway, my application is working fine in this case.
Thank you all for the replies.

Cheers,
Kishor