Export jsp specific table id to excel - excel

I have a problem and i was wondering if anyone can help me. Any help is really appreciated. And i m sure that its an 'easy' question.
I have a jsp page that shows dynamic data in tables, my problem is that the page has multiple tables.
But i want to export to excel only a specific table with a specific id.
So far i m exporting to excel all data from the jsp page which is wrong, cause i want to export only one table with id="formAssignDemands", how can i do it ?
Here is my code,
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%# page contentType="text/html;charset=windows-1253"%>
<%# taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<%# taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%# taglib uri="http://myfaces.apache.org/tomahawk" prefix="t"%>
<%# taglib uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1253"/>
<f:loadBundle basename="bundles.requests" var="FieldsDescr"/>
<f:loadBundle basename="bundles.messages" var="GeneralMessages"/>
<title>
<h:outputText value="#{FieldsDescr.AssignRequests_Title}"/>
</title>
<a4j:loadStyle src="#{AssignDemands_backing.municipality.url}#{AssignDemands_backing.municipality.templateId}#{GeneralMessages.CssPath}"/>
<script language="JavaScript" type="text/javascript"
src="./demands.js"></script>
<script language="JavaScript" type="text/javascript"
src="../reports/reports.js"></script>
</head>
<body><h:form>
<jsp:include page="/system/NavigationMenu.jsp"/>
</h:form>
<%
String exportToExcel = request.getParameter("exportToExcel");
if (exportToExcel != null && exportToExcel.toString().equalsIgnoreCase("YES")) {
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "inline; filename="
+ "excel.xls");
}
%>
<table cellspacing="0" cellpadding="0" border="0"
width="99%" align="center">
<tr>
<td class="componentheading" width="99%">
<h:outputText value="#{FieldsDescr.AssignRequests_SubHeader}"/>
</td>
<td class="componentheading" width="1%">
<table>
......
<tr>
<td class="main_component_seperator" colspan="2"> </td>
</tr>
<tr>
<td align="center" colspan="2">
<h:form id="formAssignDemands">
<t:dataTable id="demandsDataTable"
binding="#{AssignDemands_backing.demandsDataTable}"
var="demand"
value="#{AssignDemands_backing.unassignedDemandsList}"
rows="#{NavigationMenu_backing.rows}"
varDetailToggler="detailToggler"
sortColumn="#{AssignDemands_backing.sort}"
sortAscending="#{AssignDemands_backing.ascending}"
preserveSort="true"
headerClass="datatable_td_header"
rowClasses="tablerow1, tablerow2"
width="100%"
rowIndexVar="demandsRowIndex">
<f:facet name="header">
<h:panelGroup>
<f:verbatim>
<div style="float:left;"></div>
</f:verbatim>
<h:panelGrid columns="4"
cellspacing="2">
<h:outputText value="#{GeneralMessages.DataTable_RowsPerPage}"/>
.....
</table>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<%
if (exportToExcel == null) {
%>
Export to Excel
<%
}
%>
</body>
</html>
</f:view>
<%-- oracle-jdev-comment:auto-binding-backing-bean-name:AssignRequests--%>
Thank you guys for any help or any idea,,

i managed to do it with javascript and is working on 3 basic browsers mozilla, chrome and IE11 , so here it is,
<script type="text/javascript">
function ExcelReport()
{
var tab_text="<table border='2px'><tr bgcolor='#FFFFFF'>";
var textRange; var j=0;
tab = document.getElementById('table_id'); // id of table
for(j = 0 ; j < tab.rows.length ; j++)
{
tab_text=tab_text+tab.rows[j].innerHTML+"</tr>";
}
tab_text=tab_text+"</table>";
tab_text= tab_text.replace(/<A[^>]*>|<\/A>/g, "");
tab_text= tab_text.replace(/<img[^>]*>/gi,"");
tab_text= tab_text.replace(/<input[^>]*>|<\/input>/gi, "");
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./))
{
txtArea1.document.open("txt/html","replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa=txtArea1.document.execCommand("SaveAs",true,"Excel.xls");
}
else
sa = window.open('data:application/vnd.ms-excel,' + encodeURIComponent(tab_text));
return (sa);
}
</script>
and to call it somewere in your body can add the following with an iframe, like that,
<iframe id="txtArea1" style="display:none"></iframe>
<button id="btnExport" class="button_class" onclick="ExcelReport();">Export to Excel</button>
thats it , thank you guys for reading

Related

Unable to click or select checkbox using selenium python webdriver chrome

