I have a JTextPane with a HyperLinkListener
m_textPane.addHyperlinkListener(new HyperlinkListener()
{
#Override
public void hyperlinkUpdate(HyperlinkEvent hyperlinkevent)
{
EventType eventType = hyperlinkevent.getEventType();
if (eventType == HyperlinkEvent.EventType.ACTIVATED)
{
URL url = hyperlinkevent.getURL();
hyperLinkClicked(hyperlinkevent);
}
}
});
The JTextPant is created with HTML and in this HTML file I have two Links.
<tr>
<td valign="top" class="label">Telefon:</td>
<td class="value">
<a href="telnet:[PhoneNumber.primary.number]">
[PhoneNumber.primary.number]
</a>
</td>
</tr>
<tr>
<td valign="top" class="label">Mobil:</td>
<td class="value">[PhoneNumber:Mobil.number]</td>
</tr>
<tr>
<td valign="top" class="label">Arbete:</td>
<td class="value">[PhoneNumber:Arbete.number]</td>
</tr>
<tr>
<td valign="top" class="label">E-post:</td>
<td class="value">
<a href="mailto:[Email.primary.address|]">
[Email.primary.address|]
</a>
</td>
</tr>
</table>
There is no problem getting the mailto protocol, returns "mailto" but the url for the telnet returns null
Any ideas? If any more information is needed tell me :)
Try to use hyperlinkevent.getDescription(); instead of hyperlinkevent.getURL();
public void hyperlinkUpdate(HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
String description = e.getDescription();
...
}
}
Related
if (Mode.equalsIgnoreCase("View"))
{
try
{
DimEN div = new DimEN();
BcDS divStr = new BcDS();
if(divisionCode==null || divisionCode.equals(""))
{
divisionCode = "All";
}
ArrayList divRec = divStr.getLinkBC(divisionCode,divisionCriteria);
if(outputExcel.equals("true")){
out.println("outputExcel true");
response.setContentType("application/excel");
response.setHeader("Content-Disposition","attachment;filename=DivisionBc.xls");
}
if(divRec != null)
{
if (divRec.size() > 0)
{
Paging = divRec.size();
RecordPerPage=15;
%>
<br>
<center>
<table class="LARGE" width="90%" >
<tr>
<td> </td><td> </td><td> </td><td> </td><td> </td>
<td> </td><td> </td><td> </td>
</tr>
<tr>
<td colspan=7 class="HEAD" align=center>View - Division - BC</td>
</tr>
<tr>
<td> </td><td> </td><td> </td><td> </td><td> </td>
<td> </td><td> </td><td> </td>
</tr>
<tr>
<td class=LABEL> </td>
<td class=LABEL> </td>
<td class=LABEL> </td>
<td class=LABEL colspan=3 align=center>Created</td>
<td class=LABEL> </td>
</tr>
<tr>
<td class=LABEL>Company Code</td>
<td class=LABEL>Division Code</td>
<td class=LABEL>Business Code</td>
<td class=LABEL>Created on</td>
<td class=LABEL>Created by</td>
</tr>
<%# include file="Include/NavTop.jsp" %>
<%
for (int i=StartIndex; i<LastIndex; i++)
//for (int i = 0; i < divRec.size(); i++)
{
div = (com.gil.hris.DimEN)divRec.get(i);
String dispDateCreate = div.getCreationDate();
String dispDateValid = div.getValidUpto();
String QDateCreate = "";
String QDateValid = "";
if (dispDateCreate == null)
{
QDateCreate = "-";
}
else
{
String yyyyD = dispDateCreate.substring(0,4);
String mmD = dispDateCreate.substring(5,7);
String ddD = dispDateCreate.substring(8,10);
QDateCreate = ddD+"/"+mmD+"/"+yyyyD;
}
if (dispDateValid == null)
{
QDateValid = "-";
}
else
{
String yyyyD = dispDateValid.substring(0,4);
String mmD = dispDateValid.substring(5,7);
String ddD = dispDateValid.substring(8,10);
QDateValid = ddD+"/"+mmD+"/"+yyyyD;
}
if (i%2==0)
{
%>
<tr>
<td class=QUERY><%=company_code%></td>
<td class=QUERY><%=div.getDimCode()%></td>
<td class=QUERY><%=div.getBcCode()%></td>
<td class=QUERY><%=QDateCreate%></td>
<td class=QUERY><%=div.getCreatedByEmp()%></td>
</tr>
<%
}
else
{
%>
<tr>
<td class=QUERY2><%=company_code%></td>
<td class=QUERY2><%=div.getDimCode()%></td>
<td class=QUERY2><%=div.getBcCode()%></td>
<td class=QUERY2><%=QDateCreate%></td>
<td class=QUERY2><%=div.getCreatedByEmp()%></td>
</tr>
<%
}
}
%>
</table>
</center>
<%
}
}
else
{
mesg = Database.getMessage();
//mesg="Error - Division Code Not Found.";
%>
<br>
<center>
<table class="small" width="60%">
<tr><td> </td></tr>
<tr>
<td class="HEAD" align=center>View - Division - BC</td>
</tr>
<tr><td> </td></tr>
<tr>
<td class="LABEL" align=center><%= mesg %></td>
</tr>
</table>
</center>
<%
}
}
catch (Exception e)
{
e.printStackTrace();
System.out.println(e);
mesg = "General Error";
}
}
this is my code but it is not working.
Excel is not generating.
Can Any one help. thanks.
Also I use, following code
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment; filename=DivisionBc.xls");
Still it doesn't work.
Im using an example i found on stackoverflow to explain my problem.
Java code :
/**
* Example written by Bruno Lowagie in answer to the following question:
* RowSpan does not work in iTextSharp?
*/
public class ParseHtml {
public static final String DEST = "results/xmlworker/html_table_4.pdf";
public static final String HTML = "D:\\Users\\Documenten\\NetBeansProjects\\ItextTest\\recources\\xml\\table2_css.html";
public static void main(String[] args) throws IOException, DocumentException {
File file = new File(DEST);
file.getParentFile().mkdirs();
new ParseHtml().createPdf(DEST);
}
/**
* Creates a PDF with the words "Hello World"
* #param file
* #throws IOException
* #throws DocumentException
*/
public void createPdf(String file) throws IOException, DocumentException {
// step 1
Document document = new Document();
// step 2
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
// step 3
document.open();
// step 4
// XMLWorkerHelper.getInstance().parseXHtml(writer, document, null, null);
XMLWorkerHelper.getInstance().parseXHtml(writer, document,
new FileInputStream(HTML));
// step 5
document.close();
}
}
Html code:
<table border="1" style="width: 100%">
<tr>
<td colspan="5" align="center" style="background-color: lightblue">INVOICE</td>
</tr>
<tr>
<td colspan="2" rowspan="4" style="background-color: white"><b>AIRNET NETWORKS</b><br />asdadadadaada asd asd a ads adsadsadsadasd</td>
<td>INVOICE</td>
<td>DATE</td>
<td>aDATEsd</td>
</tr>
<tr>
<td>Order</td>
<td>XXXX</td>
<td>Ref XXXXXX</td>
</tr>
<tr>
<td>Delivery</td>
<td>XXXX</td>
<td>Ref XXXXXX</td>
</tr>
<tr>
<td>Due Date</td>
<td>XXXX</td>
<td>Ref XXXXXX</td>
</tr>
<tr>
<td colspan="2" rowspan="4" style="background-color: white"><p><b >CUSTOMER NAME</b></p> asd asd adadaadadadada adadaadsasdad ada asd adad</td>
<td>Customer Care No:</td>
<td colspan="2">544646454,88877978975</td>
</tr>
<tr>
<td>Email Id</td>
<td colspan="2">airnet#gmail.com</td>
</tr>
<tr>
<td>Account Details</td>
<td colspan="2">5522245125545455 IFSC 323hasd<br /> SBI India</td>
</tr>
</table>
<div> </div>
<table border="1" style="width: 100%">
<tr>
<td style="background-color: lightblue" height="15" >Srno</td>
<td style="background-color: lightblue">Particulars</td>
<td style="background-color: lightblue">Quantity</td>
<td style="background-color: lightblue">Rate/Month</td>
<td style="background-color: lightblue">Total Rupees</td>
</tr>
<tr>
<td valign="top">1</td>
<td valign="top">1 MBPS Plan</td>
<td valign="top">1</td>
<td valign="top">600</td>
<td valign="top">692</td>
</tr>
<tr>
<td height="300" valign="top" >1</td>
<td valign="top">1 MBPS Plan</td>
<td valign="top">1</td>
<td valign="top">600</td>
<td valign="top">692</td>
</tr>
<tr>
<td colspan="3" rowspan="3" valign="top">asdasdasd</td>
<td colspan="1">Total</td>
<td colspan="1">692</td>
</tr>
<tr>
<td>Service Tax</td>
<td>692</td>
</tr>
<tr>
<td>Grand Total</td>
<td>692</td>
</tr>
</table>
The problems im facing:
Is it possible to give the html access to a javaclass so i can use it like this:
<tr>
<td>invoice.getdate</td>
<td>invoice.getInvoiceNumber</td>
<td>invoice.getSomethingelse</td>
</tr>
Can you create a dynamic table like this:
<table border="1" style="width: 100%">
<tr>
<td style="background-color: lightblue" height="15" >Srno</td>
<td style="background-color: lightblue">Particulars</td>
<td style="background-color: lightblue">Quantity</td>
<td style="background-color: lightblue">Rate/Month</td>
<td style="background-color: lightblue">Total Rupees</td>
</tr>
for (ServiceDTO service : listServices) {
<tr>
<td valign="top">service.getsomevalue</td>
<td valign="top">service.getsomevalue</td>
<td valign="top">service.getsomevalue</td>
<td valign="top">service.getsomevalue</td>
<td valign="top">service.getsomevalue</td>
</tr>
}
As work around im using a stringbuilder. Where i create a temporarily html page then load the html page inside itext. But there has to be a better way ? Can someone give me some direction where to start ?
Question is i have table in which i want to populate the values of file name and file size after user click the choose file button and select any number of files, Now the issue is if the user click choose files button second time i want to append the new values in the table and add the new file in the array so that it can uploaded.. my code is,
html form code:
<form id="simpleuploadform" method="post" action="upload" enctype="multipart/form-data">
<table class="span10" border="0">
<tr>
<td colspan="3">
<legend>Simple Upload</legend>
</td>
</tr>
<tr>
<td>
<input type="file" name="files[]" multiple="multiple" onchange="getFileSizeandName(this);"/>
<div id="successdiv" hidden="true" class="label label-success">Image uploaded successfully</div>
<div id="errordiv" hidden="true" class="label label-error">Image not successfully uploaded</div>
<div id="streamdiv" hidden="true" class="label label-warning">Issue while uploading try again</div>
</td>
<td id="renameFile" align="right"></td>
<td id="removeFile" align="right"></td>
</tr>
<tr>
<td colspan="3">
<div id="uploaddiv">
<table id="uploadTable" class="table table-striped table-bordered" width="200" height="200" scrolling="yes">
<thead>
<tr>
<th>Title</th>
<th>Size</th>
</tr>
</thead>
<tbody id="tbodyid">
<tr id="tr0">
<td id="filetd0" height="10px" width="50px"></td>
<td id="filesizetd0" height="10px" width="5px"></td>
</tr>
<tr id="tr1">
<td id="filetd1" height="10px" width="50px"></td>
<td id="filesizetd1" height="10px" width="5px"></td>
</tr>
<tr id="tr2">
<td id="filetd2" height="10px" width="50px"></td>
<td id="filesizetd2" height="10px" width="5px"></td>
</tr>
<tr id="tr3">
<td id="filetd3" height="10px" width="50px"></td>
<td id="filesizetd3" height="10px" width="5px"></td>
</tr>
<tr id="tr4">
<td id="filetd4" height="10px" width="50px"></td>
<td id="filesizetd4" height="10px" width="5px"></td>
</tr>
</tbody>
<tfoot>
<tr>
<td id="filecount" height="10px" width="50px"></td>
<td id="totalsize" height="10px" width="5px"></td>
</tr>
</tfoot>
</table>
</div>
</td>
</tr>
<tr>
<td colspan="3">
<input type="submit" class="btn btn-primary" onClick="CloseAndRefresh();" value="Start Upload" id="startButton" disabled>
<input type="reset" class="btn btn-primary" onClick="Clear();" value="Clear" id="clearButton" disabled>
<input type="button" class="btn" onClick="window.close();" value="Close">
</td>
</tr>
</table>
javascript code:
<script type="text/javascript">
var totalsizeOfUploadFiles = 0;
function getFileSizeandName(input)
{
var select = $('#uploadTable tbody');
$('#renameFile').empty();$('#removeFile').empty();
if(input.files.length > 0)
{
$('#renameFile').append($('<a id="renameRec">Rename Selected</a>'));
$('#removeFile').append($('<a id="removeRec">Remove Selected</a>'));
$('#startButton').removeAttr("disabled", "disabled");
$('#clearButton').removeAttr("disabled", "disabled");
}
//if(input.files.length <= 5)
//{
for(var i =0; i<input.files.length; i++)
{
var filesizeInBytes = input.files[i].size;
var filesizeInMB = (filesizeInBytes / (1024*1024)).toFixed(2);
var filename = input.files[i].name;
//alert("File name is : "+filename+" || size : "+filesizeInMB+" MB || size : "+filesizeInBytes+" Bytes");
if(i<=4)
{
$('#filetd'+i+'').text(filename);
$('#filesizetd'+i+'').text(filesizeInMB);
}
else if(i>4)
select.append($('<tr id=tr'+i+'><td id=filetd'+i+'>'+filename+'</td><td id=filesizetd'+i+'>'+filesizeInMB+'</td></tr>'));
totalsizeOfUploadFiles += parseFloat(filesizeInMB);
$('#totalsize').text(totalsizeOfUploadFiles.toFixed(2)+" MB");
if(i==0)
$('#filecount').text("1file");
else
{
var no = parseInt(i) + 1;
$('#filecount').text(no+"files");
}
}
//}
}
function CloseAndRefresh()
{
var daa = '<%=status%>';
if(daa == "true")
$('#successdiv').show();
else if(daa == "false")
$('#errordiv').show();
else
$('#streamdiv').show();
opener.location.reload(true);
self.close();
}
function Clear()
{
$('#uploadTable tbody tr td').each(function(){
$(this).text("");
});
$('#uploadTable tfoot tr td').each(function(){
$(this).text("");
});
}
i am trying to do as like this http://www.shutterfly.com/ image upload.
any help will be appreciated, thank you friends...
You are navigating away using javascript, function CloseAndRefresh on clicking submit button.
What actually happens is that the uploading request is being submitted while the CloseAndRefresh function is being executed at almost the same time using different thread. If the upload request is not fast enough, the web page will get refresh first and your upload request get terminated immediately. There is no easy way to prevent this using your existing code.
You should use advanced method of uploading like jQuery uploading plugin to send the request. The plugin provide an binder to execute function on successful/failed submittsion.
Thank you gigadot, i solve the issue as like below,
The html form have the same code as i posted earlier, in the previous js code i have the CloseAndRefresh() method i remove it now from js as well as from the submit button onclick event.
When the form action called the controller, in which i have the code
#RequestMapping(value = "/upload", method = RequestMethod.POST)
public String UploadReceipts(#RequestParam("files[]") List<MultipartFile> file, Model model) throws IOException {
boolean status = false;
try
{
for(int i=0; i< file.size(); i++)
{
if(!file.get(i).isEmpty())
{
CommonsMultipartFile cm = (CommonsMultipartFile) file.get(i);
status = simpleUploadService.uploadFileandSave(cm);
model.addAttribute("status", status);
}
}
}
catch (IOException e) {
status = false;
model.addAttribute("status", status);
}
return "pages/simpleUploadStatus";
}
Now i redirect it to another page in which i throws the appropriate messages for the user.
that's all...
I have a table as follows
<table id="vainTbl6" class="dtable" cellpadding="3" cellspacing="1" border="0">
<thead>
<tr><th>check</td><th>Morphosal</th><th>goat </th><th>the other</th></tr>
</thead>
<tbody id="tbdy">
<tr class="gradeX">
<td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%">-Approve the femuneration Gommiqee purpirt</td>
<td>pontpose</td></tr>
<tr class="gradeX">
<td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%">-Declare a final truce</td>
<td>More</td></tr>
<tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%">-Amend the articles of asscotonation</td>
<td>Four</td></tr>
<tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%">-Re-elect Bandanna la banana for warden</td>
<td>Floor</td></tr>
</tbody>
</table>
and the first column is a checkbox. I need to fetch all the second column cells where the checkbox in the first column is set to true
I tried using this, but to no avail.
function extractRowCell(divNode){
alert(divNode.id);
$('#tbdy tr td').each(function() {
alert('hello');
var aRowData = this.cells
alert(aRowData[1].firstChild.value);
return aRowData;
});
}
The call is as follows:
<a id="la" href='#' onclick='extractRowCell(this.parentNode)' style="position:absolute; top:280px; left:350px;">Votes & Concerns</a>
The alert in the function triggers though with the correct value.
TIA
To iterate over the td's simply do the following.
$('#tbdy tr td').each(function() {
alert( $(this).text() );
});
You can do this
<table><tbody id="tbdy">
<tr class="gradeX">
<td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%" class="item">-Approve the femuneration Gommiqee purpirt</td>
<td>pontpose</td></tr>
<tr class="gradeX">
<td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%" class="item">-Declare a final truce</td>
<td>More</td></tr>
<tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%" class="item">-Amend the articles of asscotonation</td>
<td>Four</td></tr>
<tr class="gradeX"><td><input type="checkbox" class = "chcktbl" /></td>
<td style="width:55%" class="item">-Re-elect Bandanna la banana for warden</td>
<td>Floor</td></tr>
</tbody>
</table>
<button>Get</button>
<script>
$("button").click(function(){
var ret="";
$("#tbdy tr td:first").each(function()
{
if($("input:checked").length!=0)
{
ret=$("input:checked").parent().parent().find("td.item").text();
}
});
alert(ret);
});
</script>
i have a JSP with hyperlink
<table>
<tr>
<td>Product Name : </td>
<td>${product.name}</td>
</tr>
<tr>
<td>Description:</td>
<td>${product.description}</td>
</tr>
<tr>
<td>Price:</td>
<td>${product.price}</td>
</tr>
<tr><td> </td></tr>
<tr>
<td>
Add to shopping basket
</td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<table>
<tr>
<td>Return to Home Page</td>
<td> </td>
<td>Logout
(<security:authentication property="principal.username" />)
</td>
</tr>
</table>
</td>
</tr>
And the controller
#Controller
#SessionAttributes("basket")
public class ShopBasketController {
private BasketManager basketManager;
private CustomerManager customerManager;
private CategoryManager categoryManager;
#Autowired
public ShopBasketController(BasketManager basketManager, CustomerManager customerManager, CategoryManager categoryManager) {
this.basketManager = basketManager;
this.customerManager = customerManager;
this.categoryManager = categoryManager;
}
#RequestMapping(value="/basketItems", method=RequestMethod.POST)
public String removeProduct(#ModelAttribute("basket") Basket basket, BindingResult bindingResult, Model model) {
Basket newBasket = ShoppingBasketUtils.removeFromBasket(basket, basketManager);
basketManager.update(newBasket);
model.addAttribute("basket",newBasket);
model.addAttribute("customer", "Sonx"+" Nkuks");
model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(basket));
model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(basket)));
return "basketItems";
}
#RequestMapping("/populateBasket")
public String populateBasket(#RequestParam("code") String productCode, #RequestParam("name") String categoryName, Model model) {
Customer customer = customerManager.getCustomer("Sonx", "Nkuks");
if(customer != null) {
Basket shopBasket = ShoppingBasketUtils.addToBasket(productCode, categoryManager.getCategory(categoryName),
basketManager.getBasket(customer.getReferenceNumber()), basketManager);
basketManager.update(shopBasket);
model.addAttribute("basket",shopBasket);
model.addAttribute("customer", customer.getFirstName()+" "+customer.getLastName());
model.addAttribute("totalItems", basketManager.getTotalNumberOfItems(shopBasket));
model.addAttribute("totalPrice", ShoppingBasketUtils.currencyFormat(basketManager.getTotalProductPrice(shopBasket)));
return "basketItems";
}
model.addAttribute("customer", "test".concat(" test"));
return "/error";
}
}
Then the form ...
<form:form commandName="basket">
<table>
<tr>
<td>
<table>
<tr>
<td>Customer Name : </td>
<td>${customer}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table width="600" border="1" cellspacing="0" cellpadding="2"
border="0">
<thead>
<tr>
<td>Products:</td>
</tr>
<tr>
<td>Product Name</td>
<td>Product Code</td>
<td>Description</td>
<td>Price</td>
<td>Remove</td>
</tr>
</thead>
<tbody>
<c:forEach items="${basket.products}" var="product">
<tr>
<td>${product.name}</td>
<td>${product.productCode}</td>
<td>${product.description}</td>
<td>${product.price}</td>
<td><form:checkbox path="removeItemCodes" value="${product.productCode}" /></td>
</tr>
</c:forEach>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td>Total Price</td>
<td> </td>
<td>${totalPrice}</td>
</tr>
<tr>
<td>Total Items</td>
<td> </td>
<td>${totalItems}</td>
</tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr>
<td><input type="submit" value="Remove Items" /></td>
</tr>
<tr><td> </td></tr>
<tr><td> </td></tr>
<tr>
<td>
<table>
<tr>
<td>Return to Home Page</td>
<td> </td>
<td>Logout
(<security:authentication property="principal.username" />)
</td>
</tr>
</table>
</td>
</tr>
</table>
When i press the link from the first JSP "" the controller succesfully execute the method populateBasket and loads the Form. But when i submit the form, i want it to call the POST method (basketItems)... But it doesn't, pressng the submit button always executes the GET method (populateBasket) .. This doesn't happen if i load the form directly from the index page, it loads successfully . Problem is when coming from that JSP ?
If you want the form to submit to a different URL from the one that was used to retrieve the page, you need to explicitly set the action on it. Otherwise Spring is going to just fill it in with the current URL.