How to make datatable headers span a number of columns - jsf

I have a simple JSF datatable, which currently has four columns, one header row and (with current data) three data rows.
I have to add three extra columns; that part's easy.
I also want to add another header row before the existing header row with headers that span a subset of the columns.
The desired result is something like:
Column 1: first row empty; header on second row.
Columns 2-4: first row header spans 3 columns; second row has individual column headers.
Columns 5-7: first row header spans 3 columns; second row has individual column headers.
Is this possible? If so, how do I do it?
Following are images showing what it should look like.
This is the data table before I've changed anything.
Table Example 1 http://www.isw.com.au/home/sjleis/stuff.nsf/tableexample1.gif
This is the data table after I've added three columns. I was able to do this easily.
Table Example 1 http://www.isw.com.au/home/sjleis/stuff.nsf/tableexample2.gif
This shows the desired end result, which I can't figure out. Note the "Retail Sales" and "Fleet/Gov Sales" headers each span three columns.
Table Example 1 http://www.isw.com.au/home/sjleis/stuff.nsf/tableexample3.gif

This would be easy if you were using Richfaces (as Bozho mentions) with the breakBefore attribute.
Here's a quick example:
<rich:dataTable value="#{countryCodeListFactory}" var="c">
<f:facet name="header">
<rich:columnGroup>
<rich:column colspan="2">Main</rich:column>
<rich:column colspan="4">Other Details</rich:column>
<rich:column breakBefore="true">Country ID</rich:column>
<rich:column>Name</rich:column>
<rich:column>Region</rich:column>
<rich:column>Alpha</rich:column>
<rich:column>ISO</rich:column>
<rich:column>Flag Path</rich:column>
</rich:columnGroup>
</f:facet>
<rich:column>#{c.countryId}</rich:column>
<rich:column>#{c.countryName}</rich:column>
<rich:column>#{c.region}</rich:column>
<rich:column>#{c.alpha3}</rich:column>
<rich:column>#{c.isoNum}</rich:column>
<rich:column>#{c.flagImage}</rich:column>
</rich:dataTable>
If you're not then hopefully you're using facelets. Then you can build the table manually using the <ui:repeat>
<table>
<tr>
<th colspan="2">Main</th>
<th colspan="4">Details</th>
</tr>
<tr>
<th>ID</th>
<th>Name</th>
<th>Region</th>
<th>Alpha</th>
<th>ISO</th>
<th>Flag</th>
</tr>
<ui:repeat value="#{countryCodeListFactory}" var="c">
<tr>
<td>#{c.countryId}</td>
<td>#{c.countryName}</td>
<td>#{c.region}</td>
<td>#{c.alpha3}</td>
<td>#{c.isoNum}</td>
<td>#{c.flagImage}</td>
</tr>
</ui:repeat>
</table>

You can't do this with <h:dataTable>. Well, you can with some ugly hacks, like modifying the DOM with javascript and adding the desired columns, but that's not what you should do.
Take a look at RichFaces dataTable - its columns support the colspan attribute.

Related

Compare two columns, if a value is missing in one of them add to it[Excel]

I have two columns of two different tables that I want to compare (same worksheet)
I have column "A" [which belongs to a master table] where I have Owners names for different projects.
Then I have column "D" [which belongs to a table that shows the number of project each owner has]
What I want to do is that every time I write new projects with their respective Owners in the first table, if the owner is not on the second table, Column "D", that the new name is added automatically to to this column "D".
Is that possible?
Edit:
Hi thank you for your replies
Here is a graphic example.
Table1&2
Table 1 (All tasks with their owner, manually entered)
<table><tr>
<th>Owner</th>
<th>Task</th>
</tr>
<tr>
<td>Mary</td>
<td>Task1</td>
</tr>
<tr>
<td>Mary</td>
<td>Task2</td>
</tr>
<tr>
<td>Patrick</td>
<td>Task3</td>
</tr>
<tr>
<td>John</td>
<td>Task</td></tr></table>
Table 2 (all the Owners)
<table><tr>
<th>Owner</th>
<th>Overdue Tasks</th>
</tr>
<tr>
<td>Mary</td>
<td>2</td>
</tr>
<tr>
<td>John</td>
<td>1</td>
</tr>
<tr>
<td>Patrick</td>
<td>1</td>
</tr>
<tr>
</table>
So what I want is if I add new tasks in table 1 and they have an owner that is not yet in table 2, that the name of this new Owner is automatically updated in the table 2.
What If tried so far was to add a new column with =NOT(ISNUMBER(MATCH(H2,$P$2:$P$46,0)))
to check if the name is in table 2
and then tried with =IF($L2="TRUE",SUM($H2)," ") in the second table.
But I think thats a paradox and won't work
Also tried =IFERROR(VLOOKUP($H2,$P2:$P145,COLUMN(H2),FALSE),"")
But doesn't work either

