How to use foreach in Velocity template for Table - java

I have an object invoice, it has some list of Invoice Items. Now I want to get print of my invoices. For that I used Velocity Template. But my model template not getting my required format.
I used this .
I got this Output
For below template
I got this Output
But I want like this
Guys Plz help me to get requried format

Try the following code
<table>
<tr>
<th>Name</th>
<th>Desp</th>
<th>Qty></th>
<td>Unit Price</th>
<th>Disc</th>
<th>Total</th>
<th>vat rate</th>
<th>vat amount</th>
</tr>
#foreach ($titem in $!invoice.transactionItems)
<tr>
<td>$!titem.item.name</td>
<td>$!titem.description</td>
<td>$!titem.quantity</td>
<td>$!titem.unitPrice</td>
.....
</tr>
#end
</table>
Firstly,you need to write some html code as well as css,once have the html template, you can fill your object value to the html code, as your format, you need to make use of the html table label to present your result.

Related

Get data of html table from a website in android using Jsoup library,

I am working on an app where I am parsing some data from one or two websites. Luckily I did it for some of my targeted data but not. Now that I am using Jsoup for parsing the data from a website I used same jsoup format to get data of phase 2 as I did for phase 1 of my app but this time nothing is fetching arraylist showing up blank. I checked both HTML codes and there is a bit of difference in both.
In my phase1 i parsed the table using it's class and then i get the respective of that table. In the 2nd phase, the format of table and its tr & tds are different so i am struggling to figure it out. I am posting the html code from which i want to get data.
<div class="view-content">
<table class="views-table cols-3">
<thead>
</thead>
<tbody>
<tr class="odd views-row-first views-row-last">
<td class="views-field views-field-counter">
1 </td>
<td class="views-field views-field-body">
<p>some text here</p>
</td>
<td class="views-field views-field-field-notif-pdf">
Size :- 1.85 MB, Language:- English</td>
</tr>
</tbody>
</table>
</div>
I want the data inside above table tag and i am having problems to figure it out how it will be done with all classes in tr and td. Any help or suggestion will be highly appreciated..
THANK YOU!
You can use selectors in Jsoup:
File input = new File("path_to_html/test.html");
Document doc = Jsoup.parse(input, StandardCharsets.UTF_8.name());
///select table body
Element tbody = doc.select("tbody").first();
other examples at:
https://jsoup.org/cookbook/extracting-data/selector-syntax

How to generate table header with wicket

I want to generate this table header by wicket
<tr>
<th>Actions</th>
<th>ID</th>
<th>First Name</th>
<th>Last Name</th>
<th>Home Phone</th>
<th>Cell Phone</th>
</tr>
where header names are saved in arrayList
I try something like this. It generate what I want but in html code it show warning
- Invalid location of tag (div).
Good thing is that div tag is not showed in generated html code.
I dont know what tag should I use when I just want th without span tag
<tr>
<div wicket:id="seasonNames"><th wicket:id="season">[season]</th></div>
</tr>
One approach is to use DataTable component. In that case you have to pass a list of IColumn instances and use HeaderToolbar. See Wicket-examples for this approach.
Another way is to use simple repeater, like RepeatingView or ListView. In that case wicket:id="seasonNames" should be <wicket:container> instead of <div>.

Best way to display a java object that contains csv data in a JSP?

