Foros de discusión

How to use printwriter in Liferay Render Response

thumbnail
Pradeep Kumar Sharma, modificado hace 11 años.

How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
Hi,

I would like to get some help regarding this issue mentioned below.



I have a existing code here and I am trying to bring this SpringMVC application to SpringMVC portlet environment. Any help will be really appreciated.

private void sendOutput(HttpServletRequest request,
HttpServletResponse response, String serverPath, ReportInfo rptInfo)
throws IOException, ServletException {

ReportWriter rw = new ReportWriter(response.getOutputStream());

String metric = request.getParameter("metric");
String outputType = request.getParameter("outputType");
try {

if (metric != null) {
rw.writeHtmlDetail(rptInfo, metric);
} else {
// Check and set output document type.
if (PDF.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
response.setContentType(PDF_CONTENT_TYPE);
response.setHeader("Content-Disposition",
" inline; filename=\"" + FILENAME + ".pdf\"");

// Format and output the report results ...
rw.writePdf(rptInfo);
return;
} else if (EXCEL.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
response.setContentType(EXCEL_CONTENT_TYPE);
response.setHeader("Content-Disposition",
" inline; filename=\"" + FILENAME + ".xls\"");
rw.writeExcel(rptInfo);
return;
} else {
// else HTML ...
// Format and output the report results ...
rw.writeHtml(rptInfo, serverPath);
}
}
} catch (Exception ex) {
throw new ServletException(ex);
}

How should I write a new controller to make this working.

Thank You !
Pradeep

Archivos adjuntos:

thumbnail
David H Nebinger, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 Mensajes recientes
A portlet is different than a servlet. In a servlet, you can generate the whole html that will be rendered in a page.

A portlet, however, is responsible for generating a fragment of the whole aggregated page.

To do this in a portlet, you build it as a resource request (the resource request gets to return the whole thing).
thumbnail
Pradeep Kumar Sharma, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
Thank you David. This helps but need a little more info regarding, how I can make Action using this code:

Note: Hope this value= "/viewDashboard" will not work in Liferay of URL, How I can define this output URL in Liferay

@RequestMapping(value = "/viewDashboard", method = RequestMethod.GET)
// Hope this value= "/viewDashboard" will not work in Liferay of URL, How I can define this output URL in Liferay
public void viewDashboard(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException, DbSqlException {
logger.info("In ComplusController.viewDashboard");
String serverPath = getThisURL(request);

ReportInfo rptInfo = getReportInfo(request);
logger.info("In ComplusController>> Server Path", serverPath);
sendOutput(request, response, serverPath, rptInfo);
}
private static List<String> getSystems(Clients clients) {
List<String> systems = clients.getSystems();
return systems;
}
private static List<String> getMgmtCodes(Clients clients) {
List<String> mgmtCodes = new ArrayList<String>();
List<Client> clientList = clients.getClients();

for (Iterator<Client> it = clientList.iterator(); it.hasNext();) {
Client client = it.next();
mgmtCodes.add(client.getMgmtCode());
}
return mgmtCodes;
}

Im my ResourceMapping, If any help will be really appreciated.

Thanks You !
thumbnail
David H Nebinger, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 Mensajes recientes
This is servlet code. None of it is going to work as a portlet.

File objects would be returned as resource requests. The other code is cut off, so I'm not sure what the getSystems() and getMgmtCodes() is used for.
thumbnail
Hitoshi Ozawa, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Liferay Legend Mensajes: 7942 Fecha de incorporación: 24/03/10 Mensajes recientes
Look at the following page to see how SpringMVC portlet handles Requests.

http://javainfoseek.blogspot.jp/2010/08/spring-mvc-portlet-on-liferay.html
thumbnail
Pradeep Kumar Badhai, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
Thank you Davis and Hitoshi for quick response.

I made it working putting mock value in the JSP screen. Using this ResourceMapping, How I can store the user input and pass to the service. If any help will be really appreciated.

dashboard.jsp
*****************************************************************************
<%@page pageEncoding="UTF-8"%>

<%@ include file="init.jsp"%>
<%@ page isELIgnored="false" %>

<legend> TEST Complus Dashboard Report</legend>


<aui:form method="post" action="${JSPResourceURL}" id="dash-form" name="compForm" onSubmit="return ValidateForm();">

<portlet:resourceURL var="JSPResourceURL">
<portlet:param name="system" value="DBF" />
<portlet:param name="mngmtCo" value="BA" />
<portlet:param name="beginDate" value="01/01/2007" />
<portlet:param name="endDate" value="01/01/2013" />
</portlet:resourceURL>


<p>System:
<input type="text" name="system" id="system" size="15" value="${system}"/>
</p>
<p>Mgmt Code:
<input type="text" name="mgmtCode" id="mgmtCode" size="15" value="${mgmtCode}"/>
</p>
<p>Begin Date:
<input type="text" name="beginDate" id="beginDate" size="15" value="${beginDate}" />
<br />(mm/dd/yyyy)
</p>
<p>End Date:
<input type="text" name="endDate" id="endDate" size="15" value="${endDate}"/>
<br />(mm/dd/yyyy)
</p>

<p>
<label title="Select an output type" for="outputType">*Output Type:</label>
<select name="outputType" id="outputType">
<option value="HTML">Web Browser</option>
<option value="PDF">PDF (Printable)</option>
<option value="EXCEL">Excel (Spreadsheet)</option>
</select>
</p>
<p>*Web Browser: For Screen Use Only</p>
<p>*PDF: For Print Use Only</p>
<p class="submit-button">

<!-- <input type="submit" title="Run Report" value="Run Report" /> -->
<input type="button" name="viewPDFButton" value="Run Report" onClick="window.location.href = '${JSPResourceURL}';" />

</p>
</aui:form>
******************************************************************************
My Controller
******************************************************************************
@Controller("complusController")
@RequestMapping(value = "VIEW")
public class ComplusController {
private static final String CONNECTION_ID = "connection";
private static final Logger logger = LoggerFactory.getLogger(ComplusController.class);

private String sid;
private String sid2;
@RenderMapping
public String dashboardForm(RenderRequest request, RenderResponse response, Model model)
throws DbSqlException, PortletException, ClassNotFoundException, SQLException {

logger.info("In ComplusController.dashboardForm");

DBAccess dbConn = MockDB.getDBAccess();
logger.info("In ComplusController db = {}", dbConn);
logger.info("DBConnecton >>>>> = {}", dbConn);
System.out.println(" DBConnection = {}" +dbConn);

PortletSession session = request.getPortletSession();
session.setAttribute(CONNECTION_ID, dbConn);
System.out.println(" DBConnection = {}" +session);

sid = session.getId();
logger.info("In session id = {Pradeep}", sid);


DBAccess dbAccess = (DBAccess) session.getAttribute(CONNECTION_ID);
logger.info("In ComplusController db = {Sharma}", dbAccess);
System.out.println(" ComplusController db = {DBAccess}" +dbAccess);

//String userId = getUserId(request);
String userId = "pbadhai";
Clients clients = new Clients(dbConn, userId);

List<String> systems = getSystems(clients);
model.addAttribute("systems", systems );
System.out.println("SYSYEM CODE >>>" +systems);

List<String> mgmtCodes = getMgmtCodes(clients);
model.addAttribute("mgmtCodes", mgmtCodes );
System.out.println("MGMT CODE >>>" +mgmtCodes);
System.out.println(" I AM IN VIEW");

String str = null;
str = (String)request.getAttribute("viewResult");

if(str!=null && str.equals("viewResult"))
str = "viewResult";
else
str = "dashboardForm";
System.out.println("str >>>>> = "+ str);

return str;
}

private String getUserId(RenderRequest request) {
String userId = request.getRemoteUser();
if (userId == null)
userId = "ablue";
return userId;
}

private static List<String> getSystems(Clients clients) {
List<String> systems = clients.getSystems();
return systems;
}

private static List<String> getMgmtCodes(Clients clients) {
List<String> mgmtCodes = new ArrayList<String>();
List<Client> clientList = clients.getClients();

for (Iterator<Client> it = clientList.iterator(); it.hasNext();) {
Client client = it.next();
mgmtCodes.add(client.getMgmtCode());
}
return mgmtCodes;
}

private static final String EXCEL = "EXCEL";
private static final String EXCEL_CONTENT_TYPE = "application/vnd.ms-excel";
private static final String FILENAME = "complus";
private static final String PDF = "PDF";
private static final String PDF_CONTENT_TYPE = "application/pdf";

private ReportInfo getReportInfo(ResourceRequest resourceRequest)
throws PortletException, DbSqlException, ServletException {

PortletSession session = resourceRequest.getPortletSession();
logger.info("In ComplusController session = {}", session);

String sid2 = session.getId();
logger.info("In session id = {}", sid);
logger.info("In session id = {}", sid2);

DBAccess dbAccess = (DBAccess) session.getAttribute(CONNECTION_ID);

logger.info("In ComplusController db = {}", dbAccess);

if (dbAccess == null)
throw new DbSqlException("No database connection object in session");

String userId = getUserId(renderRequest);

String system =resourceRequest.getParameter("system");
String mngmtCo = resourceRequest.getParameter("mngmtCo");
String beginDate =resourceRequest.getParameter("beginDate");
String endDate = resourceRequest.getParameter("endDate");

System.out.println("SYSYEM CODE >>>" +system);
System.out.println("MGMT CODE >>>" +mngmtCo);
System.out.println("BEGIN DATE >>>" +beginDate);
System.out.println("END DATE >>>" +endDate);

ReportInfo rptInfo = new ReportInfo(dbAccess, userId);
if (!rptInfo.isUserAuthorized(system, mngmtCo)) {
throw new ServletException(userId
+ " not authorized to access this data.");
}
// Accumulate the report data ...
// (Authorization will be checked)
boolean noError = rptInfo.runReport(system, mngmtCo, beginDate, endDate);
if (!noError) {
throw new PortletException(rptInfo.getErrorMsg());
}

return rptInfo;
}

@ResourceMapping //(value = "action=complusReport")
public void complusReport(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, DbSqlException, ServletException, IOException {

/** String system=ParamUtil.get(resourceRequest, "system", "");
String mngmtCo=ParamUtil.get(resourceRequest, "mngmtCo", "");
String beginDate=ParamUtil.get(resourceRequest, "beginDate", "");
String endDate=ParamUtil.get(resourceRequest, "endDate", ""); */

String system = resourceRequest.getParameter("system");
String mngmtCo = resourceRequest.getParameter("mngmtCo");
String beginDate =resourceRequest.getParameter("beginDate");
String endDate =resourceRequest.getParameter("endDate");

ReportInfo rptInfo = getReportInfo(resourceRequest);

sendOutput(resourceRequest, resourceResponse, rptInfo);

}


private void sendOutput(ResourceRequest resourceRequest, ResourceResponse resourceResponse,
ReportInfo rptInfo) throws ServletException, PortletException, IOException {

ReportWriter rw = new ReportWriter(resourceResponse.getPortletOutputStream());
HttpServletRequest httprequest = PortalUtil.getHttpServletRequest(resourceRequest);

HttpSession session = httprequest.getSession();
OutputStream out = resourceResponse.getPortletOutputStream();

String metric = resourceRequest.getParameter("metric");
String outputType = resourceRequest.getParameter("outputType");
try {

if (metric != null) {
rw.writeHtmlDetail(rptInfo, metric);
} else {
// Check and set output document type.
if (PDF.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
resourceResponse.setContentType(PDF_CONTENT_TYPE);
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"filename="+ FILENAME);

//resourceResponse.setHeader( "FILENAME PDF_CONTENT_TYPE", "1");

// Format and output the report results ...
rw.writePdf(rptInfo);
return;
} else if (EXCEL.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
resourceResponse.setContentType(EXCEL_CONTENT_TYPE);
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"filename="+ FILENAME);
//resourceResponse.setHeader("Content-Disposition"," inline; filename=\"" + FILENAME + ".xls\"");
rw.writeExcel(rptInfo);
return;
} else {
// else HTML ...
// Format and output the report results ...
System.err.println("ERROR: rptINfo=" + rptInfo.toString()) ;
String str = rptInfo.toString();
String str1 = "<body><h1></h1>Hello, ABCD <BR></body>";
// out.write(str1.getBytes());
//out.write(str.getBytes());
rw.writeHtml(rptInfo);
}
}
} catch (Exception ex) {
throw new ServletException(ex);
}
}

Archivos adjuntos:

thumbnail
Pradeep Kumar Badhai, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
Thank you Davis and Hitoshi for quick response.

I made it working putting mock value in the JSP screen. Using this ResourceMapping, How I can store the user input and pass to the service. If any help will be really appreciated.

dashboard.jsp
*****************************************************************************
<%@page pageEncoding="UTF-8"%>

<%@ include file="init.jsp"%>
<%@ page isELIgnored="false" %>

<legend> TEST Complus Dashboard Report</legend>


<aui:form method="post" action="${JSPResourceURL}" id="dash-form" name="compForm" onSubmit="return ValidateForm();">

<portlet:resourceURL var="JSPResourceURL">
<portlet:param name="system" value="DBF" />
<portlet:param name="mngmtCo" value="BA" />
<portlet:param name="beginDate" value="01/01/2007" />
<portlet:param name="endDate" value="01/01/2013" />
</portlet:resourceURL>


<p>System:
<input type="text" name="system" id="system" size="15" value="${system}"/>
</p>
<p>Mgmt Code:
<input type="text" name="mgmtCode" id="mgmtCode" size="15" value="${mgmtCode}"/>
</p>
<p>Begin Date:
<input type="text" name="beginDate" id="beginDate" size="15" value="${beginDate}" />
<br />(mm/dd/yyyy)
</p>
<p>End Date:
<input type="text" name="endDate" id="endDate" size="15" value="${endDate}"/>
<br />(mm/dd/yyyy)
</p>

<p>
<label title="Select an output type" for="outputType">*Output Type:</label>
<select name="outputType" id="outputType">
<option value="HTML">Web Browser</option>
<option value="PDF">PDF (Printable)</option>
<option value="EXCEL">Excel (Spreadsheet)</option>
</select>
</p>
<p>*Web Browser: For Screen Use Only</p>
<p>*PDF: For Print Use Only</p>
<p class="submit-button">

<!-- <input type="submit" title="Run Report" value="Run Report" /> -->
<input type="button" name="viewPDFButton" value="Run Report" onClick="window.location.href = '${JSPResourceURL}';" />

</p>
</aui:form>
******************************************************************************
My Controller
******************************************************************************
@Controller("complusController")
@RequestMapping(value = "VIEW")
public class ComplusController {
private static final String CONNECTION_ID = "connection";
private static final Logger logger = LoggerFactory.getLogger(ComplusController.class);

private String sid;
private String sid2;
@RenderMapping
public String dashboardForm(RenderRequest request, RenderResponse response, Model model)
throws DbSqlException, PortletException, ClassNotFoundException, SQLException {

logger.info("In ComplusController.dashboardForm");

DBAccess dbConn = MockDB.getDBAccess();
logger.info("In ComplusController db = {}", dbConn);
logger.info("DBConnecton >>>>> = {}", dbConn);
PortletSession session = request.getPortletSession();
session.setAttribute(CONNECTION_ID, dbConn);
sid = session.getId();
logger.info("In session id = {Pradeep}", sid);


DBAccess dbAccess = (DBAccess) session.getAttribute(CONNECTION_ID);
logger.info("In ComplusController db = {Sharma}", dbAccess);
System.out.println(" ComplusController db = {DBAccess}" +dbAccess);

//String userId = getUserId(request);
String userId = "apple";
Clients clients = new Clients(dbConn, userId);

List<String> systems = getSystems(clients);
model.addAttribute("systems", systems );
System.out.println("SYSYEM CODE >>>" +systems);

List<String> mgmtCodes = getMgmtCodes(clients);
model.addAttribute("mgmtCodes", mgmtCodes );
System.out.println("MGMT CODE >>>" +mgmtCodes);
System.out.println(" I AM IN VIEW");

String str = null;
str = (String)request.getAttribute("viewResult");

if(str!=null && str.equals("viewResult"))
str = "viewResult";
else
str = "dashboardForm";
System.out.println("str >>>>> = "+ str);

return str;
}

private String getUserId(RenderRequest request) {
String userId = request.getRemoteUser();
if (userId == null)
userId = "apple";
return userId;
}

private static List<String> getSystems(Clients clients) {
List<String> systems = clients.getSystems();
return systems;
}

private static List<String> getMgmtCodes(Clients clients) {
List<String> mgmtCodes = new ArrayList<String>();
List<Client> clientList = clients.getClients();

for (Iterator<Client> it = clientList.iterator(); it.hasNext();) {
Client client = it.next();
mgmtCodes.add(client.getMgmtCode());
}
return mgmtCodes;
}

private static final String EXCEL = "EXCEL";
private static final String EXCEL_CONTENT_TYPE = "application/vnd.ms-excel";
private static final String FILENAME = "complus";
private static final String PDF = "PDF";
private static final String PDF_CONTENT_TYPE = "application/pdf";

private ReportInfo getReportInfo(ResourceRequest resourceRequest)
throws PortletException, DbSqlException, ServletException {

PortletSession session = resourceRequest.getPortletSession();
logger.info("In ComplusController session = {}", session);

String sid2 = session.getId();
logger.info("In session id = {}", sid);
logger.info("In session id = {}", sid2);

DBAccess dbAccess = (DBAccess) session.getAttribute(CONNECTION_ID);

logger.info("In ComplusController db = {}", dbAccess);

if (dbAccess == null)
throw new DbSqlException("No database connection object in session");

String userId = getUserId(renderRequest);

/// I want to store somewhere here the request parameter from screen

String system =resourceRequest.getParameter("system");
String mngmtCo = resourceRequest.getParameter("mngmtCo");
String beginDate =resourceRequest.getParameter("beginDate");
String endDate = resourceRequest.getParameter("endDate");

ReportInfo rptInfo = new ReportInfo(dbAccess, userId);
if (!rptInfo.isUserAuthorized(system, mngmtCo)) {
throw new ServletException(userId
+ " not authorized to access this data.");
}
// Accumulate the report data ...
// (Authorization will be checked)
boolean noError = rptInfo.runReport(system, mngmtCo, beginDate, endDate);
if (!noError) {
throw new PortletException(rptInfo.getErrorMsg());
}

return rptInfo;
}

@ResourceMapping //(value = "action=complusReport")
public void complusReport(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, DbSqlException, ServletException, IOException {


/// OR here I wanted to store somewhere here the request parameter from screen
/** String system=ParamUtil.get(resourceRequest, "system", "");
String mngmtCo=ParamUtil.get(resourceRequest, "mngmtCo", "");
String beginDate=ParamUtil.get(resourceRequest, "beginDate", "");
String endDate=ParamUtil.get(resourceRequest, "endDate", ""); */

String system = resourceRequest.getParameter("system");
String mngmtCo = resourceRequest.getParameter("mngmtCo");
String beginDate =resourceRequest.getParameter("beginDate");
String endDate =resourceRequest.getParameter("endDate");

ReportInfo rptInfo = getReportInfo(resourceRequest);

sendOutput(resourceRequest, resourceResponse, rptInfo);

}


private void sendOutput(ResourceRequest resourceRequest, ResourceResponse resourceResponse,
ReportInfo rptInfo) throws ServletException, PortletException, IOException {

ReportWriter rw = new ReportWriter(resourceResponse.getPortletOutputStream());
HttpServletRequest httprequest = PortalUtil.getHttpServletRequest(resourceRequest);

HttpSession session = httprequest.getSession();
OutputStream out = resourceResponse.getPortletOutputStream();

String metric = resourceRequest.getParameter("metric");
String outputType = resourceRequest.getParameter("outputType");
try {

if (metric != null) {
rw.writeHtmlDetail(rptInfo, metric);
} else {
// Check and set output document type.
if (PDF.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
resourceResponse.setContentType(PDF_CONTENT_TYPE);
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"filename="+ FILENAME);

//resourceResponse.setHeader( "FILENAME PDF_CONTENT_TYPE", "1");

// Format and output the report results ...
rw.writePdf(rptInfo);
return;
} else if (EXCEL.equals(outputType)) {
/* This updates the HTML header so it must be the first thing output. */
resourceResponse.setContentType(EXCEL_CONTENT_TYPE);
resourceResponse.addProperty(HttpHeaders.CACHE_CONTROL, "max-age=3600, must-revalidate");
resourceResponse.addProperty(HttpHeaders.CONTENT_DISPOSITION,"filename="+ FILENAME);
//resourceResponse.setHeader("Content-Disposition"," inline; filename=\"" + FILENAME + ".xls\"");
rw.writeExcel(rptInfo);
return;
} else {
// else HTML ...
// Format and output the report results ...
System.err.println("ERROR: rptINfo=" + rptInfo.toString()) ;
String str = rptInfo.toString();
String str1 = "<body><h1></h1>Hello, ABCD <BR></body>";

rw.writeHtml(rptInfo);
}
}
} catch (Exception ex) {
throw new ServletException(ex);
}
}

Archivos adjuntos:

thumbnail
Pradeep Kumar Badhai, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
Hi All,

I am trying to fix the above issue in JSP, I tried this approach

<%@page pageEncoding="UTF-8"%>

<%@ include file="init.jsp"%>
<%@ page isELIgnored="false" %>
<legend>Complus Dashboard Reports </legend>

<aui:form method="post" action="${JSPResourceURL}" id="dash-form" name="compForm" onSubmit="return ValidateForm();">

<portlet:resourceURL var="SubmitURL" />

<portlet:param name="system" id="txt1" /> /// If I am using for one value like this is working // <portlet:param name="system" value="ABC" />
<portlet:param name="mngmtCo" id="txt2" />
<portlet:param name="beginDate" id="txt3" />
<portlet:param name="endDate" id="txt4" />
</portlet:resourceURL>

<input type="button" onclick="helpful();" value="Submit" />
<SCRIPT LANGUAGE="JavaScript">
function helpful()
{
var system=document.getElementById('txt1').value;
var mngmtCo=document.getElementById('txt2').value;
var beginDate=document.getElementById('txt3').value;
var endDate=document.getElementById('txt4').value;
$.ajax ({

url:'<%=JSPResourceURL%>',
type: 'POST',
data : ({
textVal: textvalue

}),
success: function()
{
alert('success');

}
});

}
</SCRIPT>
<p>System:
<input type="text" name="system" id="system" size="15" value="${system}"/>
</p>
<p>Mgmt Code:
<input type="text" name="mgmtCode" id="mgmtCode" size="15" value="${mgmtCode}"/>
</p>
<p>Begin Date:
<input type="text" name="beginDate" id="beginDate" size="15" value="${beginDate}" />
<br />(mm/dd/yyyy)
</p>
<p>End Date:
<input type="text" name="endDate" id="endDate" size="15" value="${endDate}"/>
<br />(mm/dd/yyyy)
</p>

<p>
<label title="Select an output type" for="outputType">*Output Type:</label>
<select name="outputType" id="outputType">
<option value="HTML">Web Browser</option>
<option value="PDF">PDF (Printable)</option>
<option value="EXCEL">Excel (Spreadsheet)</option>
</select>
</p>
<p>*Web Browser: For Screen Use Only</p>
<p>*PDF: For Print Use Only</p>
<p class="submit-button">

<!-- <input type="submit" title="Run Report" value="Run Report" /> -->
<input type="button" name="runReport" value="Run Report" onClick="window.location.href = '${JSPResourceURL}';" />

</p>
</aui:form>

Now on the ServeResource method in the Controller I added this code

final String system= resourceRequest.getParameter("textVal1");
final String mgmgCo= resourceRequest.getParameter("textVal2");
final String startDate= resourceRequest.getParameter("textVal3");
final String endDate= resourceRequest.getParameter("textVal4");


Any Help will be appreciated.
Thank You.
thumbnail
Pradeep Kumar Badhai, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Junior Member Mensajes: 50 Fecha de incorporación: 6/09/11 Mensajes recientes
I have solve this issue and now getting the HTML Report. Still I am not getting the same page HTML reports PDF and Excel type report, If any of us from this community have faced such while generating PDF and Excel Report. I am getting this exception

Caused by: ExceptionConverter: ClientAbortException: java.io.IOException
21:17:54,921 ERROR [http-apr-8080-exec-12][PortletServlet:115] javax.portlet.PortletException: Request processing failed
javax.portlet.PortletException: Request processing failed
at org.springframework.web.portlet.FrameworkPortlet.processRequest(FrameworkPortlet.java:545)
at org.springframework.web.portlet.FrameworkPortlet.serveResource(FrameworkPortlet.java:478)
at com.liferay.portlet.FilterChainImpl.doFilter(FilterChainImpl.java:118)
........................... cont....................
Caused by: javax.servlet.ServletException: ExceptionConverter: ClientAbortException: java.io.IOException
at com.bfds.portal.complus.reports.controller.ComplusController.sendOutput(ComplusController.java:342)
at com.bfds.portal.complus.reports.controller.ComplusController.complusReport(ComplusController.java:269)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

If any of us can suggest something regarding this will be wonderful.
thumbnail
meera prince, modificado hace 11 años.

RE: How to use printwriter in Liferay Render Response

Liferay Legend Mensajes: 1111 Fecha de incorporación: 8/02/11 Mensajes recientes
HI Pradeep Kumar Badhai,

Use direct ServeResource Response to set the content type and headers.

response.setContentType("application/pdf");
response.setProperty(com.liferay.portal.kernel.servlet.HttpHeaders.CONTENT_DISPOSITION,"attachement;filename=filename");

OutputStream os = response.getPortletOutputStream();

need not use HttpServletResponce any where. directly use all serveResourseResponse and l serveResourseRequest where ever you required.


Regards,
Meera Prince
http://www.liferaysavvy.com/