I have got table and display datas from database (mysql). I use thymeleaf. All fields are ok but sb.cover doesnt show jpg (blob column in my database). Have you got any ideas how to put jpg in web page using thymeleaf? Thanks
<tr th:each="sb, poz : ${product}">
<td th:text="${poz.count}">1</td>
<td th:icon="${sb.cover}"></td>
<td th:text="${sb.title}"></td>
<td th:text="${sb.price}"></td>
<td ><b><a th:href="#{/details}">DETAILS</a></b></td>
<td ><b><a th:href="#{/cart}">ADD TO CART</a></b></td>
</tr>
It's worked for me:
<img class="info" th:attr="src=#{${image}}" />
where 'image' is base64 image:
image = "data:image/png;base64,R0lGODlhlgCWAMQAAPz.........
in Spring Java Controller:
#RequestMapping(value = "/get_goods_detail", method = RequestMethod.GET)
public String getGoodsDetail(#RequestParam(value = "itemid") final int itemid,
ModelMap model) {
// get image
String image = "data:image/png;base64,R0lGODlhlgCWAMQAAPz8/N3d3eX.../big image
model.addAttribute("image", image);
return "goods_detail"; // return name of html view with thymeleaf
}
I am not sure this will help you...
<tr th:each="sb, poz : ${product}">
<td th:text="${poz.count}">1</td>
<td><img th:attr="src=#{${sb.cover}} , title=#{background}, alt=#{background}" style="width: 150px; height: 150px;" /></td>
<td th:text="${sb.title}"></td>
<td th:text="${sb.price}"></td>
<td ><b><a th:href="#{/details}">DETAILS</a></b></td>
<td ><b><a th:href="#{/cart}">ADD TO CART</a></b></td>
</tr>
You can do some thing like this:-
<img th:src="#{'data:image/jpeg;base64,'+${sb.encodedString}}" />
where encodedString is image's byte[] data converted to base64 encoded string.
This is basic html actually. Check this question: Is it possible to put binary image data into html markup and then get the image displayed as usual in any browser?
Hope that helps
Alternatively, you can display image like below:
<img th:if="*{photo != null}" th:src="#{'data:image/jpg;base64,' + *{T(org.springframework.util.Base64Utils).encodeToString(photo)}}"/>
this method that converts the bytearray to base64 String so you can convert your product cover to base64 sring.
you need to add in the product class :
public String generateBase64Image()
{
return Base64.encodeBase64String(this.getCover());
}
in the web page you need to call the metho generateBase64Image() in in your web page :
<img th:src="#{'data:image/jpeg;base64,'+${product.generateBase64Image()}}" />
Related
I am printing the data from ViewModel into DataTable in the following way, but how to obtain a space between #item.FirstName and #item.LastName so that the output can be of the form FirstName LastName? At present, I am getting the Name as FirstNameLastName. Ex: MarkStevens. I want to print it as Mark Stevens.
#if(Model.Count() != 0)
{
<thead>
<tr>
<th data-column-id="Name">Name</th>
...
</tr>
</thead>
}
else
{
<h3 style="text-align:center">No Records Found</h3>
}
<tbody>
#foreach(var item in Model)
{
<tr>
<td>
#(if (item.UserId != null)
{
#item.FirstName #item.LastName
}
else
{
#item.OtherUser
}
</td>
</tr>
}
</tbody>
You can use #Html.Raw helper which means, you render whatever inside without any html encoding like space or string:
#item.FirstName #Html.Raw(" ") #item.LastName
If you want html, you can also use a simple non-breaking spaces:
#item.FirstName #item.LastName
How about string format the output: $"{#item.FirstName} {#item.LastName}"
use string.Format. i feel this is very clean approach.
string.Format("{0} {1}", #item.FirstName,#item.LastName)
I have Image url as database field and i want to display image with the url in table..
<table>
<tr>
<th>FirstName</th>
<th>LastName</th>
<th>EmailID</th>
<th>Mobile</th>
<th>Address</th>
<th>Country</th>
</tr>
#foreach (var data in Model.alldata)
{
<tr>
<td><img src= " #data.ImageUrl" /></td>
<td>#data.FirstName</td>
<td>#data.LastName</td>
<td>#data.EmailID</td>
<td>#data.Mobile</td>
<td>#data.Address</td>
<td>#data.Country</td>
</tr>
}
here what i should write for display image as i have url in database field and image is in Img folder.
sorry sorry i got it..
<img src="#Url.Action(data.ImgUrl)">
I have created an e-commerce website and am using a label to display the products from my sql database, the image it shows of these products are not hyperlinks, but this is what I need them to be, I think I have written the right code but I have a "parentControl" error, could someone help plz?
Below is also a link to show you visually what is being asked. REMEMBER the picture is just an image, but needs to be a hyperlink!
private void FillPage()
{
ArrayList teesList = new ArrayList();
if (!IsPostBack)
{
teesList = ConnectionClass.GetTeesBySize("%");
}
else
{
teesList = ConnectionClass.GetTeesBySize(DropDownList1.SelectedValue);
}
StringBuilder sb = new StringBuilder();
HyperLink link = new HyperLink();
link.NavigateUrl = "http://google.com";
parentControl.Controls.Add(link);
foreach (Tees tees in teesList)
{
sb.Append(string.Format(#"<table class='TeesTable'>
<tr>
<th rowspan='1' width='150px'><img runat='server' src='{6}' /</th>
<th width='50px'>Name: </th>
<td>{0}</td>
</tr>
<tr>
<th>Size:</th>
<td>{1}</td>
</tr>
<tr>
<th>Price:</th>
<td>{2}</td>
</tr>
</table>",
tees.name, tees.size, tees.price, tees.id, tees.id, tees.id, tees.image));
LblOutput.Text = sb.ToString();
(https://dl-web.dropbox.com/get/CompetitiveStreakTemplate/Pic.png?_subject_uid=9403629&w=AAD63dzqPQcNMNSU0OwbVBrGjNGFvtt7VWJ6DKwlu4UoPw).
You need to close your <img> tag properly and wrap it in a <a> to make it a hyperlink. Also use <td> instead of <th> for data rows and not headers.
Something a bit more like:
<td rowspan='1' width='150px'>
<a href='{0}.aspx'>
<img runat='server' src='{6}' />
</a>
</td>
You should probably also tidy up the rest of the code appended to your table, checking what is a header or data, and using a <tbody> tag inside the <table>
Edit: looking closer it seems as though you aren't creating the table properly in the first place, change this chunk of your code to do the loop properly:
parentControl.Controls.Add(link);
sb.Append("<table class='TeesTable'><tbody>");
foreach (Tees tees in teesList)
{
sb.Append(string.Format(#"
<tr>
<td rowspan='1' width='150px'>
<a href='{0}.aspx'>
<img runat='server' src='{6}' />
</a>
</td>
<td width='50px'>Name: </td>
<td>{0}</td>
</tr>
<tr>
<td>Size:</td>
<td colspan='2'>{1}</td>
</tr>
<tr>
<td>Price:</td>
<td colspan='2'>{2}</td>
</tr>",
tees.name, tees.size, tees.price, tees.id, tees.id, tees.id, tees.image));
}
sb.Append("</tbody></table>");
LblOutput.Text = sb.ToString();
I've been using this guide to create PDF reporting:
http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3
Basically I have a form that once it's submitted, It creates and opens a PDF report
the report is actually a view, for example this one:
#using MvcReportGeneratorDemo.Models
#model CustomerList
<br />
<table cellpadding="3" cellspacing="3">
`<tr border="1" bgcolor="#777777" color="#ffffff">`
<td>Name</td>
<td>Address</td>
<td>Place</td>
</tr>
#foreach (Customer customer in Model)
{
<tr border="1">
<td>#customer.Name</td>
<td>#customer.Address</td>
<td>#customer.Place</td>
</tr>
}
</table>
I want that each page in the PDF will have columns headers, not just the first one.
tried google but found nothing relevant.
You can use the following code at server side to solve your problem.
using (StringReader sr = new StringReader(html))
{
foreach (IElement el in iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, null))
{
if (el is PdfPTable)
{
((PdfPTable)el).HeaderRows = 1;
}
doc.Add(el);
}
}
I am using jqgrid grails plugin.
Column model for the column is:
{name:'id', index:'id', editable:true, align:'center', formatter:jobListLinkFormatter}
Custom formatter is:
function jobListLinkFormatter(cellvalue, options, rowObject){
var url = "${createLink(action:'jobListJSON')}" +"/"+cellvalue;
var link ="my link";
return link;
};
The link is produced correctly, however the text 'my link' only shows when moused over. What is the cause of this problem?
Add generate html: The text for the link only shows when mouse over on the row and 'ui-state-hover' is applied
<table id="configGrid" class="jqTable ui-jqgrid-btable" cellspacing="0" cellpadding="0" border="0" role="grid" aria-multiselectable="false" aria-labelledby="gbox_configGrid" style="width: 1178px; ">
<tbody>
<tr class="jqgfirstrow" role="row" style="height:auto">
<td role="gridcell" style="height:0px;width:1178px;"></td>
</tr>
<tr id="4" role="row" class="ui-widget-content jqgrow ui-row-ltr">
<td role="gridcell" style="text-align:center;" title="my link" aria-describedby="configGrid_id">
my link
</td>
</tr>
</tbody>
</table>
try adding in your link
function jobListLinkFormatter(cellvalue, options, rowObject){
var url = "${createLink(action:'jobListJSON')}" +"/"+cellvalue;
var link ="<a href='" + url + "'"+" style='font-color:red' >my link</a>";
return link;
};
or class="ui-state-error-text"
if this will work that means that you have problems with css so in firebug inspect your link and see what styles are applied to this link and your font color is the same as background or font size is tiny or something like that.