getting value in JSP by using field name - spring-mvc

I have requirement something similar like below in our application,
I would like to show the below details in the form of table.
Country Name Population CapitalCity Aria
US XX XX XX XX
IN YY YY YY YY
User can choose in the configuration page which columns he is interested to see.
In the backend I set model attributes as below(using spring MVC),
model.addAttribute("selColumns", "column keys");
model.addAttribute("countryDetails", "List of country details");
In the CountryDetail class, field names and selColumns key names are same.
class CountryDetails {
private String country,
population,
CapitalCity,
Aria;
}
In the UI I am trying with the following code to achieve the same.
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<c:forEach items="${selColumns}" var="item">
<th><spring:message code="${item}" /></th>
</c:forEach>
</tr>
</thead>
<tbody>
<c:forEach items="${countryDetails}" var="det">
<tr>
<c:forEach items="${selColumns}" var="item">
<td>
//Below code is not working
<c:out value="${item.det}" /></td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
</table>
Table header is working fine. But I am struggling to show row information only for the configured columns.
Code wouldn't work because it tries to find getDet() at the java side.
Could some one please help is there any way in JSP, if I give property(field) name the corresponding value would return?
Something like this
Thanks in advance,
kitty

Try this one.
<tbody>
<c:forEach items="${countryDetails}" var="det">
<tr>
<c:forEach items="${selColumns}" var="item">
<td>
<c:out value="${det[item]}" />
</td>
</c:forEach>
</tr>
</c:forEach>
</tbody>
Note:
selColumns = ["Country", "Population", "CapitalCity", "Aria"]
CountryDetails properties = Country,Population,CapitalCity,Aria

Related

thymeleaf - sum of objects in list inside a list

I use spring boot + thymeleaf and mySQL DB
I have 3 entities:
Category
SubCategory
Porducts
The current table
I would like to show the sum of products in the table
This is the code to show the sum of sub category:
<tbody>
<tr th:each="category : ${categories}">
<td th:text="${category.name}" />
<td th:text="${#lists.size(category.subCategories)}" />
</tr>
</tbody>
You can use collection projection and aggregate functions to accomplish this:
<tbody>
<tr th:each="category : ${categories}">
<td th:text="${category.name}" />
<td th:text="${#lists.size(category.subCategories)}" />
<td th:text="${#aggregates.sum(category.subCategories.![#lists.size(products)])}" />
</tr>
</tbody>
The expressions category.subCategories.![#lists.size(products)] produces a list of the products in subCategories, which you can just sum using #aggregates.sum.

Vue template colspan not working properly

Hi im having a issue with a simple problem. because for some reason i dont find anything wrong with my codes. Seems like my code is not reading my colspan. seems like this problem as been mark as duplicate. but i dont want to specify the width of the table since i want the table to be responsive and i use bootstrap table
<div>
<table class="table table-condensed">
<thead>
<tr class="text-uppercase text-contrail table-dark-head">
<th colspan="3">Spillage</th>
<th>Total</th>
<th>Remarks</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="3">Material Cost / Kg</td>
<td>
<input></input>
</td>
<td>
<input></input>
</td>
</tr>
<tr>
<td>Spillage at 0.5%</td>
</tr>
</tbody>
</table>
</div>
i put this code inside my template. please see the image for the result. The Total and Remarks should be on the right side. but it end up with balance width.

Create dynamic row as per the list recievied in CSS/XSLT

I want to create the row as per the list i am receiving using xslt and css. Currently my xslt looks like below. In the below code i am reading the DataList using xsl:for-each and I want to create a new row if my data list size is more then 7. Could anyone please help on this.
<table width="100%">
<tr>
<td width="97px" style="font-size:14px;font-weight:bold;color:#9EB7B4;">DATA:</td>
<td>
<table style = "width:100%; ">
<tr style="height:35px">
<xsl:for-each select="DataList">
<td><a href="#{generate-id(DataName)}" ><xsl:value-of select="DataName"/></a></td>
</xsl:for-each>
</tr>
</table>
</td>
</tr>
</table>

How to make the table 2 * 2 with rules in aspx page

Can I make the table with rules in my aspx page.
right now I am dispalying the page some thing like this.
Benefit Type : 000
Benfit Set: BCPCP
Converage Level : IND -Individual
Deductable Type : D-DED
Can I differnciate with the rules each and every row. like this
Benefit Type : 000
Benfit Set: BCPCP
Converage Level : IND -Individual
Deductable Type : D-DED
here is my Aspx code.. is there any way I can make like this?
<table>
<tr>
<td>
</td>
</tr>
You can just do a row with an hr in it like this: http://jsfiddle.net/WXSpD/
<table>
<tr>
<td>Benefit Type:</td>
<td>000</td>
</tr>
<tr>
<td colspan="2"><hr/></td>
</tr>
<tr>
<td>Benfit Set:</td>
<td>BCPCP</td>
</tr>
</table>
Your question is very hard to understand, but if you're just looking for a two-by-two table, can't you do it like this?:
<table>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
</table>
If there's something else you're looking for, can you clarify a little bit?

How to pass the entire object from jsp to spring controller

I am new to Spring MVC and hope someone can help me figure out this issue. I have jsp like this:
<table border="1">
<tr>
<td width="50">Id</td>
<td width="150">First Name</td>
<td width="150">Last Name</td>
<td width="50">Money</td>
<td width="50"></td>
</tr>
<c:forEach items="${persons}" var="person">
<tr>
<td><c:out value="${person.id}" /></td>
<td><c:out value="${person.firstName}" /></td>
<td><c:out value="${person.lastName}" /></td>
<td><c:out value="${person.money}" /></td>
<td colspan="2"> Delete</td>
</tr>
</c:forEach>
</table>
When user clicks on the Delete link, I want to pass the entire object (person) to the controller. Can someone please help how would I do that? I will appreciate any help.
This is my controller:
#RequestMapping(value = "/removeContact", method = RequestMethod.GET)
public String removeContact(#ModelAttribute("contact")Person person, BindingResult result) {
System.out.println("============ > "+person.getId());
return "index.jsp";
}
Thanks
First, don't use permit delete operation on GET requests. Use DELETE instead, it's more appropriate. If you use jquery, use the ajax function to submit your data to the controller.

Resources