Foren
Nullpointer at Param Util Get String method
Jennis Vaishnav, geändert vor 7 Jahren.
Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste Beiträge
Hello everyone,
I have a following code snippet, which creates a List<users> and displays all the users with their id name and other fields.
Here's the code from list.jsp, which creates a list
I have a following code snippet, which creates a List<users> and displays all the users with their id name and other fields.
Here's the code from list.jsp, which creates a list
<portlet:defineobjects />
<portlet:renderurl var="Update_controller">
<portlet:param name="jspPage" value="/html/users/update.jsp" />
</portlet:renderurl>
<%List<com.test.model.users> usersJsp=UsersLocalServiceUtil.getUserses(0,UsersLocalServiceUtil.getUsersesCount());
long operationalId=1;
for(int i=0;i<usersjsp.size();i++) { string value="usersJsp.get(i).toString().replace("{"," " ").replace("}", "); }%>
<c:foreach items="<%=usersJsp%>" var="list">
</c:foreach><br><br><blockquote>value="${list.id }"</blockquote><br><br><pre><code>
<portlet:defineobjects />
<%!
ActionRequest portletRequest;
%>
<%
String id=ParamUtil.getString(portletRequest, "Update");
%>
</code></pre><br><br><table border="1">
<tbody><tr><th>ID</th>
<th>First Name</th>
<th>Email</th>
<th>Actions</th>
</tr><tr>
<td>
<c:out value="${list.id }"></c:out>
</td>
<td>
<c:out value="${list.fname}"></c:out>
</td>
<td>
<c:out value="${list.email}"></c:out>
</td>
<td>
<a href="<%=Update_controller%>" style="text-decoration:none;"><aui:button lable="Update" name="Update" value="${list.id }" type="button" /></a>
</td>
</tr>
Now, I'm trying to get the in the last button to another jsp, by writing the following code in second jsp, Assume that necessary taglibs are imported:Any other way to store the dynamically generated id would be greatly appreciated, Suggestion are welcomed, a better way to send the id is also acceptable. This code works well till the control goes to the mentioned url. The null pointer can also due to some other reasons also, but I'm not able to get it, Hence i kept the name as null pointer at ParamUtil.GetString().</tbody></table></usersjsp.size();i++)></com.test.model.users>
ismail zabiulla, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 70 Beitrittsdatum: 13.07.14 Neueste Beiträge
Hi Jennis
This line of code is not right . How you are expecting param value Update to travel to next jsp i dont know
For quick fix you can try like this
I would suggest you to go through some blogs explaining liferay urls
regards
ismail
This line of code is not right . How you are expecting param value Update to travel to next jsp i dont know
<a href="<%=Update_controller%>"style="text-decoration:none;"><aui:button lable="Update" name="Update" value="${list.id }" type="button"/></a>
For quick fix you can try like this
<a href='<%=Update_controller%>&update{list.id }' style="text-decoration:none;"><aui:button label="Update" name="Update" value="${list.id }" type="button"/></a>
I would suggest you to go through some blogs explaining liferay urls
regards
ismail
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste Beiträge
For quick fix you can try like this<a href='<%=Update_controller%>&update{list.id }' style="text-decoration:none;"><aui:button label="Update" name="Update" value="${list.id }" type="button"/></a>
I would suggest you to go through some blogs explaining liferay urls
regards
ismail
Hi Ismail,
Thanks for the reply but, this also gave the same error!
Here are the error:
05:04:55,978 ERROR [http-nio-8080-exec-3][PortletRequestDispatcherImpl:261] org.apache.jasper.JasperException: java.lang.NullPointerException
org.apache.jasper.JasperException: java.lang.NullPointerException
05:04:55,985 ERROR [http-nio-8080-exec-3][PortletServlet:109] javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.NullPointerException
javax.portlet.PortletException: org.apache.jasper.JasperException: java.lang.NullPointerException
Caused by: org.apache.jasper.JasperException: java.lang.NullPointerException
Caused by: java.lang.NullPointerException
at com.liferay.portal.kernel.util.ParamUtil.getString(ParamUtil.java:2273)
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste Beiträgeismail zabiulla:
I would suggest you to go through some blogs explaining liferay urls
ismail
It would be great If you can share Important links and blogs regarding url and param passing!
-Thank you
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste Beiträge
Clarified Question:
<liferay-ui:icon id="${list.id }" image="edit" url="<%=Update_controller%>" message="Edit"/>
How pass the id obtained above in icon tag , to another jsp and retive in another jsp!
Any help would be greatly appreciated!
<liferay-ui:icon id="${list.id }" image="edit" url="<%=Update_controller%>" message="Edit"/>
How pass the id obtained above in icon tag , to another jsp and retive in another jsp!
Any help would be greatly appreciated!
Vicente Soriano Martinez, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
New Member Beiträge: 20 Beitrittsdatum: 23.07.14 Neueste Beiträge
I suppose it should work the way you want if you include the code
inside the for loop, and you add a param to each renderURL like this:
NOTE: I didn't test it, so check if you can use the EL expression inside that portlet:param element.
Regards.
<portlet:renderurl var="Update_controller">
<portlet:param name="jspPage" value="/html/users/update.jsp" />
</portlet:renderurl>
inside the for loop, and you add a param to each renderURL like this:
<portlet:renderurl var="Update_controller">
<portlet:param name="jspPage" value="/html/users/update.jsp" />
<portlet:param name="Update" value="${list.id }" />
</portlet:renderurl>
NOTE: I didn't test it, so check if you can use the EL expression inside that portlet:param element.
Regards.
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste BeiträgeVicente Soriano Martinez:
I suppose it should work the way you want if you include the code<portlet:renderurl var="Update_controller"> <portlet:param name="jspPage" value="/html/users/update.jsp" /> </portlet:renderurl>
inside the for loop, and you add a param to each renderURL like this:<portlet:renderurl var="Update_controller"> <portlet:param name="jspPage" value="/html/users/update.jsp" /> <portlet:param name="Update" value="${list.id }" /> </portlet:renderurl>
NOTE: I didn't test it, so check if you can use the EL expression inside that portlet:param element.
Regards.
Hi Vincente,
Firstly I would like to Thank you for answering my question, but on execution that again generated null pointer error, I'm working on this for almost 3 to 4 days, still not got a way to pass the id from one jsp to another jsp page.
Vicente Soriano Martinez, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
New Member Beiträge: 20 Beitrittsdatum: 23.07.14 Neueste Beiträge
If you're getting a NullPointerException then it's a matter of searching what variable is null and why it is null.
In this case, I guess your list object seems the perfect candidate to be null, which is probably caused because the variable usersJsp is filled with null values at some point. Did you checked your UsersLocalServiceUtil.getUserses() method? Did it return values?
You may need to debug your code in order to search for that null value.
In this case, I guess your list object seems the perfect candidate to be null, which is probably caused because the variable usersJsp is filled with null values at some point. Did you checked your UsersLocalServiceUtil.getUserses() method? Did it return values?
You may need to debug your code in order to search for that null value.
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste BeiträgeVicente Soriano Martinez:
If you're getting a NullPointerException then it's a matter of looking what variable is null and why it is null.
In this case, I guess your list object seems the perfect candidate to be null, which is probably caused because the variable usersJsp is filled with null values at some point. Did you checked your UsersLocalServiceUtil.getUserses() method? Did it return values?
You may need to debug your code in order to search for that null value.
Here is my complete list.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ page import="com.test.service.UsersLocalServiceUtil" %>
<%@ page import="com.test.PaginationUtility" %>
<%@ taglib uri="http://liferay.com/tld/ui" prefix="liferay-ui" %>
<%@ page isELIgnored ="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<portlet:defineObjects />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
Good to list!
<%List<com.test.model.Users> usersJsp=UsersLocalServiceUtil.getUserses(0,UsersLocalServiceUtil.getUsersesCount());
long operationalId=1;
for(int i=0;i<usersJsp.size();i++)
{
String value=usersJsp.get(i).toString().replace("{", " ").replace("}", " ");
}
%>
<table border="1" width="50%">
<tr>
<th>ID</th>
<th>First Name</th>
<th>Email</th>
<th>Actions</th>
</tr>
<c:forEach items="<%=usersJsp%>" var="list">
<tr>
<td>
<c:out value="${list.id }"></c:out>
</td>
<td>
<c:out value="${list.fname}"></c:out>
</td>
<td>
<c:out value="${list.email}"></c:out>
</td>
<td>
<portlet:renderURL var="Update_controller">
<portlet:param name="jspPage" value="/html/users/update.jsp" />
<portlet:param name="updateParam" value="${list.id }" />
</portlet:renderURL>
<liferay-ui:icon id="${list.id }"image="edit" url="<%=Update_controller%>"/>
</td>
</tr>
</c:forEach>
</table>
</body>
update.jsp:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ page import="com.liferay.portal.kernel.util.ParamUtil" %>
<%@ page import="javax.portlet.ActionRequest" %>
<%@ page import="javax.portlet.ActionResponse" %>
<%@ taglib uri="http://liferay.com/tld/aui" prefix="aui" %>
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<portlet:defineObjects />
<%!
ActionRequest portletRequest;
ActionResponse portletResponse;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<%String id=ParamUtil.getString(portletRequest, "updateParam"); %>
<body>
<aui:input label="Value" name="value" type="text" value="<%=id %>"></aui:input>
</body>
</html>
The out put from list.jsp is all the records from the desired database, it successfully displays all the user from database, but when we click on the icon which is provided with certain url, it throws null pointer error, and one more thing i'll like to add, if i comment the line of code which is in red colour, and remove it form value assigned to the text field it runs without error,this makes me think that ParamUtil might be throwing null due to some or other reason(which i dont know).
Another inspection shows that, when we inspect the icon i found the following:
<a href="http://localhost:8080/web/guest/servicebuilder?p_p_id=users_WAR_Portalportlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_users_WAR_Portalportlet_jspPage=%2Fhtml%2Fusers%2Fupdate.jsp&_users_WAR_Portalportlet_updateParam=501" target="_self" class=" lfr-icon-item taglib-icon" id="_users_WAR_Portalportlet_501"> <img id="501" src="http://localhost:8080/o/classic-theme/images/common/edit.png" alt="Edit" title="Edit"> <span class="taglib-text hide-accessible">Edit</span> </a>
The variable updateParam captures the value, but i'm failing to get that value in another jsp, Any help would be greatly appreciated.
Vicente Soriano Martinez, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
New Member Beiträge: 20 Beitrittsdatum: 23.07.14 Neueste Beiträge
Ok, so the URL is built as one should expect.
Since <portlet:defineObjects /> instantiates several objects, including portletRequest and portletResponse... can you remove this block from update.jsp?
Since <portlet:defineObjects /> instantiates several objects, including portletRequest and portletResponse... can you remove this block from update.jsp?
<%!
ActionRequest portletRequest;
ActionResponse portletResponse;
%>
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste BeiträgeVicente Soriano Martinez:
Ok, so the URL is built as one should expect.
Since <portlet:defineObjects /> instantiates several objects, including portletRequest and portletResponse... can you remove this block from update.jsp?<%! ActionRequest portletRequest; ActionResponse portletResponse; %>
Removing that block results into immediate error "portletRequest cannot be resolved to a variable", so I think that block should remain, guess!
I'm sorry if I'm wrong, but this really shows error
Vicente Soriano Martinez, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method (Antwort)
New Member Beiträge: 20 Beitrittsdatum: 23.07.14 Neueste Beiträge
Sorry, my bad for not checking the names of the objetcs that the <portlet:defineObjects /> creates, but you're wrong: that block doesn't do anything.
The actual names are renderRequest and renderResponse. There are more objects created by <portlet:defineObjects />, have a look on them, they're really useful.
With that block of code removed, try changing the line
by this one:
The actual names are renderRequest and renderResponse. There are more objects created by <portlet:defineObjects />, have a look on them, they're really useful.
With that block of code removed, try changing the line
<%String id=ParamUtil.getString(portletRequest, "updateParam"); %>
by this one:
<%String id=ParamUtil.getString(renderRequest, "updateParam"); %>
Jennis Vaishnav, geändert vor 7 Jahren.
RE: Nullpointer at Param Util Get String method
Junior Member Beiträge: 59 Beitrittsdatum: 01.02.17 Neueste BeiträgeVicente Soriano Martinez:
Sorry, my bad for not checking the names of the objetcs that the <portlet:defineObjects /> creates, but you're wrong: that block doesn't do anything.
The actual names are renderRequest and renderResponse. There are more objects created by <portlet:defineObjects />, have a look on them, they're really useful.
With that block of code removed, try changing the line<%String id=ParamUtil.getString(portletRequest, "updateParam"); %>
by this one:<%String id=ParamUtil.getString(renderRequest, "updateParam"); %>
Thanks! Worked