掲示板

How to send variable data from doView to JSP page?

12年前 に Dean Grobler によって更新されました。

How to send variable data from doView to JSP page?

thumbnail
12年前 に Jignesh Vachhani によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Master 投稿: 803 参加年月日: 08/03/10 最新の投稿
you can set it through renderRequest parameter and can access it to your jsp file.
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
Thats right.. you can access attributes like this.
Just request.getAttribute("attr") will work in jsp..
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
An attribute is an object. You need to check whether it is null or not before you can use it and that will save from some errors as well..

Best is to check before sending the value to jsp. Don't send null.. emoticon

If you can share the code you are using that will give clear idea..
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Hi,

It should work. I am attaching a small portlet called AttributePortlet in which i have set attribute in doView and reading the same in view.jsp

Regards,
Sandeep
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
Try like this..
<%
Object scriptObj = renderRequest.getAttribute("generatedScript");
String script = "";
if(Validator.isNotNull(scriptObj)){
script = scriptObj.toString();
}

%>
Now use script variable as you wish.. it should not give exception.. emoticon
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
Validator is a utility class. You can just check like

if(scriptObj!=null){
script = scriptObj.toString();
}


Or to use Validator you need to import
&lt;%@page import="com.liferay.portal.kernel.util.Validator" %&gt;
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Ravi Kumar Gupta によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1302 参加年月日: 09/06/24 最新の投稿
This should not happen.. can u try this
Object scriptObj = request.getAttribute("generatedScript");

instead of
Object scriptObj = renderRequest.getAttribute("generatedScript");


Can you share complete doView() method code.. are you redirecting to some other page.. ??
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: How to send variable data from doView to JSP page? (回答)

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Try this

public void doView(RenderRequest request, RenderResponse response) throws PortletException, IOException {

//gets data only for consumers table
ResultSet rs = queryDb.queryDb("Consumers");
String javaScript = Tablerize.create(rs);
request.setAttribute("generatedScript", "this is a test variable");

//prints out javascript in console for reference
System.out.println("----------------------------------------------");
System.out.println(javaScript);
System.out.println("----------------------------------------------");

response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
dispatcher.include(request, response);


}

And i would suggest you to use MVCPortlet so that you dont have to worry about dispatching and stuff.

Regards,
sandeep
12年前 に Dean Grobler によって更新されました。

RE: How to send variable data from doView to JSP page?

thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: How to send variable data from doView to JSP page?

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Well if you see your code you were dispatching the control to jsp and then setting the attribute

response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
dispatcher.include(request, response);


-------------------And then--------------

//gets data only for consumers table
ResultSet rs = queryDb.queryDb("Consumers");
String javaScript = Tablerize.create(rs);
request.setAttribute("generatedScript", "this is a test variable");

//prints out javascript in console for reference
System.out.println("----------------------------------------------");
System.out.println(javaScript);
System.out.println("----------------------------------------------");


So its apparent that the request wouldnt have the attribute as you are setting it later. So i moved the logic of fetching from db and setting in request before
First the below

//gets data only for consumers table
ResultSet rs = queryDb.queryDb("Consumers");
String javaScript = Tablerize.create(rs);
request.setAttribute("generatedScript", "this is a test variable");

//prints out javascript in console for reference
System.out.println("----------------------------------------------");
System.out.println(javaScript);
System.out.println("----------------------------------------------");


And then i included the jsp

response.setContentType("text/html");
PortletRequestDispatcher dispatcher =
getPortletContext().getRequestDispatcher("/WEB-INF/jsp/MedelogGetAdmin_view.jsp");
dispatcher.include(request, response);


-------

As far as MVCPortlet goes right now your portlet class may be extending GenericPortlet I suppose but you can extend MVCPortlet instead and it makes life easier for you.

More about MVCPortlet here -->http://www.liferay.com/documentation/liferay-portal/6.0/development/-/ai/portlet-development

Regards,
Sandeep