2

I am trying to preserve state of a table using RichFaces. RichFaces has this functionality of tableState which is a json string of all information about the table. The tableState string right now looks like this

{"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}}

I am curios to know how this identifiers are generated i.e. j_idt388 etc. I tried giving id to the column and the richfaces tableState string honored that. The tableState json looks like this now

{"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}}

I preserve this json string so that in future if I log in, I should see the state of table same as I left.

Problem is that once I log out and log in into my application. RichFaces fails and throws an exception. It makes me feel its not able to recognize the json string anymore but I wonder why. Here's the exception:

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]
Bob
  • 5,510
  • 9
  • 48
  • 80
Nick01
  • 349
  • 2
  • 8
  • 22

1 Answers1

1

JSF generates IDs for elements, where the developer hasn't set his own ID in the element's attribute. This results in the IDs beginning with j_id you posted in your first code snippet (for example j_idt433). You can read more about the ID generation in this answer.

ID generation depends on counting the number of elements. Thus, if you persist a table state and later try to restore it, and the number of elements before the table changed, the IDs are not correct anymore. This may result in the exception you posted.

To prevent this, just give every <rich:column /> an ID.

Community
  • 1
  • 1
Bob
  • 5,510
  • 9
  • 48
  • 80