-
1. Re: how to handle dynamic id on rich:column to use it for sort items
michpetrov Oct 2, 2015 6:08 AM (in response to voltandoao505)If you debug your application you'll see the getId() method is called after every request. JSF is recreating the component with each request so the columns get assigned a new id every time. This would cause even more problems if it wasn't an id, a getter method simply needs to return a value and not perform any other actions.
Instead of trying to fix a problem in your solution explain the original problem. Why don't you update your data so that every column has an id? DataTables can be made sortable, why do you require the columns to have an id? They're getting a random id assigned anyway.
-
2. Re: how to handle dynamic id on rich:column to use it for sort items
voltandoao505 Oct 2, 2015 2:18 PM (in response to michpetrov)thank you very much for all the attention that you gave to my question.
actually, we are using our own component which is based in richfaces components, which means that we are using a component that contains others, that was developed by the software factory that we are working for.
this component when is displayed in html page hasn't an id, do you get it? when we analyzed the code we didn't find the id for the element, so we created this property (id) as you saw in the code I did put in the question.
i need to have html ids. i don't need to have id for columns in the table from the database, because we already specified these ones, and we use them to make possible to sort the elements from the column. this property is called columnId, that has the same value as we find in the id columns from the tables.
but i need to automatize the tests in the system, so, for the order of priority, we must have ids to the rich columns, which is concatenated with a constant value and has always two values which are asc or desc from ascending and descending sorting.
so, in our java code, we get part of an id from the field, not its complete, by using xpath. but we cannot just put a fixed id like asc or desc, because the columns will be repetead and this breaks the system, 'cause repetead ids are not allowed.
i hope that i clarified to you our problem. and i really understood the problem by using the function getId() as explained in your answer. a friend of mine, who is in developer team, told me about this, that jsf would probably generating different ids, but he was not able to tell me why, but you did.
so, again i thank you for the answer and the attention.
-
3. Re: how to handle dynamic id on rich:column to use it for sort items
michpetrov Oct 5, 2015 5:46 AM (in response to voltandoao505)The generated HTML for rich:dataTable looks like this:
<table> <thead> <tr> <th> … <tbody> <tr> <td> …
Each one of those elements will have an id even if you don't set one, is that not the case?
You also said that some columns have ids so I'm assuming they are referencing some property in the datamodel that is missing for the other columns.
I don't understand how you're sorting the table, rich:dataTable comes with built-in sorting but even if you use a custom one you do not need an id for that.
-
4. Re: how to handle dynamic id on rich:column to use it for sort items
voltandoao505 Oct 5, 2015 4:26 PM (in response to michpetrov)yes, all html elements have an id by specifying it or not. i don't know why i said otherwise, maybe to get a quick answer to your answer.
but we have in our datatables html elements to sort elements in forms ascendent or descendant, as shown in the image above.
our problem is that we have multiples tables, not only one like this in the entire system. so, we thought of generating ids with 'asc' and 'desc' in its ends would resolve our problem, when we are not automating the page, when we are doing it, we set ids to them, do you get it? because of this, we generated random ids for all columns that we didn't set previously.
i appreciate your attention but we resolved this issue by using the property html styleclass, because it does not interfere in the rich component behaviour, so does not have any impact in the system. it's a palliative way to get the columns names and make possible our tests.