Foren

How do I get my product id from ActionRequest?

Peter Hellstrand, geändert vor 12 Jahren.

How do I get my product id from ActionRequest?

Junior Member Beiträge: 26 Beitrittsdatum: 11.10.11 Neueste Beiträge
I am very new to life ray. I am following the examples in the book "Liferay in action". The author does not show how to do this. My getPRProduct expects a long.

Thanks!

	public static PRProduct productFromRequest(ActionRequest request){
		PRProductLocalService service = new PRProductLocalServiceImpl(); 
		
		service.getPRProduct(arg0);
		return new PRProductImpl();
	}
	
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
I have not read the book but to get something from service use Util

String idStr = request.getParameter("your-form-field-name");
long id; //parse string to long and give to localserviceutil
PRProductLocalServiceUtil.getPRProduct(id)
Peter Hellstrand, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Junior Member Beiträge: 26 Beitrittsdatum: 11.10.11 Neueste Beiträge
Thanks. I could get form fields like that. There is no form field with productID. Could it be in the session in some other way or is it just the "names" from the forms that get posted?

This one "<portlet:actionURL name="addProduct" var="addProductURL" />" also looks ver strange in my browser. " " How is that possible?

&lt;%@include file="/init.jsp" %&gt;

<portlet:actionurl name="addProduct" var="addProductURL" />

<aui:form action="<%= addProductURL.toString() %>" method="post">

	<aui:fieldset>
		<aui:input name="productName" size="45" />
		<aui:input name="productSerial" size="45" />
		<aui:button-row>
			<aui:button type="submit" />
		</aui:button-row>
	</aui:fieldset>
</aui:form>


<liferay-ui:search-container emptyresultsmessage="there-are-no-products" delta="5">

<liferay-ui:search-container-results>

&lt;%
List<prproduct> tempResults = ActionUtil.getProducts(renderRequest);
results = ListUtil.subList(
tempResults, searchContainer.getStart(),searchContainer.getEnd());
total = tempResults.size();
pageContext.setAttribute("results", results);
pageContext.setAttribute("total", total);
%&gt;
</prproduct></liferay-ui:search-container-results>

<liferay-ui:search-container-row classname="com.inkwell.internet.productregistration.model.PRProduct" keyproperty="productId" modelvar="product">

	<liferay-ui:search-container-column-text name="product-name" property="productName" />
	<liferay-ui:search-container-column-text name="product-serial" property="productSerial" />
	<liferay-ui:search-container-column-jsp path="/admin/admin_actions.jsp" align="right" />

</liferay-ui:search-container-row>


<liferay-ui:search-iterator />

</liferay-ui:search-container>
thumbnail
Jignesh Vachhani, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Liferay Master Beiträge: 803 Beitrittsdatum: 10.03.08 Neueste Beiträge
if i understand correctly you want to get product id from request right ?

If it is so , you can get it by using request.getparameter("prodId");
Peter Hellstrand, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Junior Member Beiträge: 26 Beitrittsdatum: 11.10.11 Neueste Beiträge
Correct. I guess that is what I want do do.

request.getparameter("prodId");



Where do the "prodId" come from. Where is it injected in the Actionrequest?


Well I should not grt my product from the database in that method. Only create a new one that can be inserted later. I got two properties

		<aui:input name="productName" size="45" />
		<aui:input name="productSerial" size="45" />


I also need company-id and missing-group-id according to the book.

Edit: I guess I can get it from ThemeDisplay

long companyId = themeDisplay.getCompanyId();
		long groupId = themeDisplay.getLayout().getGroupId();


But he does not pass theme display to the method.
thumbnail
Ravi Kumar Gupta, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Liferay Legend Beiträge: 1302 Beitrittsdatum: 24.06.09 Neueste Beiträge
To get theme display use

ThemeDisplay themeDisplay = (ThemeDisplay) renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
Peter Hellstrand, geändert vor 12 Jahren.

RE: How do I get my product id from ActionRequest?

Junior Member Beiträge: 26 Beitrittsdatum: 11.10.11 Neueste Beiträge
Thanks that works