jsp foreach on jdbc list<map> format - sql

so im having a little problem with my code. I used jdbc to make a query to our SQL database in our DAO like so:
List<Map<String,Object>> results = namedjdbcTemplate.queryForList(FINDALL, namedParameters);
Which is then passed up from the service to the controller where it is added to our model:
List<Map<String,Object>> locations = cmsAttributeService.getAttributeList(id);
model.addAttribute("locationlist", locations);
I then need to display all the entries in our jsp. Currently i do so like this:
<c:forEach items="${locationlist}" var="list">
<tr>
<td>
<c:out value="${list }"></c:out>
</td>
</tr>
</c:forEach>
My problem is the formatting it returns, for example:
{=UCMDB2.Project.name}
How do i get it to return just 'UCMDB2.Project.name' dropping the {= }? Ive tried all sorts of other calls like using list.value, list.key, all of which either break it entirely or blank the results out. Im fairly sure it should be something simple that im just missing. Anyone got any clues?

Changed it to List <String> and it worked.

Related

Update certain data in SQL with JSP

i've been learning web programming (JSP and SQL) for the past few days, i need help with certain problem, so i need to show the list of all name of members from my database, add button beside it, and when i click it, i need to update the data in database, which name is exactly the same name besides the button .
I have successfully show the data and button, and i know syntax for updating in SQL, but i have no idea how to validate when i click the button, it updates the data with the same name exactly besides the button. Let's just pretend all name is unique. This is my sample code:
<div id="textArea">
<%
String query = "SELECT * FROM member";
ResultSet rs = st.executeQuery(query);
while(rs.next()){%>
<table>
<tr>
<td><%out.print(rs.getString("Fullname"));%></td>
<td> <input type="button" value="Change Role"/> </td>
</tr>
</table>
<%
}
%>
</div>
Any help is really appreciated. thanks!
You have to write Java code in a JSP Page for updating certain data from JSP.
You can write Java Code inside a scriptlet in a JSP page.
You have to write scriptlet inside <% ...%> tag, Please see sample below:
<%
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test");
Statement st=con.createStatement();
......
%>
Please follow the post below to execute update query directly from JSP:
Jsp sql update query

How to set the default value of input item with jQuery EasyUI framework

I am trying to set the default value of an input item from last two days.
For this, i have also searched in google but till not cannot find the solution.
I am using jQuery EasyUI framework.
<div class="fitem">
<tr>
<td></td>
<td>
<input type="text" class="easyui-validatebox" name="insertby" id="insertby" size="20">
</td>
</tr>
</div>
<script>
var s = '<?php echo $logname; ?>';
document.getElementById('insertby').value = s ;
alert(s);
</script>
As I am unable to add a comment to ask you to try stuff, I will try my best to help you out!
Firstly, your code works for me. However, there are times where other javascript codes causes errors and stops the code execution before your block of code. You might want to try pressing F12 on your Chrome browser to see if you encounter any errors before your block of code to ensure that all is well.
this code snip might have you
http://www.jeasyui.com/forum/index.php?topic=2623.0
$('#insertby').validatebox('setValue', s);
I took me while to "get it" too.
Actually, jquery easyUI modifies the DOM on the fly to make its fancy things in a way that the original input box is "gone" while you obtain their fancy widget instead. That's why modifying the input field directly has no effect, it is hidden actually. I guess this is done so because their getters/setters should be used in order to update everything correctly.
EasyUI is very easy to set up and play with, but it's way to operate on elements is rather unintuitive. But once you got the hang of it, it should be all right.
Use
setValue. $('idofcombogrid').('setValue',id_value);
The id_value refers to the value of idField as defined initially for the combogrid.

Updating HTML table through JSTL and SQL

I have a HTML table which initially displays all records in the DB. I have just added a JQuery Datepicker component, and now I want to be able to retrieve records based on date. I have no problem extracting the date from the Datepicker component, but I do have a problem updating the existing HTML table. My code is pretty standard.
<sql:query var="retrieveSecurity" dataSource="jdbc/SecurityApp">SELECT * FROM security</sql:query>
<tbody>
<c:forEach var="row" items="${retrieveSecurity.rows}">
<tr>
<td>${row.security_id}</td>
<td>${row.description}</td>
<td class="center">${row.bid_price}</td>
<td class="center">${row.bid_percent_change}</td>
<td>${row.comment}</td>
</tr>
</c:forEach>
</tbody>
What I basically want to do is to have another SQL query, something like this...
<sql:query var="retrieveSecurity" dataSource="jdbc/SecurityApp">SELECT * FROM security where trade_date = "MYVALUE"
</sql:query>
I then want to be able to update the the tbody tag to point to this new SQL query, and call it instead. The columns won't change, so it should be the same table, just with filtered data. Not sure if what I am asking is the easiest/best solution, just looking for something that will work quickly for a prototype.
Hope this makes sense.

mvc model has byte[] data- how to display in view should be simple

I've seen an answer to this in MVC3 "Displaying database image (bytes[]) in Razor/MVC3", but it end using two trips.
Is there an improved way in MVC4/5 using razor? Will WebImage help. I'm learning but a lot of this is over my head
The previous questioner made this observation, I echo it.
" I've yet to see an example of the image being taken from the model/viewmodel and displayed (except my answer using TempData). You'd think it would be a common requirement, but either it's so simple no-one asks or it's so difficult no-one bothers."
My images are small bargraphs.
So in my view the collection is passed in the Model.Lots
#foreach (var item in Model.Lots)
{ <tr>
<td>
#item.LotName
</td>
<td>
// code here to take #item.TaskImage (a byte array) and show image
</td>
As an example to get things working:
<img src="data:image/png;base64,#Convert.ToBase64String(item.TaskImage)" />
This technique uses the data URI scheme. We take the incoming byte array, convert it to Base64 and put it as the data in the URI.
see "Image to Byte[] harder than thought 2 challenges" for working answer.

Calculate module of index int Struts2 iterator

I'm using Struts2 iterator to setup a list of checkbox in a table. I want to have 10 checkbox per row, so I'm doing the following:
<table>
<tr>
<s:iterator value="securityMasterFields" status="fieldNameStatus" var="fieldName">
<s:if test="#fieldNameStatus.index % 10 ==0">
</tr><tr>
</s:if>
<td>
<s:checkbox name="fieldsToShow" fieldValue="%{fieldName}" value="%{fieldName}"/>
</td>
</s:iterator>
</tr>
</table>
It never goes through the if, so I'm assuming the mod is not been calculated correctly. How do I do it?
thanks
Well, I had to add some parentheses and it worked correctly. The loop was working, it was just that it wasn't going through the if.
<s:if test="(#fieldNameStatus.index % 8 )==0"></tr><tr></s:if>
It looks good to me. Two thoughts:
1) try printing the result of the test in s:property tag
2) It looks like you will have empty table rows... Are you looking at the generated html or just the output, because if it is just the output then unless you have some CSS giving you some table padding and borders, without an empty 'td' element the row might collapse and make it appear as if nothing is being added. So do make sure you print the empty 'td' elements too!