for (Object id : idList)
{
logger.info("mass updating id: " + id);
}
ScreenMessage msg = null;
// cleanup the request, only use ticked (marked with 'use_'
WritableTuple tuple = new KeyValueTuple();
for (HtmlInput<?> input : this.getFormScreen().getNewRecordForm().getInputs())
{
if (!request.isNull("use_" + input.getName()))
{
tuple.set(input.getName(), request.get(input.getName()));
}
}
int row = 0;
try
{
Query<? extends Entity> q = db.query(view.getController().getEntityClass()).in(
view.create().getIdField(), idList);
List<? extends Entity> entities = q.find();
db.beginTx();
for (Entity e : entities)
{
row++;
// set only not null values
e.set(tuple, false);
db.update(e);
}
db.commitTx();
msg = new ScreenMessage("MASS UPDATE SUCCESS: updated " + entities.size() + " rows", null, true);
}
catch (Exception e)
{
try
{
db.rollbackTx();
}
catch (DatabaseException e1)
{
logger.error("doMassUpdate() Should never happen: " + e1);
e1.printStackTrace();
}
msg = new ScreenMessage("MASS UPDATE FAILED on item '" + row + "': " + e, null, false);
}
view.getMessages().add(msg);
}
// record the selected ids