I have a jsp that gathers data from the user and passes that data to a servlet. The servlet uses that data to query an api and the response is a string object that contains csv data, which is forwarded to a search results jsp page.
In the search results jsp page I call the object. It's just a string of csv values and it looks bad on the page. I'm a total novice when it comes to web app development. Any idea the best way to parse the csv data in such a way that it looks better? Maybe into a HTML table? All I can find is info on parsing through a csv file, not an object with csv data in it.
I'm sure there's a simple way to handle this but after a whole day of combing the internet I need a little help where to look...
-----Edited to add sample data.
The data is returned to the jsp like so.
product_nbr,member_nbr,prod_cd,create_dt XYZ0000,000,777,2015-10-30
The first 4 fields are the headers and the data follows in line. I would like it to look like this..
(stackoverflow doesn't allow the table tag, but you really I just want to be able to display an HTML table on screen)
<table>
<tr>
<td>product_nbr</td>
<td>member_nbr</td>
<td>prod_cd</td>
<td>create_dt</td>
</tr>
<tr>
<td>XYZ0000</td>
<td>000</td>
<td>777</td>
<td>777</td>
</tr>
</table>
I recommend you to read this article:
http://www.journaldev.com/2090/jstl-tutorial-with-examples-jstl-core-tags
It shows you how to use JSTL in a JSP. You have to use the forEach tag like this, but before yoy have to parse your csv file into a array.
http://www.tutorialspoint.com/java/java_string_split.htm
String a = "product_nbr,member_nbr,prod_cd,create_dt XYZ0000,000,777,2015-10-30";
String[] b = a.split(",");
Este es un JSP de ejemplo
<table>
<tbody>
<tr><th>ID</th><th>Name</th><th>Role</th></tr>
<c:forEach items="${requestScope.empList}" var="emp">
<tr><td><c:out value="${emp.id}"></c:out></td>
<td><c:out value="${emp.name}"></c:out></td>
<td><c:out value="${emp.role}"></c:out></td></tr>
</c:forEach>
</tbody>
</table>

Why is my post not give data to my controller from my form?

I am developing a Sprin MVC application and I have a form containing a table in one of the UI jsp's, (welcome.jsp) and when the submit button is clicked, I am trying to print out the data in the form to the web applications console.From there i intend to parse the checkboxes that are selected and then have the controller send the 'selected' data back to the databased to be updated to the next status in the applications flow.
So far the form is 'successfully' posting as in no error or exceptions is being thrown, but the printed statement in the console is blank which makes me think that no data is being sent, and I would greatly welcome any help to fix this.
Here is the setup of what I have, not the actual code but a rough set up of the elements and methods.
welcome.jsp:
<form action="<c:url value="/postPage" />"method="post" modelAttribute="rTable">
<br/>
<table>
<thead>
<tr>
<th>title1</th>
<th>title2</th>
<th>title3</th>
<th><select>
<option>option1</option>
<option>option2</option>
</select></th>
</tr>
</thead>
<tbody>
<tr>
<td>value1</td>
<td>value1</td>
<td>value1</td>
<td><input type="checkbox" value="row_data_id" /></td>
</tr>
</tbody>
<tfoot>
<tr><td colspan="4"></td>
</tfoot>
</table>
<br/>
</form>
My controller has the following method in it with all the necessary libraries imported:
controller.java
#RequestMapping(value="/postPage", method = RequestMethod.POST)
public String processUpdate(#ModelAttribute("rTable") String table, ModelMap model) {
System.out.println(table);
return "postPage";
}
The console line that is print is this:
.
.
.
[3/19/14 16:36:53:625 EDT] 0000006a SystemOut O
.
.
.
Does anyone know why this is not printing anything? Am I really not successfully sending anything to the controller?
After a good deal of reading and trial and error I found my answer. I will explain in terms with spring framework forms. In order to pass data through the form from front-end to back end, first every input will need to be tied to the form using the spring form JSTL tag
ex.
form => form:form
input=> form:input
in the form:form it isn;t necessary but you should have a modelAttribute that is linked to a java class, then in each input their need to be a path attribute the is linked to a variable in the modelAttribute class and a value to assign to the variable. Then on a submit the values are linked to the back end via the getters and setters on the java class to be used in the back-end. I hope I am explained that clearly.

How to iterate over <td> tags with condition using jsoup

I am able get all text with in tags but I want to access only specific td tags.
Eg.I want to get data of second cell text whose first cell html contains attribute
a name="manufacturer"
or Content.I am using Jsoup.
<tabel>
<tr>
<td><a name="Manufacturer"></a>manufacturer</td>
<td>happiness</td>
</tr>
<td>manuf</td>
<td>hap</td>
</tr>
<tr>
<td>tents</td>
<td>acd</td>
</tr>
<tr>
<td><a name="Content"></a>Contents</td>
<td>abcd</td>
</tr>
</tabel>
I am using the code ..
doc.select("a[name=Manufacturer]");
..but its giving me the reference of cell one ,I need to go to cell two get cell two text
You need to use selector like [attr=value]: elements with attribute value, e.g. [width=500].
Take a look at official documentation Selector Syntax

Categories