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.
Related
I'm trying to create an edit form and prepopulate to form with the chosen objects values but it is returning an HTTP status of 404 and the error message I'm getting is
org.springframework.web.servlet.DispatcherServlet.noHandlerFound No
mapping for GET
/AgentsCRUD/agent/edit/1;jsessionid=07E2EC08848D0C9C9346DC67563DDF1F
I think what I have is pretty logical but I must have messed up with the mapping.
The code in the get AllAgent.jsp
<spring:message code="welcome.message" />
<body>
<table style="width:100%">
<tr>
<th align="left"><spring:message code="label.agentId" /></th>
<th align="left"><spring:message code="label.name" /></th>
<th align="left"><spring:message code="label.fax" /></th>
<th align="left"><spring:message code="label.phone" /></th>
<th align="left"><spring:message code="label.email" /></th>
<th align="left"><spring:message code="label.datejoined" /></th>
<th align="left"><spring:message code="label.sales" /></th>
<th align="left"><spring:message code="label.actions" /></th>
</tr>
<c:forEach items="${agentList}" var="agent">
<tr>
<td>${agent.agentId}</td>
<td>${agent.name}</td>
<td>${agent.fax}</td>
<td>${agent.phone}</td>
<td>${agent.email}</td>
<td>
<spring:message code="label.delete" />
<spring:url value="/agent/edit/${agent.agentId}" var="editURL"/>
<spring:message code="label.edit" />
<spring:message code="label.insert" />
</td>
</tr>
</c:forEach>
</table>
</body>
the code in the controller AgentController.java
#GetMapping("/edit")
public ModelAndView EditAnAgent(#QueryParam("agentId") int agentId) {
return new ModelAndView("/editAgent", "agent", service.getAgentById(agentId));
}
#GetMapping("/editAgent")
public ModelAndView editAgent(#Valid #ModelAttribute("agent") Agents a, BindingResult result, ModelMap model) {
if (result.hasErrors()) {
return new ModelAndView("/editAgent");
}
service.editAgent(a);
return new ModelAndView("redirect:/agent");
}
the code in the Model AgentService.java
public static Agents getAgentByID(int agentId) {
EntityManager em = DBUtil.getEMF().createEntityManager();
Agents a = null;
try {
a = em.createNamedQuery("Agents.findByAgentId", Agents.class)
.setParameter("agentId", (agentId))
.getSingleResult();
} catch (Exception ex) {
System.out.println("Error in getting property details: " + ex);
} finally {
em.clear();
}
return a;
}
public void editAgent(Agents a) {
EntityManager em = DBUtil.getEMF().createEntityManager();
EntityTransaction transaction = em.getTransaction();
try {
transaction.begin();
em.merge(a);
transaction.commit();
} catch (Exception e) {
System.out.println(e);
} finally {
em.close();
}
}
the code in the editAgent.jsp
<form:form method="POST" action="/AgentsCRUD/agent/editAgent" modelAttribute="agent">
<table>
<tr>
<td><form:label path="agentId"><spring:message code="label.agentId" /></form:label></td>
<td><form:input path="agentId"/></td>
<td style="color:red"><form:errors path="agentId"/> </td>
</tr>
<tr>
<td><form:label path="name"><spring:message code="label.name" /></form:label></td>
<td><form:input path="name" /></td>
<td style="color:red"><form:errors path="name"/> </td>
</tr>
<tr>
<td><form:label path="phone"><spring:message code="label.phone" /></form:label></td>
<td><form:input path="phone"/></td>
<td style="color:red"><form:errors path="phone"/> </td>
</tr>
<tr>
<td><form:label path="fax"><spring:message code="label.fax" /></form:label></td>
<td><form:input path="fax"/></td>
<td style="color:red"> <form:errors path="fax"/> </td>
</tr>
<tr>
<td><form:label path="email"><spring:message code="label.email" /></form:label></td>
<td><form:input path="email"/></td>
<td style="color:red"> <form:errors path="email"/> </td>
</tr>
<tr>
<td><form:label path="username"><spring:message code="label.username" /></form:label></td>
<td><form:input path="username"/></td>
<td style="color:red"> <form:errors path="username"/> </td>
</tr>
<tr>
<td><form:label path="password"><spring:message code="label.password" /></form:label></td>
<td><form:input path="password"/></td>
<td style="color:red"> <form:errors path="password"/> </td>
</tr>
<tr>
<spring:message code="submit.button" var="labelSubmit"></spring:message>
<td><input type="submit" value="${labelSubmit}"/></td>
</tr>
</table>
</body>
</form:form>
In the Error the url given is .../edit/1 where 1 is a path parameter,
However in the get mapping, you are trying to read it as a query parameter.
Try this.
#GetMapping("/edit/{agentId}")
Patient getEmployee(#PathParam("agentId") int agentId) ;
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();
...
}
}
my requirement is based on group of checkbox checks shipping address fields will be disable or enabled.
make clear my requirement:Wicket id:"nonDigital" having 6 check boxes.if any one of check box is checked then only shipping address section is enabled and then only user can enter value.
Here is my code
My HTML code:
<fieldset class="deliveryFormats">
<h2 class="sectionHeading">Delivery Formats</h2>
<span class="required">* Required Field</span>
<br/>
<div class="leftDiv">
<label>Non-digital</label>
<div class="radioLabel" wicket:id="nonDigital" >
<label>
<input class="checkbox" type="checkbox" name="formatType" />Beta SP NTSC
</label>
</div><!-- /.radioLabel non digital -->
</fieldset>
<fieldset class="shippingAddress" style="border-bottom: 0px;" >
<h2 class="sectionHeading">Shipping Address</h2>
<table class="form">
<tbody>
<tr>
<th class="fieldName" scope="row">Company</th>
<td class="fieldEdit">
<input class="organization" type="text" wicket:id="address.organization"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 1</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.line1">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 2</th>
<td class="fieldEdit">
<input class=" long" type="text" wicket:id="address.line2">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Address 3</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.line3">
</td>
</tr>
<tr>
<th class="fieldName" scope="row">City</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.city"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">State</th>
<td class="fieldEdit">
<input class="long" type="text" wicket:id="address.state"/>
</td>
</tr>
<tr>
<th class="fieldName" scope="row">Postal Code</th>
<td class="fieldEdit">
<input class="postalcode" type="text" wicket:id="address.postalCode"/>
</td>
</tr>
</tbody>
</table>
Java code:
List<DeliveryFormat> formatChoices = lookupProcessor.getLookupValues(DeliveryFormat.class);
List<DeliveryFormat> nonDigital = new ArrayList<DeliveryFormat>();
List<DeliveryFormat> digital = new ArrayList<DeliveryFormat>();
Iterator<DeliveryFormat> nondigitalIterator = formatChoices.iterator();
while(nondigitalIterator.hasNext()){
DeliveryFormat df = nondigitalIterator.next();
if(df.getLabel().equals("Audio Bundle") || df.getLabel().equals("XDCAM file")|| df.getLabel().equals("FTP")){
digital.add(df);
}
else
{
nonDigital.add(df);
}
}
//Add the check boxes for Delivery format for digital List
// add(new CheckBoxMultipleChoice<DeliveryFormat>("nonDigital", nonDigital, new ChoiceRenderer<DeliveryFormat>("label")));
ChoiceRenderer<DeliveryFormat> deliveryFormatShippment = new ChoiceRenderer<DeliveryFormat>("label", "id");
CheckBoxMultipleChoice<DeliveryFormat> nonDigitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
"nonDigital", nonDigital, deliveryFormatShippment);
CheckBoxMultipleChoice<DeliveryFormat> digitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
"digital", digital, deliveryFormatShippment);
add(nonDigitalDelivery);
/*final CheckBox test = new CheckBox("nonDigital");
test.setOutputMarkupId(true);
nonDigitalDelivery.add(new AjaxEventBehavior("onKeyUp")
{
*//**
*
*//*
private static final long serialVersionUID = 1L;
#Override
protected void onEvent(AjaxRequestTarget target) {
// TODO Auto-generated method stub
test.setEnabled(false);
target.addComponent(test);
}
});*/
You should try to enable the markupid to be written:
textArea.setOutputMarkupId(true);
and then add this component to the target:
textArea.setEnabled(false):
target.add(textArea);
I want to upload details of a hoarding in mysql database with an image using .jsp and servlet but when i call my servlet it gives a blank page..
My .jsp
<form action="HoardingProfile" method="post" enctype="multipart/form-data">
<table style="height: 100%; width:100%;">
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Location</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" name="txtLocation"
placeholder="Location" required="yes">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Size</h3>
</td>
<td class="padd10" style="width: 50%;">
<input class="tx bk" type="text" name="txtSize" placeholder="Size"
required="yes">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Owner Name</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" placeholder="Owner Name"
required="yes" name="txtName">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Contact No.</h3>
</td>
<td style="width: 50%;">
<input type="text" class="tx bk" placeholder="Number"
required="yes" name="txtNumber">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Address</h3>
</td>
<td style="width: 50%;">
<textarea class="tx bk2" placeholder="Address" required="yes"
name="txtAddress"></textarea>
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 15%;">
<td class="tdleft" style="width: 50%;">
<h3>Picture</h3>
</td>
<td style="width: 50%;">
<input type="file" name="file" id="file">
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 50%;">
<h3>Google map</h3>
</td>
<td style="width: 50%;">
<textarea class="tx bk2" placeholder="Google Map iframe"
name="txtMap"></textarea>
</td>
</tr>
<tr style="height: 02%">
<td>
</td>
</tr>
<tr style="height: 10%;">
<td class="tdleft" style="width: 80%;">
<input class="btn" type="submit" name="Add" value="Save"
</td>
<td style="width: 20%;">
<input class="btn" type="reset" value="Reset"
</td>
</tr>
</table>
</form>
and my servlet
PrintWriter out = response.getWriter();
try {
// Apache Commons-Fileupload library classes
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload sfu = new ServletFileUpload(factory);
if (! ServletFileUpload.isMultipartContent(request)) {
System.out.println("Sorry. No file uploaded");
return;
}
// parse request
List<FileItem> items = sfu.parseRequest(request);
out.print(items);
FileItem txtLocation = (FileItem) items.get(0);
String location = txtLocation.getString();
out.println(location);
FileItem txtSize = (FileItem) items.get(1);
String size = txtSize.getString();
out.println(size);
FileItem txtName = (FileItem) items.get(2);
String name = txtName.getString();
out.println(name);
FileItem txtNumber = (FileItem) items.get(3);
String number = txtNumber.getString();
out.println(number);
FileItem txtAddress = (FileItem) items.get(4);
String address = txtAddress.getString();
out.println(address);
// get uploaded file
FileItem file = (FileItem) items.get(5);
// Connect to Oracle
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/opm?zeroDateTimeBehavior=convertToNull","root","");
con.setAutoCommit(false);
PreparedStatement ps = con.prepareStatement("insert into hprofile(location,size,owner,address,phone,deleted,img) values(?,?,?,?,?,?,?)");
ps.setString(1, location);
ps.setString(2, size);
ps.setString(3, name);
ps.setString(4, number);
ps.setString(5, address);
// size must be converted to int otherwise it results in error
ps.setBinaryStream(6, file.getInputStream(), (int) file.getSize());
ps.executeUpdate();
con.commit();
con.close();
out.println("Proto Added Successfully. <p> <a href='listphotos'>List Photos </a>");
}
catch(Exception ex) {
out.println( "Error --> " + ex.getMessage());
}
finally {
out.close();
}
I found out that I made some mistakes while linking the libraries...
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>