adding a custom row to worksheet

98 views
Skip to first unread message

Massimiliano Del Matto

unread,
Aug 31, 2011, 9:26:37 AM8/31/11
to JMesa
Hi.

I just want to add rows using some input values instead of editing an
empty row each time it's added as explained in the
WorksheetAddRemoveValidateRowsV3 tutorial.

So, is there a way of adding a non-empty row to a jmesa worksheet?

Thank you, Massimiliano

Massimiliano Del Matto

unread,
Aug 31, 2011, 10:21:51 AM8/31/11
to JMesa
Tried for some hours before posting.
Solved some minutes after posting.

Thanks anyway! Massimiliano

Jeff Johnston

unread,
Aug 31, 2011, 11:58:39 AM8/31/11
to jm...@googlegroups.com
Great! For those following the thread that would be the

tableModel.addRowObject();

I will get the docs updated!

-Jeff Johnston



--
You received this message because you are subscribed to the Google Groups "JMesa" group.
To post to this group, send email to jm...@googlegroups.com.
To unsubscribe from this group, send email to jmesa+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/jmesa?hl=en.


Massimiliano Del Matto

unread,
Sep 14, 2011, 8:32:42 AM9/14/11
to JMesa
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("&nbsp;");
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:

Jeff Johnston

unread,
Sep 14, 2011, 12:42:01 PM9/14/11
to jm...@googlegroups.com
Your explanation is very clear and your assumptions are correct as well.

Now that you bring this to my attention I think there are a few things that should be improved in the API. The first is that when the user presses the add button there should be a callback function on the TableModel so that the callback is called at the correct time. Right now you need to find out that the user is even requesting to add a row. This would work the same as when you call tableModel.saveWorksheet(WorksheetSaver) and the WorksheetSaver is called if needed. Then we could address the second issue (which is what you really need), and that would be to have a method on the TableModel that simply adds a row to the worksheet when requested. In addition this should take a list of objects, not just one thing.

    public void addWorksheetRow(Object addedRowObject) {
        this.addedRowObjects.add(addedRowObject);
    }

I would not have time to do this myself, but you could easily add this functionality yourself. The only class you would have to change is the TableModel, and that is a really easy class to work with. Once you get that done just send me a patch!

Getting JMesa set up should be fairly straightforword.  The dependent jar files are all checked into subversion and I use groovy and ivy to do the build. Here is a page that describes what I do.

http://code.google.com/p/jmesa/wiki/ProjectBuild


-Jeff

Jeff Johnston

unread,
Sep 15, 2011, 12:05:50 AM9/15/11
to jm...@googlegroups.com
Also, if you have problems getting JMesa up and running be sure to just ping me right away. It is a custom build script and I would not want you to have to struggle just to get the project running locally!

-Jeff

Massimiliano Del Matto

unread,
Sep 19, 2011, 1:41:01 PM9/19/11
to JMesa
Thank you, as soon as I get time I'll try!

On 15 Set, 06:05, Jeff Johnston <jeff.johnston...@gmail.com> wrote:
> Also, if you have problems getting JMesa up and running be sure to just ping
> me right away. It is a custom build script and I would not want you to have
> to struggle just to get the project running locally!
>
> -Jeff
>
> On Wed, Sep 14, 2011 at 11:42 AM, Jeff Johnston
> <jeff.johnston...@gmail.com>wrote:
Reply all
Reply to author
Forward
0 new messages