After all unsuccessful tries I had to ask for the help.
The thing is I want to make script which will automatically login, go to specific tab ("WAN"), click appropriate check box (to disable NAT) and log out. (It's actually Huawei GPON router HG8245)..
My code goes fine until the check box, so...
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re
driver=webdriver.Chrome(r"C:\chromedriver.exe") #load the driver => OK
driver.get("http://192.168.100.1") #go to this web page => OK
driver.find_element_by_id("txt_Username").send_keys("root") #username=root => OK
driver.find_element_by_id("txt_Password").send_keys("root") #password=root => OK
driver.find_element_by_xpath(".//*[#id='button']").click() #click Submit button => OK
driver.find_element_by_xpath(".//*[#id='headerTab']/ul/li[2]/div[2]").click() #Go to the 'WAN' tab => OK
And for the clicking of check box my tries:
#1
driver.find_element_by_xpath("//input[#value='InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1']").click() #=> NOT OK
#2
driver.find_element_by_xpath("//*[#id='record_1']/td[1]/input").click() #=> NOT OK
#3
driver.find_element_by_css_selector("#record_1 > td > input[name=\"rml\"]").click() #=> NOT OK
Of course all xpaths are checked in chrome via console (in the Mozilla as well) and they seems fine!
Any ideas how to solve this?
HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body>[![enter image description here][1]][1]
<div id="main">
<div id="header">
<div id="center" style="height: 495px;">
<div id="nav" style="height: 495px;">
<div id="content" style="height: 495px;">
<div id="topNav">
<div id="frameWarpContent" style="height: 470px;">
<iframe id="frameContent" marginheight="0" marginwidth="0" scrolling="no" src="html/network/wan.asp" style="height: 470px;" height="100%" frameborder="0" width="100%">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html id="Page" xmlns="http://www.w3.org/1999/xhtml" dir="ltl">
<head>
<body class="mainbody">
<script language="JavaScript" src="../../resource/common/util.js?1103405">
<script language="JavaScript" src="../../resource/english/jsdiff.js?1103405">
<script language="JavaScript" src="../../resource/common/tabdes.js?1103405">
<script language="javascript" src="../common/manage_mode.asp">
<script language="javascript" src="../common/user_info.asp">
<script language="javascript" src="../common/topo_info.asp">
<script language="javascript" src="../common/feature_info.asp">
<script language="javascript" src="../common/wan_prefix_acquire.asp">
<script language="javascript" src="../common/wan_address_acquire.asp">
<script language="javascript" src="../common/wan_dns.asp">
<script language="javascript" src="../common/wan_list.asp">
<script language="javascript" src="../common/wlan_list.asp">
<script language="javascript" src="../common/lanmode_list.asp">
<script language="javascript" src="../common/policyroute_list.asp">
<script language="javascript" src="wan_language.html?1103405">
<script language="javascript" src="../common/wan_pageparse.html?1103405">
<script language="javascript" src="../common/wan_databind.html?1103405">
<script language="javascript" src="../common/wan_control.html?1103405">
<script language="javascript" src="../common/wan_check.html?1103405">
<script language="JavaScript" src="../../resource/english/bbspdes.html?1103405">
<script>
<div id="PromptPanel">
<script>
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<tr>
<td id="Wan Connection">
<table id="wanInstTable" class="tabal_bg" width="100%" cellspacing="1">
<tbody>
<tr class="tabal_title">
<tr id="record_0" class="tabal_01" onclick="selectLine(this.id);">
<tr id="record_1" class="tabal_01" onclick="selectLine(this.id);">
<td align="center">
<input name="rml" value="InternetGatewayDevice.WANDevice.1.WANConnectionDevice.2.WANPPPConnection.1" onclick="" type="checkbox">
</td>
<td align="center">
<td align="center">
<td title="RealName :HSI Status :Connected IPAddress :10.10.10.10" align="center">
</tr>
</tbody>
</table>
<script>
<form id="ConfigForm">
</td>
</tr>
</tbody>
</table>
</body>
</html>
</iframe>
</div>
</div>
</div>
<div id="footer">
<div id="fresh">
</div>
</body>
</html>
*Edit: Modifying code tags and IP values
Considering provided HTML code sample you need to switch to iframe before handling check-box:
driver.switch_to.frame("frameContent")
driver.find_element_by_xpath("//tr[#id='record_1']//input").click()

HTML tag is not accepted in nodejs

in this code html table tag not accepted.i don't why within codes i have tried but result not came i want the table format with border style.html within code also tried
this is my html table :
let mailOptions = {
from: 'aaaaaaaaa',
to: 'bbbbbbbbbb',
subject: 'Test',
html:`<html><head>
<body>
<table>
<tr>
<th>Id </th><th>Templatename</th>
<th>Description</th>
<th>TemplateContent</th>
<th>Active</th>
</tr>
<tr>
<td>streamingTemplate.id.toString()</td>//here the table data should be a database not the defined one.
<td>streamingTemplate.template_name.toString()</td>
<td>streamingTemplate.description.toString()</td>
<td>streamingTemplate.template_content.toString()</td>
<td>streamingTemplate.is_active.toString()</td>
</tr>
</table>
</body>
</head></html>`
};
Your <table> tag is inside a <head> tag.
Change your structure to this :
<html>
<head>
</head>
<body>
<table></table>
</body>
</html>
You have a space character inside your <table> tag. It is <table > instead of <table>

Nested Layouts MVC5

I am new to MVC so pardon if my questions come across as stupid.
I have a main layout file (_MainLayout.cshtml) and a secondary layout file (_AdminLayout.cshtml). Both these files reside in my /Views/Shared folder.
The _MainLayout.cshtml looks like:
<!DOCTYPE html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="shortcut icon" type="image/x-icon" href="~/icons/favicon.ico" />
<title>U - #ViewData["Title"]</title>
<link rel="stylesheet" href="~/Content/Site.css"/>
</head>
<body>
<nav>
<div id="MainMenu" style="top:45px; height:40px; width:100%; position:fixed">
<ul style="list-style-type:none; text-align:center">
<li class="u-li-rightfloatinglink">#Html.ActionLink("Admin", "_AdminLayout", "Admin")</li>
<li class="u-li-rightfloatinglink">#Html.ActionLink("Contact", "Contact", "Home")</li>
<li class="u-li-rightfloatinglink">#Html.ActionLink("About", "About", "Home")</li>
<li class="u-li-rightfloatinglink">#Html.ActionLink("Home", "Index", "Home")</li>
</ul>
</div>
</nav>
<div id="MainBody" style="top: 80px; width:100%; text-align:center; position:fixed">
#RenderBody()
</div>
<div id="MainFooter" style="position:fixed; bottom:0px; width:100%; height:20px; background:#015da0">
<p style="display:table-cell; color:#ffffff; text-align:center; vertical-align: middle">© #DateTime.Now.Year - U</p>
</div>
#RenderSection("scripts", required: false)
</body>
The _AdminLayout.cshtml looks like:
#{
ViewBag.Title = "_AdminLayout";
Layout = "~/Views/Shared/_MainLayout.cshtml";
}
<h2>_AdminLayout</h2>
<div>
#RenderBody()
</div>
The ManageTableContent.cshtml is again supposed to be displayed in the #RenderBody section of the _AdminLayout.cshtml.
ManageTableContent.cshtml looks like:
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
ViewBag.Title = "Manage Table Content";
}
<body>
<div class="u-div-header">
<p class="u-p-header">Manage Table Content</p>
</div>
<br />
<div style="width: 100%">
<table class="u-table-layouttable">
<tr>
<td class="u-td-description">Table Name here</td>
<td class="u-td-buttons">
<button class="u-button-addrecord" title="Add Record">
<img />
</button>
<button class="u-button-deleterecord" title="Delete Record">
<img />
</button>
<button class="u-button-clonerecord" title="Clone Record">
<img />
</button>
</tr>
<tr>
<td colspan="2">
<table id="ManagedTable" class="u-table-datatable">
<tr class="u-tr-datatable">
<td></td>
</tr>
</table>
</td>
</tr>
</table>
<table style="width: 100%">
<tr>
<td>
<input id="Submit" type="submit" value="Submit" style="float: right" />
<input id="Cancel" type="reset" value="Cancel" style="float: right" />
</td>
</tr>
</table>
</div>
</body>
For some reason if I get this error when I try and open my _AdminLayout.cshtml by selecting the Admin link from my _MainLayout.cshtml:
Additional information: The file "~/Views/Shared/_AdminLayout.cshtml" cannot be requested directly because it calls the "RenderBody" method.
Controller Code:
namespace U.Controllers
{
public class AdminController : Controller
{
// GET: Admin
public ActionResult ManageTableContent()
{
return View();
}
public ActionResult _AdminLayout()
{
ViewBag.Message = "Your admin page.";
return View();
}
}
}
If I remove the #RenderBody()from my code then the _AdminLayout.cshtml loads fine.
I need the #RenderBody() in my _AdminLayout.cshtml because here I will display partial Views again.
Any help would be appreciated.
You can only have one #RenderBody() per master layout (that's where the output of a View goes to).
If _AdminLayout.cshtml is not a master layout, then you should use #RenderPartial to insert partial views there.
Based on your comment,
when you call _AdminLayout action
then it calls automatically _AdminLayout.cshtml and as it has #RenderBody() method in his view file it get error. Action controller view can not hold #RenderBody().
you can do that way. Change your ActionResult _AdminLayout name to AdminLayout.
And create another view file named AdminLayout.cshtml.
And in that cshtml you can code this way.
#{
Layout = "~/Views/Shared/_AdminLayout.cshtml";
ViewBag.Title = "Manage Table Content";
}
I hope you understand why do you get this error.

