Tips Abmf

download Tips Abmf

If you can't read please download the document

description

ffff

Transcript of Tips Abmf

PlatinumModel

Ajustes en la clase (Entity) de la tabla que se va a hacer el ABM.

Que el tipo de datos del atributo que es primary key (@Id en el Entity) se del tipo Long.

Agregar los Anotations para enlazar a la secuencia de base de datos que le corresponde a la tabla en cuestion. (ej. Producto.java del proyecto PlatinumModel)Agregar @SequenceGenerator, esto va debajo del @Entity

Agregar @GeneratedValue, esto debajo del anotations @Id

Ajustes en la clase (Controller) del Entity.La clase controller debe heredar de AbstractJpaDao e implementar los metodos.
Ej. Class TipoProductoControler extends AbstractJpaDao

Agregar constructor por defecto, para invocar dentro de este al constructor de la clase padre
ej. public TipoProductoController() { super(); }

Se puede copiar uno que ya esta hecho ejmplo: TipoProductoControler y luego buscar y reemplazar por el Entity en cuestion


PlatinumTe adjunto el tutorial que utilizamos como para mirar los del javascript del radio button y las otras cosas q vimos en ese tutorial.

Agregar javascript para verificar si se selecciono un registro para el Caso Elimiar
Ejemplo:

var delSelect;
function confirmar() {
if (delSelect!=null){
if(!confirm("Est seguro de eliminar el Producto seleccionado?")) {
return false;
}else{
return true;
}
}
}

En el evento onClick del boton Eliminar registro, agregar algo asi: onClick="javascript:returnconfirmar()"

Al agregar el metodo getAllFiltered importar los siguientes paquetes:

import javax.persistence.EntityManager;import javax.persistence.Query;

Radio Button de la GrillaAgregar una columna con radio button en la Grilla

Agregar el Siguiente codigo en la Bean de la Pagina

private TableSelectPhaseListener tablePhaseListener =

new TableSelectPhaseListener();

public void setSelected(Object object) {RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");if (rowKey != null) {tablePhaseListener.setSelected(rowKey, object);}}

public Object getSelected(){RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");return tablePhaseListener.getSelected(rowKey);

}

public Object getSelectedValue() {RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");return (rowKey != null) ? rowKey.getRowId() : null;

}

public boolean getSelectedState() {RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");return tablePhaseListener.isSelected(rowKey);}Asignar las siguientes propiedades del radio button

name="#{Page1.radioButton1.id}"
selected="#{Page1.selected}"
selectedValue="#{Page1.selectedValue}"

reemplazar Page1 por el nombre del pagina que se esta desarrollando.

En la columna que le contiene al radioButton1 en la pagina cambiar las siguientes propiedades:

Set the onClick property to setTimeout(initAllRows(),0)
selectId property to #{Page1.radioButton1.id}

reemplazar Page1 por el nombre del pagina que se esta desarrollando.

En el table Row Group tag jsp webuijsf:tableRowGroup


selected="#{Page1.selectedState}"

Agrear en el Bean de la Pagina, en el metodo del Boton Eliminar Registro

if (getTableRowGroup1().getSelectedRowsCount() > 0){

RowKey[] selectedRowKeys = getTableRowGroup1().getSelectedRowKeys(); Users[] users = getSessionBean1().getUsers(); int rowId = Integer.parseInt(selectedRowKeys[0].getRowId()); Users user = users[rowId]; // Remove the Entity from the database using UserController UserController userController = new UserController(); userController.removeUser(user); } return null; Agrear en el Bean de la Pagina, en el metodo del Boton Guardar Nuevo Registro

// Create a new User Entity

Users newUser = new Users();newUser.setUsername((String) userNameField.getText());newUser.setPassword((String) passwordField.getText());newUser.setEmailAddress((String) emailAddressField.getText());// Add the new Entity to the database using UserControllerUserController userController = new UserController();userController.addUser(newUser);updateRequest = false;return null;En la operacin de Editar registro

Guadar el ID del registro seleccionado en SessionBean1

ej.: getSessionBean1().setId()
en el metodo "cargar los campos" agregar
getSessionBean1().setId(tipoProducto.getCodTipoProducto());

Agrear en el Bean de la Pagina, en el metodo del Boton Guardar al Editar Registro

RowKey[] selectedRowKeys = getTableRowGroup1().getSelectedRowKeys();

Users[] users = getSessionBean1().getUsers();int rowId = Integer.parseInt(selectedRowKeys[0].getRowId());Users user = users[rowId];user.setUsername((String) userNameField.getText());user.setPassword((String) passwordField.getText());user.setEmailAddress((String) emailAddressField.getText());// Update the database table data using UserControllerUserController userController = new UserController();userController.updateUser(user);addRequest = false;return null;