I am trying to display a bar chart on click of button on a page which is test.jsp. I am able to display the chart,but it opens as a image in the same browser where my test.jsp is.I want to display it in a new Window ,how can I do that. I am using Struts2 and Jfreechart:
Following is my action :
public class TestAction extends ActionSupport{
public String execute() throws Exception {
//code to populate DataSet
chart = ChartFactory.createBarChart(
"Bar Chart", //Chart title
"", //Domain axis label
"MARKETS", //Range axis label
dataSet, //Chart Data
PlotOrientation.VERTICAL, // orientation
true, // include legend?
true, // include tooltips?
false // include URLs?
);
chart.setBorderVisible(true);
return SUCCESS;
}
}
Following is my struts.xml :
<action name="testAction"
class="testAction"
method="execute">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">jpeg</param>
<param name="width">600</param>
<param name="height">400</param>
</result>
</action>
<action name="displayDataAction"
class="testAction"
method="getData">
<result name="success">test.jsp</result>
</action>
Jsp is :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" target="_blank">
<table>
//Mapping of data from database
</table>
<s:submit id="submit" value="Display Chart" align="left" action="testAction"/>
<s:submit value="Display Data" align="left" action="displayDataAction"/>`
</s:form>
</body>
</html>
Instead of using s:form tag and s:submit, use form tag like:
<form action="blah blah" target="_blank">
And that should resolve the issue.
Related
I have test.jsp which has two buttons.on click of Display Chart button,it should open chart on new page which is happening using target=_blank in form tag. But problem is i don't want this behavior on click of Display Data button. On click of this button,I want to display data fetched on same page only,but currently for this button as well it is opening a new window .
My code is:
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" target="_blank">
<table>
//Mapping of data from database
</table>
<s:submit id="submit" value="Display Chart" align="left" action="testAction"/>
<s:submit value="Display Data" align="left" action="displayDataAction"/>`
</s:form>
</body>
</html>
public class TestAction extends ActionSupport{
public String execute() throws Exception {
//code to populate DataSet
chart = ChartFactory.createBarChart(
"Bar Chart", //Chart title
"", //Domain axis label
"MARKETS", //Range axis label
dataSet, //Chart Data
PlotOrientation.VERTICAL, // orientation
true, // include legend?
true, // include tooltips?
false // include URLs?
);
chart.setBorderVisible(true);
return SUCCESS;
}
}
struts.xml:
<action name="testAction"
class="testAction"
method="execute">
<result name="success" type="chart">
<param name="value">chart</param>
<param name="type">jpeg</param>
<param name="width">600</param>
<param name="height">400</param>
</result>
</action>
<action name="displayDataAction"
class="testAction"
method="getData">
<result name="success">test.jsp</result>
</action>
I got it done as follows :
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function openPopUp(){
document.getElementById('testForm').setAttribute('target', '_blank');
document.getElementById('testForm').setAttribute('action', 'testAction.action');
document.getElementById('testForm').submit();
}
function noPopUp(){
document.getElementById('testForm').setAttribute('target', '');
}
<title>Data</title>
<s:head theme="ajax" debug="true"/>
</head>
<body bgcolor="white">
<s:form validate="true" target="_blank">
<table>
//Mapping of data from database
</table>
<s:submit id="submit" value="Display Chart" align="left" onclick="openPopUp();"/>
<s:submit value="Display Data" align="left" action="displayDataAction" onclick="noPopUp();"/>`
</s:form>
</body>
</html>
I want to fetch a text box value from jsp to my action class.
But my action class in not getting called while submitting the page.
My code are
Jsp page
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="AddedColor" method="post">
<div class="box">
<span class="label">Color Name</span>
<span class="ib"> <input type="text" name="color" id="color"/></span>
</div>
<div class="box">
<input type="button" id="submit_color" value="Add Color"/>
</div>
</form>
</body>
</html>
In struts.xml
<package name="colorpkg" extends="struts-default">
<action name="AddedColor" class="iland.work.ColorAction" method="insert">
<result name="success">/pages/colors/showColors.jsp</result>
</action>
</package>
In ActionClass
public class ColorAction extends ActionSupport {
private String color;
//getter and setter of color
public String insert() {
System.out.println("-> ColorAction insert()");
System.out.println(getColor());
return SUCCESS;
}
}
try this:
<div class="box">
<input type="submit" id="submit_color" value="Add Color"/>
</div>
I have an array list in action class. I want to access this arraylist in my jsp page along with a checkbox. if the checkbox is checked i want to get the associated value of checkbox in another actionclass. how can i do this??
Action class:
public class CreateModuleAction extends ActionSupport{
private List modNameList=new ArrayList();
private int size;
public String manageModule()
{
ManageModule ob=new ManageModule();
modNameList=ob.selectModule();
if(modNameList.isEmpty()) {
addActionError("Module list is empty!!!");
return ERROR;
}
else{
setSize(modNameList.size());
return SUCCESS;
}
}
public List getModNameList() {
return modNameList;
}
public void setModNameList(List modNameList) {
this.modNameList = modNameList;
}
public int getSize() {
return size;
}
public void setSize(int size) {
this.size = size;
}
jsp page:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<title>Admin Module Management</title>
</head>
<body>
<div class="main">
<div class="header">
<!-- Page heading-->
<jsp:include page="/templates/heading.jsp" flush="true"/>
</div>
<div class="menu">
<!-- Page menu-->
<jsp:include page="/templates/menu.jsp" flush="true"/>
</div>
<div class="content">
<!-- page content-->
<div id="right_top" style="position:absolute; left:900px; top:300px;;">
<img src="../images/add.jpg"/>Add
<img src="../images/edit.jpg"/>Edit
<img src="../images/add.jpg"/>Delete
</div>
<s:iterator status="size" value="modNameList">
<s:checkbox name="modNameCheck" fieldValue="true" value="modNameList"/>
<s:property value="modNameList"/>
</s:iterator>
<s:actionerror/>
</div>
<div class="footer" style="margin-left: 50%">
<!-- page footer-->
<jsp:include page="/templates/footer.jsp" flush="true"/>
</div>
</div>
</body>
</html>
Why dont you use struts2 checkboxlist tag
<s:form action="myAction">
<s:checkboxlist list="modNameList" name="modNameCheck"/>
</s:form>
Now in yoyr myAction action class declare
private List modNameCheck; //with getter/setter
It will have entries which were checked in the jsp
If you want submit values from checkboxes to action then you need form in your JSP. If you want to display checked/unchecked checkboxes depending on some values from action then you need some condition check in value attribute.
<s:checkbox name="modNameCheck" value="list.contains(something)"/>
I am using struts2 in my project .
I used DOJO jar for Treenode
but i don't know how to get
Treenode id/label in action class when it is clicked
Follow is my "tree.jsp" page when i click on "java in action" treenode(leaf node)
i want this name is to be send immeditaly to action class.
<%#taglib prefix="s" uri="/struts-tags"%>
<%# taglib prefix="sx" uri="/struts-dojo-tags"%>
<html>
<head>
<sx:head/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Example Tree Tag</title>
</head>
<body>
<h1>Example tree & treenode Tag</h1>
<div>
<sx:tree id="books" label="Books" title="test" >
<sx:treenode label="Programing books" title="test">
<sx:treenode label="Java" title="test">
<sx:treenode id="Thread-Books" label="Core-Java" >
<sx:treenode id="Thread-Books" label="Java in Action" />
<sx:treenode id="Thread-Books" label="Core-Java Essentials" />
<sx:treenode id="Thread-Books" label="Head first Java" />
<sx:treenode id="Thread-Books" label="Multi-threading" />
<sx:treenode id="Thread-Books" label="Networking" />
</sx:treenode>
</sx:tree>
You need add following code
<script language="JavaScript" type="text/javascript">
dojo.event.topic.subscribe("treeSelected", function treeNodeSelected(node) {
alert(node);
dojo.io.bind({
url: "<s:url value='../roseindia/objectsList2.action'/>?categoryId="+node.node.title,
load: function(type, data, evt) {
var divDisplay = dojo.byId("displayIt");
divDisplay.innerHTML=data;
},
mimeType: "text/html"
});
});
sx:treenode label passed as node.node.title
I'm working with some nested datalist controls and cannot get the SP parameters for my nested stored procedure to work.
In debug I can see that SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString()); is getting the correct value from the label but when the results display I always get the results for the last parameter added?
I'm guessing I need to clear the parameters in some way each time the nested datalist is bound but if I add code to do that it results in an error that I have not specified the parameters?
My code is below, you'll see that eventually I will have 3 nested datalists inside each other - or that's the plan.
Thanks for any suggestions
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="nhscsharprepeater._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%# Import Namespace="System.Web" %>
<%# Import Namespace="System.Web.UI" %>
<%# Import Namespace="System.Data" %>
<script type="text/C#" runat="server">
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
DataList oList = (DataList)e.Item.FindControl("Datalist2");
Label oLabel = (Label)e.Item.FindControl("lblSection");
DataList oList2 = (DataList)oList.FindControl("Datalist3");
SqlDataSource2.SelectParameters.Clear();
SqlDataSource2.SelectCommand = "report_DistinctSubSections";
SqlDataSource2.SelectParameters.Add("Section",oLabel.Text.ToString());
oList.DataBind();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_DistinctSection" SelectCommandType="StoredProcedure"></asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="Section" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:productfolioConnectionString %>"
SelectCommand="report_getReports" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:Parameter Name="SubSection" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" RepeatColumns="2" RepeatDirection="Horizontal" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Section") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist2" runat="server" DataSourceID="SqlDataSource2">
<ItemTemplate>
<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "SubSection") %>' ID="lblSection">
</asp:Label>
<br />
<asp:datalist id="Datalist3" runat="server" DataSourceID="SqlDataSource3">
<ItemTemplate>
<!--<asp:Label Runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Report") %>' ID="lblSection">
</asp:Label>-->
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:datalist>
</ItemTemplate>
</asp:DataList>
</div>
</form>
</body>
</html>
One might guess that calling Clear on SqlDataSource2.SelectParameters before calling Add might do the trick.