I want to show the data from the database but can not repeat the same profile, just add a location to the existing profile. With the example above becomes clear:
+-------------------+---------------+---------------+
| PROFILE | LOCATION | STATUS |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
| Admin | Chief | OK |
+-------------------+---------------+---------------+
| Director | Supervision | OK |
+-------------------+---------------+---------------+
| Secretary | Supervision | OK |
+-------------------+---------------+---------------+
| | Admin | OK |
| | Chief | OK |
| Chief-accessor | Director | OK |
| | Secretary | OK |
| | Supervision | OK |
+-------------------+---------------+---------------+
With this piece of code that is my datatable, I can only repeat them, but I can not group them:
<rich:panel header="User location info" style="margin: 20px 0 !important;">
<h:dataTable id="userLocationList"
value="#{userLocation.list()}" var="row"
styleClass="rich-table"
headerClass="rich-table-subheader rich-table-subheadercell rich-table-thead"
rowClasses="rich-table-row"
columnClasses="rich-table-cell,rich-table-cell,rich-table-cell">
<h:column>
<f:facet name="header">
<h:outputText value="Profile" />
</f:facet>
<center>
<h:outputText value="#{row.profile}" />
</center>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Location" />
</f:facet>
<h:outputText value="#{row.location}" />
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<center>
<h:outputText value="#{row.profile.status ? 'OK' : 'Inactive'}" />
</center>
</h:column>
</h:dataTable>
</rich:panel>
Like this:
+-------------------+---------------+---------------+
| PROFILE | LOCATION | STATUS |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
| Admin | Chief | OK |
+-------------------+---------------+---------------+
| Director | Supervision | OK |
+-------------------+---------------+---------------+
| Secretary | Supervision | OK |
+-------------------+---------------+---------------+
| Chief-accessor | Admin | OK |
+-------------------+---------------+---------------+
| Chief-accessor | Chief | OK |
+-------------------+---------------+---------------+
| Chief-accessor | Director | OK |
+-------------------+---------------+---------------+
| Chief-accessor | Secretary | OK |
+-------------------+---------------+---------------+
| Chief-accessor | Supervision | OK |
+-------------------+---------------+---------------+
Method list() from UserLocation is just a select in table_user_location:
select userLoc from UserLocation userLoc where userLoc.user.id = :userId
I've tried to follow some answers here in StackOverflow that say to put a datatable inside another datatable, but as I could was to repeat all locations without group profiles, example:
+-------------------+---------------+---------------+
| PROFILE | LOCATION | STATUS |
+-------------------+---------------+---------------+
+-------------------+---------------+---------------+
| | Chief | |
| | Supervision | |
| | Supervision | |
| | Admin | |
| Admin | Chief | OK |
| | Director | |
| | Secretary | |
| | Supervision | |
+-------------------+---------------+---------------+
| | Chief | |
| | Supervision | |
| | Supervision | |
| | Admin | |
| Director | Chief | OK |
| | Director | |
| | Secretary | |
| | Supervision | |
+-------------------+---------------+---------------+
| | Chief | |
| | Supervision | |
| | Supervision | |
| | Admin | |
| Secretary | Chief | OK |
| | Director | |
| | Secretary | |
| | Supervision | |
+-------------------+---------------+---------------+
| | Chief | |
| | Supervision | |
| | Supervision | |
| | Admin | |
| Chief-accessor | Chief | OK |
| | Director | |
| | Secretary | |
| | Supervision | |
+-------------------+---------------+---------------+
| | Chief | |
| | Supervision | |
| | Supervision | |
| | Admin | |
| Chief-accessor | Chief | OK |
| | Director | |
| | Secretary | |
| | Supervision | |
+-------------------+---------------+---------------+
And so it goes...
My doubt is the generic query I'm doing, so the duplicate content in the table. Does anyone have an idea for this operation?
Questions related:
Nested datatable in JSF 2.0
JSF: Empty nested dataTable
JSF, datatable in datatable
As I was not able to do it the way they return all locations for the same profile and using only one query, I decided to do differently, I thought of using two queries, one for all without repetition profiles (select distinct ...) and one for each location according to the profile. Only realized (correct me if I'm wrong) the property h:datatable renders by columns rather than rows. So, in part, was the first profile column returned all without repeating profiles, however the locations were the same in each cell was shown all user locations without distinction if the cell that the location would appear was of a given profile. That's when I realized I was very focused in locations where the focus was to be on user profiles.
Ran the select distinct the profiles and created a method to return the locations that profiles at the time the table was created. Just as the reported questions, a datatable inside another datatable.
Finally got my code:
<rich:panel header="Informations" style="margin: 20px 0 !important;">
<h:dataTable id="userLocationList"
value="#{userLocation.list()}" var="row"
styleClass="rich-table"
headerClass="rich-table-subheader rich-table-subheadercell rich-table-thead"
rowClasses="rich-table-row"
columnClasses="rich-table-cell,rich-table-cell,rich-table-cell">
<h:column>
<f:facet name="header">
<h:outputText value="Profile" />
</f:facet>
<center>
<h:outputText value="#{row.name}" />
</center>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Localizations" />
</f:facet>
<h:dataTable id="uLoc" var="c"
value="#{home.getLocByProfile(row.idProfile)}">
<h:column>
<h:outputText value="#{c}" />
</h:column>
</h:dataTable>
</h:column>
<h:column>
<f:facet name="header">
<h:outputText value="Status" />
</f:facet>
<center>
<h:outputText value="#{row.active ? 'OK' : 'Inactive'}" />
</center>
</h:column>
</h:dataTable>
</rich:panel>
Related
The problem I have is the following:
I have a datatable with a list of the class Producto, which internally consists of several fields of simple type and 2 objects of type Proveedor. Categoria and TipoProveedor are enums.
public class Producto {
private int idProducto;
private String nombre;
private Categoria categoria;
private Proveedor proveedorUno;
private Proveedor proveedorDos;
}
public class Proveedor {
private int idProveedor;
private TipoProveedor tipoProveedor;
private String nombre;
private BigDecimal precio;
}
My problem is that in each row of the datatable all the information must be displayed so that if a single filled provider comes, it will be displayed normal but if both fillings come, the part of the provider information is divided into 2 rows. Example:
|------------------------------------------------------------------|
| Nombre | Categoria | idProveedor | Nombre Proveedor | Precio |
|------------------------------------------------------------------|
| DIN-A4 | Papel | 10256 | Proveedor Manolito | 10.59 € |
| | | 24747 | Proveedor Fulanito | 10.75 € |
|------------------------------------------------------------------|
| DIN-A5 | Papel | 10256 | Proveedor Menganito | 4.77 € |
|------------------------------------------------------------------|
| DIN-A3 | Papel | 44787 | Proveedor Saturnino | 14.77 € |
|------------------------------------------------------------------|
I had tried to do it with a datatable like this but it does not look exactly as I need:
<p:dataTable id="listadoProductos" widgetVar="listadoProductos"
value="#{listadoProductosBean.listadoProductos}" var="producto"
emptyMessage="#{messages['tabla.VACIA']}">
<p:column headerText="#{messages['listado.NOMBRE']}">
<h:outputText value="#{producto.nombre}" />
</p:column>
<p:column headerText="#{messages['listado.CATEGORIA']}">
<h:outputText value="#{producto.categoria.desc}" />
</p:column>
<p:column headerText="#{messages['listado.ID_PROVEEDOR']}"
rendered="#{producto.proveedorUno != null && producto.proveedorDos != null}">
<p:panelGrid columns="1">
<p:row>
<h:outputText value="#{producto.proveedorUno.idProveedor}" />
</p:row>
<p:row>
<h:outputText value="#{producto.proveedorDos.idProveedor}" />
</p:row>
</p:panelGrid>
</p:column>
<p:column headerText="#{messages['listado.ID_PROVEEDOR']}"
rendered="#{producto.proveedorUno != null && producto.proveedorDos == null}">
<p:panelGrid columns="1">
<p:row>
<h:outputText value="#{producto.proveedorUno.idProveedor}" />
</p:row>
</p:panelGrid>
</p:column>
<p:column headerText="#{messages['listado.ID_PROVEEDOR']}"
rendered="#{producto.proveedorUno == null && producto.proveedorDos != null}">
<p:panelGrid columns="1">
<p:row>
<h:outputText value="#{producto.proveedorDos.idProveedor}" />
</p:row>
</p:panelGrid>
</p:column>
</p:dataTable>
Is it possible to do what I say?
My version of Primefaces is 6.2 but I could upgrade if I can get what I want.
Many Thanks.
NOTE: it could be worth it (although it is not desired) that the part of the providers divided into 2 appears even if there is only one. Example:
|------------------------------------------------------------------|
| Nombre | Categoria | idProveedor | Nombre Proveedor | precio |
|------------------------------------------------------------------|
| DIN-A4 | Papel | 10256 | Proveedor Manolito | 10.59 € |
| | | 24747 | Proveedor Fulanito | 10.75 € |
|------------------------------------------------------------------|
| DIN-A5 | Papel | 10256 | Proveedor Menganito | 4.77 € |
| | | | | |
|------------------------------------------------------------------|
| DIN-A3 | Papel | 44787 | Proveedor Saturnino | 14.77 € |
| | | | | |
|------------------------------------------------------------------|
You can use the groupRow attribute on the columns you want to group, so:
<p:column headerText="#{messages['listado.NOMBRE']}" groupRow="true">
<h:outputText value="#{producto.nombre}" />
</p:column>
<p:column headerText="#{messages['listado.ID_PROVEEDOR']}">
<h:outputText value="#{producto.proveedorUno.idProveedor}" />
</p:column>
See:
https://www.primefaces.org/showcase/ui/data/datatable/rowGroup.xhtml (rowspan)
https://primefaces.github.io/primefaces/8_0/#/components/datatable?id=row-grouping
To use a fixed row height, give your table a styleClass and style the table cells to have a min-height using CSS.
See:
How do I override default PrimeFaces CSS with custom styles?
Let's say I have a table as follows
| make | model | license | mileage | book value |
|-----------|-----------|---------|---------|------------|
| ford | F150 | 123456 | 34000 | 35000 |
| chevrolet | Silverado | 555778 | 32000 | 29000 |
| | | | | |
Let's pretend I had to unpivot and all that, which I've done. I just used simplified data for this question. Now let's assume I run the query today (July 30th) I want my result to be:
| Date | make | model | license | mileage | book value |
|------------|-----------|-----------|---------|---------|------------|
| 2020-07-30 | ford | F150 | 123456 | 34000 | 35000 |
| 2020-07-30 | chevrolet | Silverado | 555778 | 32000 | 29000 |
| | | | | | |
I want to add the day the query is run. However, here's where I am stuck. Let's say I ran the query tomorrow, I want it to add the new values to the bottom of the existing result:
| Date | make | model | license | mileage | book value |
|------------|-----------|-----------|---------|---------|------------|
| 2020-07-30 | ford | F150 | 123456 | 34000 | 35000 |
| 2020-07-30 | chevrolet | Silverado | 555778 | 32000 | 29000 |
| 2020-07-31 | ford | F150 | 123456 | 34200 | 35000 |
| 2020-07-31 | chevrolet | Silverado | 555778 | 32156 | 29000 |
This would allow me to track the fleet over time.
Any help would be greatly appreciated
I have two spreadsheets--one represents locations where the road was recently repaired and the second shows all eligible roads based on the road's speed limit. The first spreadsheet has a list of ID's (Column B) and a beginning point (Column E) and ending point (Column F) for the repair location. The second spreadsheet may have multiple matches for each ID (Column A) and the eligible beginning points (Column P) and ending points (Column Q).
I want to compare to see if any portions of the eligible roads are already on the recently repaired list.
Completed repairs = 18SealCoatMap where B=Highway Name, E=Beginning Limit, and F=Ending Limit.
| County | Highway | BDFO | EDFO |
|-----------|-----------|--------|--------|
| Guadalupe | FM0078-KG | 13.064 | 14.018 |
| Guadalupe | FM0078-KG | 14.018 | 14.848 |
| Guadalupe | FM0078-KG | 14.848 | 18.991 |
| Guadalupe | FM0465-KG | 0 | 3.342 |
Elibible repairs =MLOVER45 where A=Highway Name, B=Line ID, P=Beginning Limit, and F=Ending Limit.
| Lane | ID | Highway | SpeedLimit | Begin_DFO | End_DFO |
|-----------|----|---------|------------|-----------|---------|
| FM0078-KG | 1 | FM0078 | 50 | 13.064 | 14.018 |
| FM0078-KG | 2 | FM0078 | 55 | 14.845 | 14.848 |
| FM0078-KG | 3 | FM0078 | 50 | 14.018 | 14.845 |
| FM0078-KG | 4 | FM0078 | 55 | 14.848 | 15.006 |
So far, I'm only working with the beginning point of each eligible location. When I get a working formula, I'll copy it for the ending location.
Here's a more varied example...
Eligible Locations:
| Lane | ID | Highway | SpeedLimit | Begin_DFO | End_DFO |
|-----------|-----|---------|------------|-----------|---------|
| FM0791-KG | 369 | FM0791 | 70 | 0 | 6.909 |
| FM0791-KG | 372 | FM0791 | 70 | 6.909 | 18.603 |
| FM0791-KG | 377 | FM0791 | 55 | 19.286 | 19.486 |
| FM0791-KG | 378 | FM0791 | 70 | 19.486 | 30.971 |
Completed Locations:
| County | Highway | BDFO | EDFO |
|----------|-----------|--------|--------|
| Atascosa | FM0791-KG | 21.619 | 23.196 |
| Atascosa | FM0791-KG | 21.619 | 23.196 |
| McMullen | FM0791-KG | 0.000 | 7.017 |
| McMullen | FM0791-KG | 0.000 | 7.017 |
| McMullen | FM0791-KG | 2.190 | 2.760 |
| McMullen | FM0791-KG | 2.190 | 2.760 |
I tried the following formula but every location came back true:
=IF(A2='18SealCoatMap'!B2:B345,AND(MLOVER45!P2>'18SealCoatMap'!E2:E345,MLOVER45!P2<'18SealCoatMap'!F2:F345),TRUE)
Then I tried:
=INDEX('18SealCoatMap'!B2:B345,MATCH(A2,IF(P2>'18SealCoatMap'!E2:E345,P2<'18SealCoatMap'!F2:F345)),2)
but all of the results came back #N/A
I expect the outcome to be the ID number for the eligible location (or TRUE) if there's a match so that I can schedule repairs for all locations that do not already fall within the limits. Based on the results, I will then schedule locations that are entirely or partially due for repair.
I have a Python script that writes to a SQLite3 database and the table is called notify_users, and it has two text-content columns, language_code and username.
Visualized, then, the notify_users database looks like this:
| language_code | username |
---------------------------------
| de | jane_doe |
| sv | jane_doe |
| fi | jane_doe |
| de | tom_petty |
| zh | tom_petty |
What I'd like to do is be able to use two criteria (both the language_code and username) to delete a specific record.
For example, I'd like to delete the record that has both jane_doe in the username column and de in language_code.
| language_code | username |
---------------------------------
| de | jane_doe | X
| sv | jane_doe |
| fi | jane_doe |
| de | tom_petty |
| zh | tom_petty |
How can I format a DELETE FROM notify_users... query appropriately to accomplish this task? Thanks in advance!
You can string together conditions using and:
conn.execute("""delete from notify_user
where language_code = ? and username = ?;""",('de','jane_doe'))
A while ago I asked how to perform the "Through Associations".
I have the following tables :
genres
+-----------+--------------+------+-----+
| Field | Type | Null | Key |
+-----------+--------------+------+-----+
| id | int(6) | NO | PRI |
| slug | varchar(255) | NO | |
| parent_id | int(11) | YES | MUL |
+-----------+--------------+------+-----+
genres_radios
+----------+--------+------+-----+
| Field | Type | Null | Key |
+----------+--------+------+-----+
| genre_id | int(6) | NO | MUL |
| radio_id | int(6) | NO | MUL |
+----------+--------+------+-----+
radios
+-----------+--------------+------+-----+
| Field | Type | Null | Key |
+-----------+--------------+------+-----+
| id | int(5) | NO | PRI |
| slug | varchar(100) | NO | |
| url | varchar(100) | NO | |
+-----------+--------------+------+-----+
The answer is there : Sails.js associations.
Now I was wondering, if I had a new field in the genres_radios table, for example:
genres_radios
+----------+--------+------+-----+
| Field | Type | Null | Key |
+----------+--------+------+-----+
| genre_id | int(6) | NO | MUL |
| new_field| int(10)| NO | |
| radio_id | int(6) | NO | MUL |
+----------+--------+------+-----+
How would I do to get that attribute while making the join?
It is not implemented yet. Quoting Waterline's documentation :
Many-to-Many Through Associations
Many-to-Many through associations behave the same way as many-to-many
associations with the exception of the join table being automatically
created for you. This allows you to attach additional attributes onto
the relationship inside of the join table.
Coming Soon