0

I'm developing a dynamic form using Mojarra 2.2.5 and Primefaces 4.0 and i need to implement a datatable with dynamic content. Unfortunately when i try to submit form appears this error:

java.lang.NumberFormatException: Trying to extract rowIndex from clientId 'id_of_my_datatable:j_id1:j_id1'

I generated datatable by code using it, inspired by Primefaces Showcase (http://primefaces.org/showcase/ui/datatableDynamicColumns.jsf) and from (Stack Overflow discussion)

    private DataTable addList(UIComponent parent, String labelStr, String id, List<ColumnModel> rowItems, List<Map<String, String>> values, String styleClass,
        boolean isRequired, String updateComponents)
{
    OutputPanel outputPanel = new OutputPanel();
    outputPanel.setStyleClass("question_panel col-md-11");

    if (labelStr != null)
    {
     addLabel(outputPanel, id, labelStr, "component_label col-md-11");
    }

    DataTable dataTable = new DataTable();
    dataTable.setValue(values);
    //mapModel = values;
    //ValueExpression veTable = super.createValueExpression("#{composerTestBean.mapModel}", List.class);
    //dataTable.setValueExpression("value", veTable);
    dataTable.setVar("model");
    dataTable.setId(id);
    dataTable.setRowIndexVar("rowIndex");

    Columns columns = new Columns();
    columns.setValue(rowItems);
    //columnModel = rowItems;
    //ValueExpression veColumns = super.createValueExpression("#{composerTestBean.columnModel}", List.class);
    //columns.setValueExpression("value", veColumns);
    columns.setVar("column");
    columns.setColumnIndexVar("colIndex");

    HtmlOutputText headerText = new HtmlOutputText();
    ValueExpression veHeader = super.createValueExpression("#{column.header}", String.class);
    headerText.setValueExpression("value", veHeader);
    columns.getFacets().put("header", headerText);

    HtmlOutputText valueText = new HtmlOutputText();
    ValueExpression veValue = super.createValueExpression("#{model[column.property]}", String.class);
    valueText.setValueExpression("value", veValue);
    columns.getChildren().add(valueText);

    dataTable.getChildren().add(columns);

    outputPanel.getChildren().add(dataTable);

    parent.getChildren().add(outputPanel);

    return dataTable;
}

As you can see I've also tried to use valueExpression and the property bean binding, but nothing is changed. setRowIndexVar() and setColumnIndexVar() methods are just attempts to resolve the question.

I also read that it could be a Mojarra bug on this discussion (it should be resolved) and in another one that is a Primefaces bug (I can't apply patches on project libraries).

Also I try to follow this post and this remove this exception but brings others problem to my page about update.

Do You think I'm doing something wrong? Or Is it just an unresolvable case? Thanks in advance.

Community
  • 1
  • 1
giaffa86
  • 708
  • 1
  • 9
  • 22
  • It should work. I suppose it is a bug in Mojarra (the stack trace shows the state saving algorithm gets broken), maybe you should try with MyFaces to see if the same problem happens. In MyFaces there is another different algorithm to deal with the ids, and another different algorithm to deal with the state, maybe that can be helpful. – lu4242 Apr 09 '14 at 14:39
  • I could do it but I will not switch to MyFaces. I've already did a test on MyFaces and I didn't like it,I had a lot of problems there so I decide to switch to Mojarra(successfully used in another project). I would like to know if is possible resolve it without switch. – giaffa86 Apr 11 '14 at 08:25
  • I doubt that the problem can be solved easily, but you never knows. There is a new web config param in MyFaces 2.2 to help to the guys that uses the old facelets 1.1 /Mojarra syntax called org.apache.myfaces.STRICT_JSF_2_FACELETS_COMPATIBILITY. You could try that to see if it works for you. Besides that, there is nothing else to do but change the approach and try to solve it in another way. – lu4242 Apr 11 '14 at 11:25
  • I didn't found nothing to similar to STRICT_JSF_2_FACELETS_COMPATIBILITY for Mojarra. I will try another approach when I will find it. :( – giaffa86 Apr 23 '14 at 13:08
  • 1
    It is a web config param for MyFaces 2.2 that make it work similar to Mojarra in that part. It was added, because over the time we founded people that wanted to do a migration, but they had apps with the old logic, that has been proved as incorrect from MyFaces perspective. The updated web config param list is [HERE](http://myfaces.apache.org/core22/myfaces-impl/webconfig.html). I know you are stuck with Mojarra, so I'm just trying to help here, because for some guys in your same situation, this has been helpful. – lu4242 Apr 23 '14 at 13:43

0 Answers0