How to iterate through a list of list in jsp - jsp-tags

I have list of list in a java class. I want to display list of list in JSP.
Java code
ArrayList<ArrayList<String>> criteriaList;//have getter,setter
JSP Code
<s:iterator value="criteriaList" status="status">
<tr><td>
<s:property value="[#status.index]" />
</tr></td>
</s:iterator>
But can't working.

As copied out of the struts documentation.
Iterating over a list of lists
<table>
<s:iterator value="grid">
<tr>
<s:iterator value="top">
<td><s:property/></td>
</s:iterator>
</tr>
</s:iterator>
</table>
The trick here is to use 'top' as the value for the inner iterator. This example probably uses a two-dimensional array, but you can use the pattern for any list of lists.

Related

What does h:dataTable bodyrows attribute mean

Does anybody know what h:dataTable bodyrows means? I tried a simple example, but I don't understand what it's supposed to do.
<h:dataTable bodyrows="d" value="#{index.publishDates}" var="d">
Is this some sort of shortcut for making a table? I don't see any rows because of the bodyrows annotation. If h:column does columns, what does bodyrows do?
I don't understand the documentation.
This must be a comma separated list of integers. Each entry in this list is the row index of the row before which a "tbody" element should be rendered.
In HTML, a <table> can have multiple bodies via <tbody>.
<table>
<tbody>...</tbody>
<tbody>...</tbody>
<tbody>...</tbody>
</table>
By default, a <h:datatable> generates only one body like below.
<h:dataTable value="#{[1,2,3,4,5]}" var="i">
<h:column>#{i}</h:column>
</h:dataTable>
<table>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
<tr><td>5</td></tr>
</tbody>
</table>
The bodyrows attribute can be used to specify a commaseparated string of row indexes which should start as a new body.
<h:dataTable value="#{[1,2,3,4,5]}" var="i" bodyrows="0,2,4">
<h:column>#{i}</h:column>
</h:dataTable>
<table>
<tbody>
<tr><td>1</td></tr>
<tr><td>2</td></tr>
</tbody>
<tbody>
<tr><td>3</td></tr>
<tr><td>4</td></tr>
</tbody>
<tbody>
<tr><td>5</td></tr>
</tbody>
</table>
See also:
Can we have multiple <tbody> in same <table>?
HTML Dog HTML beginner tutorial - tables
MDN HTML element reference - table

xpages dijit.form.checkbox multiple values

Using xpages on domino 8.5.3 server.
Can a djcheckbox be use with muiltiple value field similar to a checkboxgroup ?
if so, would it be possible to supply a code snippet.
Thanks
dijit.form.CheckBox can deal with only one value and that's true for djCheckBox too as it's based on dijit.form.CheckBox.
You could combine several djCheckBox controls and let it look like a checkBoxGroup. Bind every djCheckBox to a viewScope variable initialized by a document item and write values back at document save.
Here is an example for UI similarity to checkBoxGroup:
<fieldset
class="xspCheckBox">
<table>
<tbody>
<tr>
<td>
<xe:djCheckBox
label="abcdefg"
id="djCheckBox4"
value="#{viewScope.abcdefg}">
</xe:djCheckBox>
</td>
<td>
<xe:djCheckBox
label="hijklmno"
id="djCheckBox5"
value="#{viewScope.hijklmno}">
</xe:djCheckBox>
</td>
<td>
<xe:djCheckBox
label="pqrstuvwxyz"
id="djCheckBox6"
value="#{viewScope.pqrstuvwxyz}">
</xe:djCheckBox>
</td>
</tr>
</tbody>
</table>
</fieldset>
I am not sure though what's the reason for your question and if it's worth the extra effort.

Extracting specific values with Postgresql

I have a table like this:
Table
<!DOCTYPE html>
<html>
<body>
<table border="1" style="width:100%">
<tr>
<td>email</td>
<td>data</td>
</tr>
<tr>
<td>creator_a#creator.com</td>
<td>"vimeo_profile"=>"", "twitter_profile"=>"", "youtube_profile"=>"", "creator_category"=>"production_company", "facebook_profile"=>"", "linkedin_profile"=>"", "personal_website"=>"", "instagram_profile"=>"", "content_expertise_categories"=>"4,5,8"</td>
</tr>
<tr>
<td>creator_b#creator.com</td>
<td>"twitter_profile"=>"", "creator_category"=>"association", "facebook_profile"=>"", "linkedin_profile"=>"", "personal_website"=>"", "content_expertise_type"=>"image", "content_expertise_categories"=>"4, 6"</td>
</tr>
</table>
</body>
</html>
And I want to query this using PostgreSQL, so I only get the values regarding content_expertise_categories:
*Important to mention that the number of values vary. The table has many more entries so I am looking for a solution that helps me extract the values regardless of whether there are 2 or 15 values to pull out.
Result
<!DOCTYPE html>
<html>
<body>
<table border="1" style="width:100%">
<tr>
<td>email</td>
<td>data</td>
</tr>
<tr>
<td>creator_a#creator.com</td>
<td>4,5,8</td>
</tr>
<tr>
<td>creator_b#creator.com</td>
<td>4,6</td>
</tr>
</table>
</body>
</html>
I have tried substring but can't make it to work.
Some help would be much appreciated, thanks!
SELECT
email,
(string_to_array(
data::text,'"content_expertise_categories"=>'::text
)
)[2] as data
FROM users
;
Update:
In your example all strings have "content_expertise_categories" listed last, which allows to think you can just split string to two pieces. If you happen to have more php array definition values after, you'll need an additional split on ',"' and taking [1] part this time...
Mind casting column "data" to ::text before using it in content_expertise_categories function, as it requires text type, and your column appeared to be not such.
I believe more elegant would be this query:
select
email,
data->'content_expertise_categories' as data
from h
;
But when I was posting first query I did not know that you use hstore