Merging two spreadsheets using a script and creating HTML language

I have to merge this two stylesheet - http://www.j-e.com/Demo_Database.xlsx
The first one "DB" is a database of products, is a music shop.
As you can see I have four columns: the id of the product, the title, the price, and the tracklist.
Title and price are OK, but the column of the tracklist for now is empty.
The second one "TRACKS" is where my tracks are. Tree columns, the first one is the id of the produt who refer, the second column is the number of the track, and the third column is the title.
I need to merge all the tracks on different lines for each product from "TRACKS" in a single cell of the tracklist in "DB"
The real BESTBESTBEST is to have a structure like this in the cell tracklist of "DB" :
<table>
<tbody>
<tr>
<td>1.</td>
<td>TITLE_1</td>
</tr>
<tr>
<td>2.</td>
<td>TITLE_2</td>
</tr>
<tr>
<td>3.</td>
<td>TITLE_3</td>
</tr>
</tbody>
the question is
solved here:
http://www.vbaexpress.com/forum/showthread.php?54574-Merging-two-spreadsheets-using-a-script-and-creating-html-language
Thanks

Why hard coded value for p:inputText in p:dataTable showing blank value?

<p:column headerText="serial no">
<h:outputText value="#{helloBean.serialNo}"></h:outputText>
</p:column>
<p:column headerText="name">
<p:inputText value="srikanth"></p:inputText>
</p:column>
</p:dataTable>
The above is populated by a list of 10 objects with serial numbers from 1 to 10. The datatable renders with 10 rows with first column showing serial number correctly but the second column in all the rows is shown blank even though i hard coded column value.
What is the reason behind this!!!!
Use h:outputText tag for second column as well, this will render the values. If you want to provide input, use p:inputText tag.
<p:column headerText="name">
<h:outputText value="srikanth"></h:outputText>
</p:column>
i think the way dataTable in JSF works is that you have two important attributes value and var defined at table level, here value is a collection / arraylist of POJOs which you want to iterate and val is one item in the list / POJO at a time. in table columns using JSF components value property, you can access the value of particular properties of POJO and display their values. Number of rows displayed in table will depend on size of arrayList. For example Employee table with different attributes of employee in different columns. so one good way seems to be iterating over table's value property and rendering columns accordingly.
here since you are displaying same constant value for name for all the columns, you can use a string constant defined in bean and access it from the value property of the component and it should work.
it was little bit surprising that using
<p:inputText value="srikanth"></p:inputText>
outside a dataTable on a page results in html code <input type="text" value = "srikanth" ...> but it does not work that way inside a dataTable.
after using footer facet of column, i could see the inputText value :
<p:dataTable>
<p:column >
<f:facet name = "header">name</f:facet>
<f:facet name="footer"><p:inputText value="srikanth"></p:inputText></f:facet>
</p:column>
</p:dataTable>
the code above could generate an html <input value="srikanth"...> inside table's footer .
It seems like static content is better suited to be placed inside table columns header and footer area while actual content should be provided through dataTable's value and var attributes.

Management of retrieved dataTable columns