How to insert a custom label in between two fields in newform.aspx?

I have a form with many fields in it. I want to group 4-5 fields so that they can fall below the custom label. How to create this? I have very limited knowledge of coding.
I want to have custom labels like shown in the figure:
http://i45.tinypic.com/33agm0y.png
I picked up a coding from net and inserted it but it didn't work.
First, create your webusercontrol
WebUserControl1.ascx
This code is
<%# Control Language="C#" AutoEventWireup="true" CodeBehind="WebUserControl1.ascx.cs" Inherits="WebApplication1.WebUserControl1" %>
<asp:Label ID="label" runat="server" >
</asp:Label>
<table>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:TextBox ID="textbox5" runat="server"></asp:TextBox>
</td>
</tr>
</table>
Add this code behind for your usercontrol
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class WebUserControl1 : System.Web.UI.UserControl
{
public string MyProperty { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
label.Text = MyProperty;
}
}
}
Secondly create your aspx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>
<%# Register TagName="test" TagPrefix="uc" Src="~/WebUserControl1.ascx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<uc:test id="uc1" runat="server" MyProperty="Texte1"></uc:test>
<uc:test id="uc2" runat="server" MyProperty="Texte2"></uc:test>
<uc:test id="uc3" runat="server" MyProperty="Texte3"></uc:test>
<uc:test id="uc4" runat="server" MyProperty="Texte4"></uc:test>
</div>
</form>
</body>
</html>