Adding new xElement after ALL found Descendants

I have an xDocument with multiple various xElements.
I can successfully find a specific xElement by searching via it's xAttributes & then Add a new xElement after it using the code below:
xDocument.Descendants("td").LastOrDefault(e => ((string)e.Attribute("ID")) == "3").Add(new XElement("b", "Just a test."));
The problem is that I wish to Add this new xElement after all found instances of the Descendants, not just LastOrDefault or FirstOrDefault.
My xDocument is created dynamically & there is no way before hand to know how many 'td' xElements with 'ID' = '3' that there are going to be.
Any help would be appreciated.
Thanks
ADDED CODE AS REQUESTED
<html> .... etc....
<body>
<table>
<tr>
<td>Image</td>
<td>Description</td>
<td>Date</td>
</tr>
<tr>
<td ID="1">*.jpg</td>
<td ID="2">some image</td>
<td ID="3">01/01/1901</td> <--CHANGING THIS PART OF CODE-->
<--THIS TABLE ROW REPEATS AN UNDETERMINED NUMBER
OF TIMES RELATING TO THE NUMBER OF FILES CONTAINED IN WHATEVER DIRECTORY IS BEING SEARCHED USING A FOREACH LOOP IN ANOTHER PART OF
THE CODE-->
</tr>
</table>
</body>
</html>
So I am trying to add a tag between the <td> with ID = 3.
This <b> tag also contains a string variable i.e.
new xElement("b", DateTaken)
& needs to be created at runtime and not hard coded as it relates to each loaded image at the start of the table row.
So I am trying to add this <b> tag to every occurrence of <td> with ID=3 & not just the first or the last.
Hope this extra info helps.

Create a dynamic table from a java.util.Map

I'm developing a web application in JSF 2.0. In my application I need a table for viewing presences.
I have a Map<Date, List<Presence>> in my 'PresenceService' bean.
The Presence object has a Person object (with name and surname) and a boolean present/not present.
I'd like to create a table that looks like this:
monday tuesday wednesday ...
Name Person 1 present not present present ...
Name Person 2 present present present ...
... ... ... ... ...
Which JSF components could I use to create such a table? Or should I not be using a Map for this? I tried creating a table myself with <ui:repeat>'s but failed to do so.
As wel the colums as the rows can be dynamic since the user can choose a period and a range of persons.
EDIT: solution (see answer Balus C)
This works like a charm:
<table>
<tr>
<th>Name</th>
<ui:repeat value="#{aanwezigheidController.siAanwezigheidService.datums}" var="datumHeader">
<th>
<h:outputText value="#{datumHeader}">
<f:convertDateTime pattern="dd/MM/yyyy" />
</h:outputText>
</th>
</ui:repeat>
</tr>
<ui:repeat value="#{aanwezigheidController.siAanwezigheidService.aanwezigheidSiRijen}" var="aanwRij">
<tr>
<td>#{aanwRij.persoon.naam} #{aanwRij.persoon.voornaam}</td>
<ui:repeat value="#{aanwezigheidController.siAanwezigheidService.datums}" var="datumCell">
<td>
<h:outputText value="aanwezig" rendered="#{aanwRij.aanwezighedenMap[datumCell].aanwezig}" />
<h:outputText value="afwezig" rendered="#{!aanwRij.aanwezighedenMap[datumCell].aanwezig}" />
</td>
</ui:repeat>
</tr>
</ui:repeat>
</table>
A double nested <ui:repeat> should be fine. The standard JSF implementation does not offer something like <h:columns> to represent dynamic columns, but component libraries RichFaces and PrimeFaces have respectively <rich:columns> and <p:columns> for exactly this purpose. You may want to take a look at it.
With alone a Map<Date, List<Presence>>, it is not possible to pick a specific person to present the row data for all columns. You basically need a Map<Date, Map<Person, List<Presence>>, or a separate List<Date> representing the dynamic columns and a separate List<Presence> where the Presence in turn has Person and Map<Date, Boolean> properties so that a specific date can be picked for the columns.

Resources