I have 13 columns in a table. When I display it in a <h:dataTable>, then it expands to a very wide area on the page.
Is there any way to minimize their width or to display some columns above and some columns below?
You can use h:dataTable's columnClasses attribute to set width of columns.
From the Java EE tutorial:
If columnClasses or rowClasses
specifies more than one style, the
styles are applied to the columns or
rows in the order that the styles are
listed in the attribute. For example,
if columnClasses specifies styles
list-column-center and
list-column-right and if the table has
two columns, the first column will
have style list-column-center, and the
second column will have style
list-column-right.
You can define styles for different widths and assign these styles to your columns. Here is an example:
<h:dataTable id="items"
columnClasses="list-column-center, list-column-left,
list-column-right, list-column-center">
...
</h:dataTable>
And in your css file:
.list-column-center{ width: 300px; }
.list-column-left{ width: 100px; }
If you want to display columns in rows you can use for example two datatables in a panelGrid:
<h:panelGrid columns="1">
<h:dataTable value=#{myBean.myTable} var="item">
<h:column>#{item.column1}</h:column>
...
</h:dataTable>
<h:dataTable value=#{myBean.myTable} var="item">
<h:column>#{item.column2}</h:column>
...
</h:dataTable>
</h:panelGrid>

JSF - tomahawk t:panelGrid styling

JSF:
...
xmlns:t="http://myfaces.apache.org/tomahawk">
<t:panelGrid columns="4">
...
</t:panelGrid>
It dynamically generates plain old HTML table with tr's and td's elements.
How can I set specific css styles for these tr and/or td elements?
Use columnClasses and rowClasses attributes to give each cell a unique class
For example:
<t:panelGrid columns="4" columnClasses="a,b,c,d" rowClasses="x,y,z">
</t:panelGrid>
columnClasses
The columnClasses attribute accepts a comma-delimited list of CSS style classes that will be applied to the columns of the table. Style classes for an individual column may also be defined in a space separated list. A style class is applied to a table column as the value for the class attribute of rendered td or th element.
The algorithm used to apply the CSS style classes to the table columns is simple. In the table rendering process, style classes are applied to columns one at a time until (a) there are no more columns to display or (b) there are no more style classes to apply.
* If (a) happens at the same time as (b), the next row in the table is rendered.
* If (a) happens before (b), the remaining style classes are ignored.
* If (b) happens before (a), the remaining columns will not have style classes.
rowClasses
The rowClasses attribute accepts a comma-delimited list of CSS style classes to be applied to the rows of the table. Style classes for an individual row may also be defined in a space separated list. A style class is applied to a table row as the value for the class attribute of rendered tr element.
Style classes are applied to rows in the same order that they are defined. For example, if there are two style classes, the first is applied to the first row, the second is applied to the second row, the first is applied to the third row, the second is applied to the fourth row, and so on. The list of styles is looped over from the beginning until there are no more rows to display.
In my standard JSF Project (Mojarra 2.0.3)
This tag generates:
<h:panelGrid border="1"
columns="4"
columnClasses="a,b,c,d"
rowClasses="x,y,z">
<h:outputText value="ax"/>
<h:outputText value="bx"/>
<h:outputText value="cx"/>
<h:outputText value="dx"/>
<h:outputText value="ay"/>
<h:outputText value="by"/>
<h:outputText value="cy"/>
<h:outputText value="dy"/>
<h:outputText value="az"/>
<h:outputText value="bz"/>
<h:outputText value="cz"/>
<h:outputText value="dz"/>
</h:panelGrid>
This HTML:
<table border="1">
<tbody>
<tr class="x">
<td class="a">ax</td>
<td class="b">bx</td>
<td class="c">cx</td>
<td class="d">dx</td>
</tr>
<tr class="y">
<td class="a">ay</td>
<td class="b">by</td>
<td class="c">cy</td>
<td class="d">dy</td>
</tr>
<tr class="z">
<td class="a">az</td>
<td class="b">bz</td>
<td class="c">cz</td>
<td class="d">dz</td>
</tr>
</tbody>
</table>

Resources