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]
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.
I would like to know what is the prefered way to handle hour-minute input fields in JSF.
I am using JSF2.2 with primefaces 5.2
I would like to have one input field for hours and one for minutes and have the value saved to dabase in decimal and fraction format.
Then it would be nice alo so have a converter for this, for example if you have the need to store in minute or second precision. Is there already something availabe or do I realy have to write one of my own?
In my JSF2 application, I want my double value to be displayed without exponential notation. Is it possible?
I cannot use NumberFormat or DecimalFormat since its going to change my data type to String.
I understand from Java documentation, if my double value is less than 10^-3 or greater than or equal to 10^7, then it is represented in so-called "computerized scientific notation"(Ref: http://docs.oracle.com/javase/7/docs/api/java/lang/Double.html#toString()).
And, In JSF while displaying a double value it will internally convert any data type to string.
For example, if my double value is 9999999999 it is getting displayed as 9.9e^9. I want it to be displayed as it is. i.e 9999999999
But, it there any possibility to override this character of Double or is there any other approach to solve this issue?
The correct solution for problems like this is to pass the internal data type around for as long as possible. Just at the moment when you display it to the user, you format it properly using DecimalFormat.
So you have to find all the places in your JSF2 UI where you display doubles and use the proper formatters there.
Note that DecimalFormat isn't threat safe, so you have to create a new formatter for each request (at least).
If your code provides a double or Double, you can display that value directly in the page using a converter:
<h:outputText value="#{myBean.someDoubleValue}">
<f:convertNumber pattern="0"/>
</h:outputText>
I am using JSF,Primefaces.
I have a search Criteria Functionality in my App, there i am facing a problem with calendar date.
I am using this piece of code for my application.
<p:calendar id="Date" value="#{bean.fromDate}" pattern="MM/dd/yyyy" showOn="button"/>
I faced this sort of issue that it is accepting even i had given the date 214/03/2013
as and then converting it into 10/03/2030 and performing the action!
But,What exactly i need to do is either to display a message or else to mask that input field as 99/99/9999.
I referred this Link
In my scenario i should not use readonlyInput="true" because i may or may not give a date.
If i am using that then i am unable to clear the field back to empty,because i am in use with #SessionScoped.
Having a look to how Primefaces Calendar works, it turns to use by default Java's SimpleDateFormat to do the parsing work. If you have a look at the docs, Java uses heuristics to force any given input to convert to an specific date.
Specify whether or not date/time parsing is to be lenient. With lenient parsing, the parser may use heuristics to interpret inputs that do not precisely match this object's format. With strict parsing, inputs must match this object's format.
That's why your calendar input is accepting that weird dates when they don't even exist. The key is to provide the calendar your custom converter which doesn't accept a lenient date format. JSF already provides one:
<p:calendar ...>
<f:convertDateTime pattern="MM/dd/yyyy" />
</p:calendar>
That would throw a conversion error if the end user provides a non-existing date.
See also:
Incorrect date parsing using SimpleDateFormat, Java
What is the use of "lenient "?
So, I´ve got an issue that someone might have solved (or so I hope). I have a datetime field that I use in a contenttype (on a listtemplate) that has its own editform.
Here´s a walkthrough of what happens:
Adding a value to the datetime column and saving the updated value shows up (as expected).
Updating the datetime column and adding null (emptying out the value) via the editform. The value isn´t updated but instead showing the old value.
I did some experimenting with this and I came to the conclusion that if I add an eventreceiver and try to update the value there it doesn´t even enter the eventreceiver as a blank string (I had an idea that the value is as a blank string and sharepoint can´t parse that to a null datetime) which leads me to think that there´s an issue with the fieldcontrol that causes this. I also found this article on MSDN which seems to be around the same issue. And also, the datetime field in the contenttype isn´t required.
Any ideas or suggestions?
UPDATE:
Apparently this only happens when I use a custom editform. When I use one of built in listtemplates this works like a charm.
I've had similar issues with this in the past. It is indeed a known bug. One work around is to set the field to the min or max value of the type and check for this value wherever needed and do the appropriate conversions. Depending on your setup and use, you could create a trigger to convert min/max values to null and thus minimize the code required to handle such a work around.
After some deep investiongation I have found that the root of this problem is related to the fact that I was using XML node propagation between the columns in the list and the actual xml file. I had prevoiusly been struggling with this regarding stardard text fields and thought that I had taken care of the issue..apparently not. DateTime fields apparently will not get sent to the eventreceiver afterproperties if it is null as thus my code will not pick it up as a null value. I had to take case of that and add them to afterproperties if I can´t find them in afterproperties. I will make a blogpost series about these issues and post the links to this post shortly.
UPDATE:
I have now completed a blogpost about how I solved this issue. Feel free to check it out:
http://johanleino.wordpress.com/2009/08/24/node-demotion-does-not-work-with-blank-empty-values/