JS Calendar + JSF

sorry about input mistakes, english its not my mother lang.
I have this code written on normal html that i managed to transform into xhtml file, i want to send the value shown on <input id="f_date"> to <h:inputText>:
<script src="../js/jscal2.js" type="text/javascript" xml:space="preserve"></script>
<script src="../js/lang/en.js" type="text/javascript" xml:space="preserve"></script>
<link rel="stylesheet" type="text/css" href="../css/jscal2.css" />
<link rel="stylesheet" type="text/css" href="../css/border-radius.css" />
<link rel="stylesheet" type="text/css" href="../css/steel/steel.css" />
<h:form id="form1">
<table>
<tr>
<td colspan="4" id="cont"></td>
</tr>
<tr>
<td>
<input style="text-align: center" name="date" id="f_date"
size="14" />
<h:inputText id="f_date" value="#{solicitud.fechaI}" maxlength="10" size="10" valueChangeListener="#{solicitud.fechaIText}">
<a4j:ajax event="keyup" render="fechaI, fIni" status="statusFI"/>
</h:inputText>
</td>
<td>
<input style="text-align: center" name="hour" id="f_hour" size="2" />
</td>
<td>
:
</td>
<td>
<input style="text-align: center" name="minute" id="f_minute"
size="2" />
</td>
</tr>
</table>
</h:form><script type="text/javascript" xml:space="preserve">//<![CDATA[
function updateFields(cal) {
var date = cal.selection.get();
if (date) {
date = Calendar.intToDate(date);
document.getElementById("f_date").value = Calendar.printDate(date, "%Y-%m-%d");
}
document.getElementById("f_hour").value = cal.getHours();
document.getElementById("f_minute").value = cal.getMinutes();
};
Calendar.setup({
cont : "cont",
showTime : 12,
onSelect : updateFields,
onTimeChange : updateFields
});
//]]></script>
Thanks in advance, best regards
You should reuse input element from <h:inputText> when setting up JS calendar. Use inputField argument to pass id of input generated by JSF. It could be form1:f_date but check html source to make sure.
EDIT:
prefix id with "form1:" in updateFields"
document.getElementById("form1:f_date")
and get rid of
<input style="text-align: center" name="date" id="f_date"
size="14" />

Resources