How set a table row's attribute class dynamically with clojure/enlive? - java

I have created a table using enlive template engine. what I have done, is create a singe table row and repeated that row up to the no of row needed dynamically. But, I have some problems update the each row's attribute class.
How can I set the class attribute for every table row dynamically, say even odd manner?

There is a thread on the enlive mailing list where Christophe Grand explains how to do this.
I also share the feeling that if you can use nth-child selector it is way cleaner.

Related

JTable based on a list of Objects, like TableView's items list

I have an application that was using a JavaFX TableView, but I need to switch to using a JTable because of certain issues I was running into.
TableViews take in a list of objects and each column is a field in each object, for example, a Person object with columns for First Name, Last Name, and email. If you edited the email field in the table, it would go out and edit the email in that Person object. If I selected rows in the table, I could get the Person objects from those selected indices.
Is there a way to do this in JTable?
You need to create a custom TableModel for your Person object.
Check out Row Table Model which gives a step by step example how you might do this.
It also provide a generic class to make the implementation easier and include additional generic methods for accessing the data in the TableModel.
You can also follow the BeanTableModel link for a TableModel you can use without any custom code.

How to avoid page Break between two detail rows of table in BIRT

I have eclipse version 3.4.1 for BIRT Reporting,
I need to avoid page break between two detail rows of a table.I didn't found "avoid" option in page break properties.
My table showing data in two detail rows so may Table can be break at the end not in between two detail rows.
Example:
Employee No/Employee Name
--------------------------
Detail row 1 [employee_No]
Detail row 2 [employee_Name]
In above, I need to avoid page break between employee_No and employee_Name
Thanks in Advance.
The easiest solution if your design criteria will allow it; is to use a table with 2 detail columns. Place your employee number in the left column and the employee name in the right column, this way there is no row to break, everything is on the same row.
The harder way but it will allow you keep the existing format and control page breaks between employee name and number is to use a list element with a table inside it.
In this example I have a list with a table (actually two tables) in the detail line of the list. The table(s) each return only one occurrence per primary key (in my case a ticket ID, in yours an employee ID). You can get as fancy as you want with table (I have extra columns for spacing, and two columns of data & Two columns of labels.)
You can then avoid page breaks in your table.
I built this report a couple years ago, and have not done anything similar for a while, so all the details of making it work are not fresh in my mind, but I don't recall it being overly difficult to figure out.
I know this is quite old, but with versions 2.5 and following, you can define where in your layout do you want to avoid page breaks.
To do so, select an element in your layout, go to property editor -> page break and select "avoid" in the desired position.
Keep in mind that, depending on your layout, you probably need to set "avoid" in different point, for example after "first rows" and before "second rows" of each record in the question example.

How made dataTable in rowExpansion section in another dataTable with common model

I have complex dataTable witch paganation, dynamic columns, lazyloading, sotring , filtering, multi selection. Now I have to use this table and model in another context. All rows in table now must have "subtable" with the same colums, multiselection woring in outer table context without pagination, sorting, fitering. I schould use dataTable(row Expansion(inner dataTable))?
The actual question is not clear. And I must warn you about heavy table structures in primefaces, they tend to not function as intended. It's generally a good approach to simplify the structure (on JSF/PF elements level).
For example, instead of using tables inside tables you could use JSTL for the outer iteration. There are also SubTable (http://www.primefaces.org/showcase/ui/data/datatable/subTable.xhtml) and TreeTable (http://www.primefaces.org/showcase/ui/data/treetable/basic.xhtml) elements available. You could also adapt DataGrid or DataList elements for your purposes...

How do I make the data passed in a table is no longer displayed in the other

I have a problem for a couple of hours does not resolve, is the following.
I have a Table A and Table B.
Table A is filled with a ResultSet, and Table B is being added to products available in Table A
What I am trying to achieve is: Once you click on the Add button Spend the product of Table A to Table B, and the last product is no longer displayed in Table A.
The responsibility to inform the tables that data was added and remove to and from them is completely up to you, and should be handled in each table's model. If you want to 'move' data from one to the other, you need to remove that data from the model of the first table and add it to the 2nd. Once that is done, both models need to be informed of the change via fireTableDataChanged, so they know to redraw.
I would endorse #Colby's and #GETah's suggestion to focus on the model. Also consider giving modelA and modelB access to a common data structure, say List<Product>, where each Product has a boolean attribute that allows each model to to decide what it's corresponding view can see.
Get and remove the selected element from tableA's TableModel and add it to the tableB's TableModel and then refresh both tables.
See this tutorial on using JTable and TableModel

How to retrieve "${selectedElement}" from a JTable where the elements are bound to a List

In my application I have a JTable and a List.
The List:
The list is populated using a JPA query. The user can re-execute the query by changing attributes in the GUI. Let's assume the query has a named parameter "year" and the user can change this. Then the following happens (simplified by leaving out exception handling):
myList.clear()
mylist.addAll( myQuery.setParameter("year", 2010) )
As the list changes, the binding fires the required handlers and the table now reflects the new dataset.
The JTable:
The contents of the JTable come from a BeansBinding (more precisely a JTableBinding). The binding source is the aforementioned list.
The query is only executed for intensive tasks. Like applying a rough filter on a huge dataset. The earlier example with the year is a good example. This will always return a manageable chunk of data to the client. Now, to have a more responsive user experience, more fine-grained filters happen in the JTable itself. This avoids unnecessary round-trips to the database.
Next, assume the following scenario: A user selects a row in the table and hit's the delete button. If the table has not been filtered the required code is straightforward (again, no error-checking, concurrency locking, and exception handlers for code simplicity):
MyObject = myList.get( myTable.getSelectedRow() );
myEntityManager.getTransaction().begin()
myEntityManager.remove( myObject )
myEntityManager.getTransaction().commit()
However: If the table is filtered on the client side, the table won't reflect the data inside the List. So getSelectedRow() will not return an index which will map to the same entry in the List (I have not tested this, but I beleive I am correct with this assumption?)
So... My question:
How best to solve this?
A possible solution?
I've solved the problem at hand with the following:
I created a new Bean called selectedTableElement which contains a member holding the element which is currently selected in the table.
Next, I created a new binding (source: my table, target: my "selectedElement" bean) using
binding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, myTable, ELProperty.create("${selectedElement}"), selectedTableElement, BeanProperty.create("selectedElement"), "selectedElementBinding");
This solution effectively solves the problem by keeping track of the selected element of the table using Beans Binding.
But is this really necessary? It feels clunky to me. A whole new class only the encapsulate the selected element? Is there no other, more direct way of retrieving the "${selectedElement}" property of the JTable?
I'll try to answer to both your questions.
Regarding the first question (the filtered selected index vs the real list index):
I assume that you bound the table using BeansBinding, via createJTableBinding. So, the client-side filtering might be applied through the use of swing TableRowSorter and RowFilter. Am I right ? if so, you could use the method
int row = myTable.convertRowIndexToModel(myTable.getSelectedRow());
to convert the selected row in the filtered view to the actual selected row in the model.
For the second question (bean to keep the selected item of table)
You could also create a binding using this as the source/target object, and create a property selectedElement in the class containing the table. Thus, you won't need another class. The code will be : createAutoBinding(UpdateStrategy.READ_WRITE, myTable,
ELProperty.create("${selectedElement}"), this, BeanProperty.create("selectedElement"), "selectedElementBinding");
(note also that READ_WRITE binding is not really used, as beans binding does not support changing the selected element from the bound property)

Categories

Resources