RichFaces ExtendedDataTable tableState error with generated ID - jsf

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.

Related

Trim string in JSF

I am building a Web application using JSF.
I have the following line in my code:
where the value is being fetched from properties file.
Suppose if the value of that particular key changes in the properties file,I don't want this value to be displayed with increased length.
Rather I need to display original string and append it with "..."
How can I achieve this?

Is there a way to add expression in RequestContext.getCurrentInstance().update("anyExpression")?

can we add ID ends with selection expression like RequestContext.getCurrentInstance().update("#([id$=myId])");
which will update all the DOM components ending with id 'myId'. i don't want to mention this expression in xhtml. The attached image shows the generated IDs.DOM structure with generated IDs. if I mention ID as form:myTableLocalId:4:myId
then it updates only single component. I want to update all the components ending with ID 'myId'
what you are looking for is expecting jsf to identify all the dom elements and update the elements ending with some specific name unfortunately JSF is not providing such type of facilities it's containing logic so you need to write logic to find all the elements ID of the DOM elements then pass the ID and JSF will update them.
You can call a Javascript function and then in Javascript you can find all the id which is ending with your matching id and then update them since now you are having ID you can do it easily.

How to pass a static field value with user entered value to managed bean with input field in jsf

I have a JSF page code snippet like below:
<h:inputText value="#{locConfigBB.fetchFldVal('FACEBOOK_PAGE_URL')}"/>
<h:inputText value="#{locConfigBB.fetchFldVal('TWITTER_ID')}"/>
My pojo 'FieldDetail' class has two attributes named 'fieldInternalName' & 'fieldInternalValue'.
The above code gives me value stored in the database associated with the 'fieldInternalName', which I am passing as parameter (e.g. 'TWITTER_ID').
But now my requirement is, if my database doesn't contain records with the given 'fieldInternalName' (i.e. 'TWITTER_ID'), I need to enter a value in the input text so that I will have a list of 'FieldDetail' (which will create records as per my user input)
It means if I would enter a value in the inputText field with label 'Facebook Id' n submit the form then my list in the baking bean will contain only one object
I had tried to search and explore but couldn't get right way to solve this problem.
How can I pass both the static value n user enterd value together to managed bean that create a list of objects ?
I would be very much greateful if anybody can help. Thanks in advance.
Let me know if further information required.

Extending Kuali Document Business Object

I am facing an issue with extended attributes on a document (trying to extend a document table). I created the original table’s PK (FDOC_NBR) in the extended table and linked the two via a foreignKey of the customized original table’s ojb entry (as an “extension” reference-descriptor). I created the bo and dd for the extension and customized the original document’s dd to add the new attributes. On the extended BO itself I also added members (with setters and getters) for the 2 new columns + for the PK column of documentNumber. I also added the new attributes to the documet’s jsp. The pertinent module definition was already extended to include custom dd, ojb, etc. files.
Indeed, when opening the document the new fields are shown- however, when trying to submit the document (regardless of doing anything with the new fields) I get an error-
Error Details: OJB operation; SQL []; ORA-01400: cannot insert NULL
into ("KFSTEM"."TEM_TRVL_ARRANGER_DOC_EXT_T"."FDOC_NBR") ; nested
exception is java.sql.SQLIntegrityConstraintViolationException:
ORA-01400: cannot insert NULL into
("KFSTEM"."TEM_TRVL_ARRANGER_DOC_EXT_T"."FDOC_NBR")
Seems like somehow the system tries to insert a value of NULL into the extension’s PK field, instead of the actual document number. Trying to debug this, in the action’s route method and all the way down to DocumentDaoOjb.save (which is as far down as I can go) I see the document with the real doc number is passed on, so the problem seems to be purely with ojb trying to set this number to the extension table.
Does anyone have any experience with extended attributes on documents that could help shed some light on this?
KFS is using the KNS, and in the Kuali Nervous System, the primary key on the extended attributes object must be set through manual intervention.
In this case, it looks as if you're adding an extended attribute to a transactional document, the Travel Arranger document (TAA), which simplifies things. Basically, you'll need to extend org.kuali.kfs.module.tem.document.TravelArrangerDocument and override prepareForSave to set the document number there (it may be set already since prepareForSave should be called several times during the routing process, but there's no real harm from overwriting that information as the base document's number will remain the same).
Hope this helps!

Orchard CMS - Query based on values from ContentPicker

EDIT: Rephrased issue
I think there is either a bug or I am doing something wrong.
I add a field to the type Blogpost. This field is of type
Contentpicker. I call it Related Page.
Then I create to regular pages (ContentType Page).
I create 4 blogposts. Two blogposts get PageOne as selected value in the RelatedPage field. The other two posts get PageTwo as selected value in the RelatedPage.
Now I create a query with filter ContentType is BlogPost. And a filter with Blog Post.Related Page equals {21} (that is the Id of PageOne).
I would expect to get results BlogPostOne and BlogPostTwo. Instead I don't get results. Actually I wanted the pageid to be retrieved from the page the widget is placed on but couldn't get it to work, so I reduced back to a predefined value instead of dynamic for the filter. But like I said no results.
So is the query wrong and how should I do it then. Or is there a bug with filters for ContentPicker fields.
P.S. I will also submit an issue in Codeplex.
UPDATE
In Tokenizer all the values that contain { } are being seen as tokens and therefore are replaced. The problem is that the Ids of content items in a contentpicker field are stored with accolades. So when having {21} as the value for the filter, 21 gets tokenized and since there is no value for this token the value becomes empty. When skipping the tokenizer it works (while debugging). But one cannot skip the tokenizer, because it is very legitimate that there is a token present.
So I believe there is a bug with either the tokenizer, or the way the ids are stored in the contentitem field for contentpicker. I think it can be solved by changing the contentpicker to store numbers separated with comma's but without the accolades.
have you tried using the alias of the page instead of content id as the identifier? e.g. "/about-us", like you do in the layer rules.

Resources