Well i have a form with a related data that search into an oracle DB, but when i tried to get the ID of the selected row with the
getContainerProperty
i’ll get a null , so what’s wrong?
This is the method that controls the button event
public void itemClick(ItemClickEvent event) {
String cadena ="";
if (event.isDoubleClick() && (event.getButton() == event.BUTTON_LEFT)){//Comprobamos el doble click y si se ha pulsado la derecha
Object rowID = tablaDatos.getValue();
try {
Property property = tablaDatos.getContainerProperty(PersonalDAO.PERSONAL_PROPERTY_ID,rowID);
cadena = "Paso 1: " + (String) property.getValue();
}catch(Exception e){
try {
cadena = "Paso 2: " + rowID.toString(); <<<< here jumps when it's loaded the event
} catch(NullPointerException np){
cadena = "Paso 3: " + np.getMessage();
}
}
getWindow().showNotification("Selected: " + cadena );
}
PersonalDAO
package com.example.aplicacion.DAO;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.example.aplicacion.bean.PersonalBean;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
public class PersonalDAO {
public static final Object PERSONAL_PROPERTY_ID = "Id";
public static final Object PERSONAL_PROPERTY_NOMBRE = "Nombre";
public static final Object PERSONAL_PROPERTY_APELLIDOS ="Apellidos";
public static final Object PERSONAL_PROPERTY_CUERPO = "Cuerpo";
public static final Object PERSONAL_PROPERTY_TELEFONO = "Telefono";
public static final Object PERSONAL_PROPERTY_NIF = "Nif";
private static IndexedContainer personalContainer = carga();
private static IndexedContainer carga(){
IndexedContainer aux = new IndexedContainer();
aux.addContainerProperty(PERSONAL_PROPERTY_ID,Integer.class, "");
aux.addContainerProperty(PERSONAL_PROPERTY_NOMBRE,String.class, "");
aux.addContainerProperty(PERSONAL_PROPERTY_APELLIDOS,String.class, "");
aux.addContainerProperty(PERSONAL_PROPERTY_CUERPO,String.class, "");
aux.addContainerProperty(PERSONAL_PROPERTY_TELEFONO,String.class, "");
aux.addContainerProperty(PERSONAL_PROPERTY_NIF,String.class, "");
return aux;
}
public static IndexedContainer findAll() throws ClassNotFoundException, SQLException
{
String query = "select * from TEMP_EA_PERSONAL";
Connection con = UtilBD.getConnection();
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
try
{
personalContainer = carga();
while(rs.next())
{
String id = rs.getString("ID");
String nombre= rs.getString("NOMBRE");
String apellidos = rs.getString("APELLIDOS");
String cuerpo = rs.getString("CUERPO");
String telefono = rs.getString("TELEFONO");
String nif = rs.getString("NIF");
Item item = personalContainer.addItem(id+nombre+apellidos+cuerpo+telefono+nif);
if (item != null) {
item.getItemProperty(PERSONAL_PROPERTY_ID).setValue(id);
item.getItemProperty(PERSONAL_PROPERTY_NOMBRE).setValue(nombre);
item.getItemProperty(PERSONAL_PROPERTY_APELLIDOS).setValue(apellidos);
item.getItemProperty(PERSONAL_PROPERTY_CUERPO).setValue(cuerpo);
item.getItemProperty(PERSONAL_PROPERTY_TELEFONO).setValue(telefono);
item.getItemProperty(PERSONAL_PROPERTY_NIF).setValue(nif);
}
}
return personalContainer;
}
finally
{
if(con!=null)
UtilBD.closeConnection(con);
System.out.println("Cierre de la conexion...");
rs.close();
st.close();
}
}
}