Hi Jeff.
Actually, the tableModel.addRowObject(Object toAdd) doesn't really
adds the custom row to the table if one didn't do a call at
javascript:jQuery.jmesa.setAddRowToWorksheet(idTable), i.e. pressing a
button named "Add", am I right?
Well, and what if one wants to add the row and render it completely
from API?
In my working example, I've got an entity (let's call it "master-
entity") containing a collection of some other entities: this
collection is shown by a jMesa table.
It's expected a functionality for duplicating objects: when user calls
it, master-entity fields must be shown in a new form BUT NOT SAVED
until the user doesn't presses the Save button. So I need to "preview"
the collection in the jMesa table (adding to the table's worksheet as
many rows as the collection contains) and save it only when user saves
the master-entity...
I build the table from API, but I don't know how to add every single
row to the worksheet.
Hope I explained well the problem...
Here is my code:
private String buildProdottiDynamicTable(PortletRequest request,
Collection<Posizioneddt> prodotti) {
String toReturn = "";
try {
TableModel tableModel = new TableModel("prodotti",
PortalUtil.getHttpServletRequest(request));
tableModel.setItems(new ArrayList<Posizioneddt>()); // table must
be void, except for the WorksheetRowStatus.ADD rows
tableModel.setStateAttr("restore");
tableModel.setEditable(Boolean.valueOf(true));
// this hides the toolbar
tableModel.setMaxRows(prodotti.size());
tableModel.setToolbar(new Toolbar() {
});
tableModel.saveWorksheet( new WorksheetSaver() {
public void saveWorksheet(Worksheet worksheet) {
saveWorksheetChanges(worksheet);
}
});
// table
HtmlTable htmlTable = new HtmlTable().width("98%");
htmlTable.setCaption("Prodotti");
// row
HtmlRow htmlRow = new HtmlRow().highlighter(false);
htmlRow.setRowRenderer(new CustomHtmlRowRenderer());
htmlRow.setUniqueProperty("id");
htmlTable.setRow(htmlRow);
// columns
HtmlColumn rimuovi = new HtmlColumn();
rimuovi.setCellRenderer(new CustomHtmlCellRenderer());
rimuovi.getCellRenderer().setWorksheetEditor(new
RemoveRowWorksheetEditor());
rimuovi.setTitle(" ");
rimuovi.setFilterable(Boolean.valueOf(false));
rimuovi.setSortable(Boolean.valueOf(false));
htmlRow.addColumn(rimuovi);
HtmlColumn codice = new HtmlColumn("materiale.codice");
codice.setTitle("Codice");
//codice.setEditable(Boolean.valueOf(false));
htmlRow.addColumn(codice);
// ... adding of other columns omitted ...
// this is what I'm trying to do, but doesn't works...
Worksheet worksheet = new Worksheet("prodotti");
Iterator<Posizioneddt> it = prodotti.iterator();
while(it.hasNext()) {
System.out.println("ADDING 1 ROW OBJECT");
Posizioneddt nextelement = it.next();
tableModel.addRowObject(nextelement);
WorksheetRow newWorksheetRow = new WorksheetRow(new
UniqueProperty("id", "0"));
newWorksheetRow.setRowStatus(WorksheetRowStatus.ADD);
newWorksheetRow.setItem(nextelement);
worksheet.addRow(newWorksheetRow);
//worksheet.addRow(nextelement);
}
// here ends what I'm trying to do, but doesn't works...
tableModel.setTable(htmlTable);
toReturn = tableModel.render();
} catch (Exception ex) {
System.err.println("buildProdottiDynamicTable() - Exception: " +
ex.getMessage());
ex.printStackTrace();
}
return toReturn;
}
Thank you in advance. Best regards,
Massimiliano
On 31 Ago, 17:58, Jeff Johnston <
jeff.johnston...@gmail.com> wrote:
> Great! For those following the thread that would be the
>
> tableModel.addRowObject();
>
> I will get the docs updated!
>
> -Jeff Johnston
>
> On Wed, Aug 31, 2011 at 9:21 AM, Massimiliano Del Matto
> <
maxdu...@gmail.com>wrote: