Fórum

New struts action

Madhukara Patel, modificado 7 Anos atrás.

New struts action

Junior Member Postagens: 46 Data de Entrada: 23/03/15 Postagens Recentes
Hi,

am created new struts action using hook.
now am bale to redirect to jsp page aslo.

my questions is here,

I want to do some resource action or render action in that jsp.
am not able to do .

am facing below issues when importing below tags.

<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/theme" prefix="liferay-theme" %>

<portlet:defineObjects/>
<liferay-theme:defineObjects/>

Error:

May 17, 2016 1:36:02 PM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:638)
thumbnail
Olaf Kock, modificado 7 Anos atrás.

RE: New struts action

Liferay Legend Postagens: 6403 Data de Entrada: 23/09/08 Postagens Recentes
Madhukara Patel:
...
am facing below issues when importing below tags.
...

I'd say they have nothing to do with each other - need more description and information.
thumbnail
Andrew Jardine, modificado 7 Anos atrás.

RE: New struts action

Liferay Legend Postagens: 2416 Data de Entrada: 22/12/10 Postagens Recentes
Can you share the source code with us? Meaning the resource action handlers and the full content of the JSP? As Olaf said, it's hard to help with only 1/2 the story. If the resource action is in your struts action, and you are calling originalStrutsAction.xxx (basically a super type call) after you have sent a response in your resource action then that is probably the problem.
Madhukara Patel, modificado 7 Anos atrás.

RE: New struts action

Junior Member Postagens: 46 Data de Entrada: 23/03/15 Postagens Recentes
HI thanks for your replay.


below controller code:

package com.bc.basil.common.liferayhook;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.time.DateUtils;
import com.bc.basil.model.UserSharedAsset;
import com.bc.basil.service.UserSharedAssetLocalServiceUtil;
import com.liferay.portal.kernel.log.Log;
import com.liferay.portal.kernel.log.LogFactoryUtil;
import com.liferay.portal.kernel.struts.BaseStrutsAction;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.kernel.util.PropsUtil;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.kernel.util.Validator;

public class GuestAssetView extends BaseStrutsAction {
public static final Log LOGGER=LogFactoryUtil.getLog(GuestAssetView.class);
@Override
public String execute(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String baseURL = PropsUtil.getProperties().getProperty("nuxeo.base.url")
+ "nuxeo/site/easyshare/";
String userSharedId = ParamUtil.getString(request, "assetId");
if (!userSharedId.equalsIgnoreCase("assetId")) {
UserSharedAsset userSharedAsset = UserSharedAssetLocalServiceUtil
.getUserSharedAsset(userSharedId);
if (Validator.isNotNull(userSharedAsset)) {
if (!userSharedAsset.getExpiryDate().before(DateUtils.addDays(new Date(),-1))) {
String docType = userSharedAsset.getDocType();
Date expiryDate = userSharedAsset.getExpiryDate();
String data = StringPool.BLANK;
data = baseURL + userSharedAsset.getEasyShareId() + "/"
+ userSharedAsset.getAssetId() + "/"
+ userSharedAsset.getAssetTitle();
request.setAttribute("downloadCount", userSharedAsset.getAssetId());
request.setAttribute("sourceUrl", data);
request.setAttribute("expiryDate", expiryDate);
request.setAttribute("docType", docType);
request.setAttribute("path", userSharedAsset.getAssetPath());
request.setAttribute("assetTitle",
userSharedAsset.getAssetTitle());
request.setAttribute("userSharedAsset", userSharedAsset);
} else {
System.out.println("expired..");
}

}
}
return "/portal/guest_asset_view.jsp";
}
}








Hook.xml is:

<struts-action>
<struts-action-path>/portal/guestassetview</struts-action-path>
<struts-action-impl>com.bc.basil.common.liferayhook.GuestAssetView</struts-action-impl>
</struts-action>


and jsp file is:

<%@page import="javax.portlet.WindowState"%>
<%@page import="javax.portlet.ActionRequest"%>
<%@page import="com.liferay.portal.util.PortletKeys"%>
<%@page import="com.liferay.portal.util.PortalUtil"%>
<%@page import="com.liferay.portlet.PortletURLFactoryUtil"%>
<%@page import="javax.portlet.PortletURL"%>
<link href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/css/bootstrap.min.css' rel='stylesheet' type='text/css'>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.2/js/bootstrap.min.js"></script>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="com.liferay.portal.kernel.util.Validator"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%
String sourceUrl = (String)request.getAttribute("sourceUrl");
String docType = (String)request.getAttribute("docType");
String path1 = (String)request.getAttribute("path");
String assetTitle = (String)request.getAttribute("assetTitle");

PortletURL redirectURL = PortletURLFactoryUtil.getPortletURLFactory();



if(Validator.isNotNull(sourceUrl) && Validator.isNotNull(docType)){
%>
<%=redirectURL.toString() %>
<div class="wrapper">
<div class="header">
<a class="logo default-logo" href="#" title="Go to trl"> <img alt="trl" height="" src="/ace-theme/images/logo.png" width=""> </a>
</div>
<div class="share-img-wrapper row-fluid">
<div class="span4" style="padding:0 15px; border-right:1px solid #E3E3E3; margin:0;">
<div class="summary-img-ht">
<%if(docType.equalsIgnoreCase("Picture")){
%>
<img src="<%=sourceUrl %>" class="img-responsive">
<%} else if(docType.equalsIgnoreCase("Video")){
%>
<video class="img-responsive" controls>
<source src="<%=sourceUrl %>" type="video/mp4">
<source src="<%=sourceUrl %>" type="video/ogg">
Your browser does not support HTML5 video.
</video>
<% } else if(docType.equalsIgnoreCase("Audio")){
%>
<audio class="img-responsive" controls>
<source src="<%=sourceUrl %>" type="audio/ogg">
<source src="<%=sourceUrl %>" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<%}
%><br/>
<%-- <h4>Title</h4><%=assetTitle %><a href="<%=sourceUrl %>" target="_blank" class="download-img"><img alt="trl" height="" src="/ace-theme/images/download.png" width=""></a><br>
<h4>Expiry Date</h4><fmt:formatDate pattern="yyyy-MM-dd"
value="${expiryDate}" /> --%>

</div>
<div class="summary-tools">
<a href="<%=sourceUrl %>" target="_blank" class="download-img"><img alt="trl" height="" src="/ace-theme/images/download.png" width=""></a>
</div>
<%-- <h6><%=assetTitle %></h6><a href="<%=sourceUrl %>" target="_blank" class="download-img"><img alt="trl" height="" src="/ace-theme/images/download.png" width=""></a><br>
<h4>Expiry Date</h4><fmt:formatDate pattern="yyyy-MM-dd"
value="${expiryDate}" /> --%>
</div>
<div class="span8" style="margin:0; padding-left:15px;">
<div class=" non-edit">
<h4 class="widget-title">Information</h4>
<div class="form-group">
<label>Version</label>
<span><c:out value="${userSharedAsset.assetVersion}"/></span>
</div>
<div class="form-group">
<label>Title/Info</label>
<span><c:out value="${userSharedAsset.assetTitle}"/></span>
</div>
<div class="form-group">
<label>Created on</label>
<span><c:out value="${userSharedAsset.assetCreationDate}"/></span>
</div>
<div class="form-group">
<label>Owner / Author</label>
<span><c:out value="${userSharedAsset.assetOwner}"/></span>
</div>
<div class="form-group">
<label>Last Modified Date</label>
<span><c:out value="${userSharedAsset.assetModifiedDate}"/></span>
</div>
<div class="form-group">
<label>Path</label>



<%String ss=path1;
String final1[] =ss.split("/");
String path="";
for (int i=4;i<final1.length;i++ ){
if(path.isEmpty()){
path=final1;
}else {
path=path+"/"+final1;
}

}

%>
<span><%=path%></span>

<%-- <span><c:out value="${userSharedAsset.assetPath}"/></span> --%>
</div>
<div class="form-group">
<label>Document Type</label>
<span><c:out value="${userSharedAsset.assetType}"/></span>
</div>
<div class="form-group">
<label>Countries</label>
<span><c:out value="${userSharedAsset.countries}"/></span>
</div>
<div class="form-group">
<label>Size</label>
<span><c:out value="${userSharedAsset.size}"/></span>
</div>
<div class="form-group">
<label>No of Downloads</label>
<span><c:out value="${userSharedAsset.noofdownloads}"/></span>
</div>
</div>
</div>
</div>

</div>
<div class="footer">
<span>Copyright © 2015 <span class="blue bolder">Brand Centre</span>. All rights reserved</span>
</div>
<%}else{%>
<div class="alert alert-info">

<strong>
<i class="ace-icon fa fa-exclamation-triangle"></i>
Link has expired.
</strong>


</div><%}%>

<style>









My question is i want update some data in ajax call.
how do ajax action from this jsp page.