具有生成ID的RichFaces ExtendedDataTable tableState错误

时间:2016-06-29 00:49:33

标签: jsf richfaces richfaces-modal

我正在尝试使用RichFaces保留表的状态。 RichFaces具有tableState的这个功能,它是有关该表的所有信息的json字符串。 tableState字符串现在看起来像这个

{"columnsWidthState":{"j_idt433":"140px","j_idt269":"32px","j_idt379":"80px","j_idt424":"200px","j_idt415":"200px","j_idt406":"110px","j_idt375":"115px","j_idt397":"80px","j_idt388":"120px"},"columnsSortState":{"j_idt433":null,"j_idt269":null,"j_idt379":null,"j_idt424":null,"j_idt415":null,"j_idt406":null,"j_idt375":null,"j_idt397":null,"j_idt388":null},"columnsOrderState":["j_idt269","j_idt375","j_idt379","j_idt388","j_idt397","j_idt406","j_idt415","j_idt424","j_idt433"],"columnsFilterState":{"j_idt433":null,"j_idt269":null,"j_idt379":null,"j_idt424":null,"j_idt415":null,"j_idt406":null,"j_idt375":null,"j_idt397":null,"j_idt388":null}}

我很想知道如何生成这个标识符,例如j_idt388等。我尝试给列赋予id,并且richfaces tableState字符串很荣幸。 tableState json现在看起来像这样

{"columnsWidthState":{"date":"140px","sessions":"110px","application":"115px","activity":"200px","kvalue":"80px","risk":"80px","account":"120px","riskFactor":"200px","status":"32px"},"columnsSortState":{"date":null,"sessions":null,"application":null,"activity":null,"kvalue":null,"risk":null,"account":null,"riskFactor":null,"status":null},"columnsOrderState":["status","application","account","kvalue","sessions","riskFactor","activity","risk","date"],"columnsFilterState":{"date":null,"sessions":null,"application":null,"activity":null,"kvalue":null,"risk":null,"account":null,"riskFactor":null,"status":null}}

我保留这个json字符串,以便将来如果我登录,我应该看到表的状态与我离开时一样。

问题是,一旦我退出并登录我的应用程序。 RichFaces失败并抛出异常。它让我觉得它不能再识别json字符串,但我想知道为什么。这是例外:

java.lang.NullPointerException: null
at org.richfaces.renderkit.ExtendedDataTableRenderer.encodeHeaderOrFooterCell(ExtendedDataTableRenderer.java:275) ~[richfaces-4.5.13.Final.jar:4.5.13.Final]
at org.richfaces.renderkit.ExtendedDataTableRenderer.encodeHeaderOrFooter(ExtendedDataTableRenderer.java:378) ~[richfaces-4.5.13.Final.jar:4.5.13.Final]
at org.richfaces.renderkit.ExtendedDataTableRenderer.encodeHeader(ExtendedDataTableRenderer.java:466) ~[richfaces-4.5.13.Final.jar:4.5.13.Final]
at org.richfaces.renderkit.ExtendedDataTableRenderer.doEncodeChildren(ExtendedDataTableRenderer.java:725) ~[richfaces-4.5.13.Final.jar:4.5.13.Final]

1 个答案:

答案 0 :(得分:0)

JSF为元素生成ID,开发人员没有在元素的属性中设置自己的ID。这会导致ID以您在第一个代码段中发布的j_id开头(例如j_idt433)。您可以在this answer中了解有关ID生成的更多信息。

ID生成取决于计算元素的数量。因此,如果您持久保存表状态并稍后尝试将其还原,并且表更改之前的元素数量,则ID将不再正确。这可能会导致您发布的例外情况。

要防止出现这种情况,只需为每个<rich:column />提供一个ID。