Ray Auge 16 Years Ago I just updated the Wiki with and example of how this might be used from either XSL or VM templates.<a href="http://wiki.liferay.com/index.php/Journal_Internal_API#Request_Handling_Example">http://wiki.liferay.com/index.php/Journal_Internal_API#Request_Handling_Example</a>Enjoy! Please sign in to reply. Reply as... Cancel James Min Ray Auge 15 Years Ago awesome Please sign in to reply. Reply as... Cancel simon tuffle Ray Auge 14 Years Ago hai Ray,Could you please assist me in retrieving the portletsession variable kept in jsp into .vm file. I tried in the below fashion but unable to get the value..#set ($somePSAttribute = $request.get('portlet-session').get('keyname').get('com.liferay.util.servlet.SessionMessages'))or i need to write an additional code in any .xml files? Please sign in to reply. Reply as... Cancel Ray Augé simon tuffle 13 Years Ago $request.portlet-session gets you the session Map. but there are two paths from here: portlet-attributes, and application-attributes to emulate the PortletSession.PORTLET_SCOPE and PortletSession.APPLICATION_SCOPE respectively.Therefore you would have something like:#set ($attribute = $request.portlet-session.portlet-attributes.keyname)Note: the returned type is always String, so you may have to parse that result of the object was serializable, but not a String or primitive or primitive Wrapper class object. Please sign in to reply. Reply as... Cancel Christian De Vera Talampas Ray Auge 13 Years Ago Hi Ray!Sorry for posting in a wrong thread. Do you have example on how to initialize and manipulate arrays in velocity?Thanks Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago Arrays are handled automatically in Velocity. this is how you create an empty array: #set ($arr = []) a non-empty array: #set ($arr2 = [1, 2, 3])But whenever you think "array", you should really think "ArrayList", which means that manipulation uses the java.util.List interface: $arr2.add(4), $arr2.size(), etcBut where you are passing this to a method call that really requires an array, velocity will autobox down from ArrayList to plain array, as long as the contents of the ArrayList fit the parameter array type of the method. Please sign in to reply. Reply as... Cancel Christian De Vera Talampas Ray Augé 13 Years Ago thanks ray! however i have other queries. i tried to use this line $arr2.add(1) but i noticed that it returns a value "true" (probably a flag). how can i prevent that from happening? i just want to insert an element and access it. plus if i want to access an array element of a certain index, how do i do that? Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago The only way that I have found to do this in velocity was to fudge a void method call using #set:#set ($void = $list.add($thing)) Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel jeff gerbracht Ray Augé 13 Years Ago I'm struggling with arrays in Velocity, specifically, I can't get the method TagsEntryLocalService.getEntryIds() to work though getEntry works fine. I've the following code in a template (note that in reality, each #set is on it's own line)#set( $tags=["gallery"])#set ($tagsEntryService= $serviceLocator.findService("com.liferay.portlet.tags.service.TagsEntryLocalService"))#set ($entries=$tagsEntryService.getEntryIds($getterUtil.getLong($companyId),$tags))#set ($entryid=$tagsEntryService.getEntry($getterUtil.getLong($companyId),$tags.get(0)).getEntryId())tags=$tagsentries = $entries entryID=$entryidwhich displaystags=[gallery] entries = $entries entryID=717820and it should be something liketags=[gallery] entries = [717820] entryID=717820Any Ideas??? Please sign in to reply. Reply as... Cancel
simon tuffle Ray Auge 14 Years Ago hai Ray,Could you please assist me in retrieving the portletsession variable kept in jsp into .vm file. I tried in the below fashion but unable to get the value..#set ($somePSAttribute = $request.get('portlet-session').get('keyname').get('com.liferay.util.servlet.SessionMessages'))or i need to write an additional code in any .xml files? Please sign in to reply. Reply as... Cancel Ray Augé simon tuffle 13 Years Ago $request.portlet-session gets you the session Map. but there are two paths from here: portlet-attributes, and application-attributes to emulate the PortletSession.PORTLET_SCOPE and PortletSession.APPLICATION_SCOPE respectively.Therefore you would have something like:#set ($attribute = $request.portlet-session.portlet-attributes.keyname)Note: the returned type is always String, so you may have to parse that result of the object was serializable, but not a String or primitive or primitive Wrapper class object. Please sign in to reply. Reply as... Cancel
Ray Augé simon tuffle 13 Years Ago $request.portlet-session gets you the session Map. but there are two paths from here: portlet-attributes, and application-attributes to emulate the PortletSession.PORTLET_SCOPE and PortletSession.APPLICATION_SCOPE respectively.Therefore you would have something like:#set ($attribute = $request.portlet-session.portlet-attributes.keyname)Note: the returned type is always String, so you may have to parse that result of the object was serializable, but not a String or primitive or primitive Wrapper class object. Please sign in to reply. Reply as... Cancel
Christian De Vera Talampas Ray Auge 13 Years Ago Hi Ray!Sorry for posting in a wrong thread. Do you have example on how to initialize and manipulate arrays in velocity?Thanks Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago Arrays are handled automatically in Velocity. this is how you create an empty array: #set ($arr = []) a non-empty array: #set ($arr2 = [1, 2, 3])But whenever you think "array", you should really think "ArrayList", which means that manipulation uses the java.util.List interface: $arr2.add(4), $arr2.size(), etcBut where you are passing this to a method call that really requires an array, velocity will autobox down from ArrayList to plain array, as long as the contents of the ArrayList fit the parameter array type of the method. Please sign in to reply. Reply as... Cancel Christian De Vera Talampas Ray Augé 13 Years Ago thanks ray! however i have other queries. i tried to use this line $arr2.add(1) but i noticed that it returns a value "true" (probably a flag). how can i prevent that from happening? i just want to insert an element and access it. plus if i want to access an array element of a certain index, how do i do that? Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago The only way that I have found to do this in velocity was to fudge a void method call using #set:#set ($void = $list.add($thing)) Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel jeff gerbracht Ray Augé 13 Years Ago I'm struggling with arrays in Velocity, specifically, I can't get the method TagsEntryLocalService.getEntryIds() to work though getEntry works fine. I've the following code in a template (note that in reality, each #set is on it's own line)#set( $tags=["gallery"])#set ($tagsEntryService= $serviceLocator.findService("com.liferay.portlet.tags.service.TagsEntryLocalService"))#set ($entries=$tagsEntryService.getEntryIds($getterUtil.getLong($companyId),$tags))#set ($entryid=$tagsEntryService.getEntry($getterUtil.getLong($companyId),$tags.get(0)).getEntryId())tags=$tagsentries = $entries entryID=$entryidwhich displaystags=[gallery] entries = $entries entryID=717820and it should be something liketags=[gallery] entries = [717820] entryID=717820Any Ideas??? Please sign in to reply. Reply as... Cancel
Ray Augé Christian De Vera Talampas 13 Years Ago Arrays are handled automatically in Velocity. this is how you create an empty array: #set ($arr = []) a non-empty array: #set ($arr2 = [1, 2, 3])But whenever you think "array", you should really think "ArrayList", which means that manipulation uses the java.util.List interface: $arr2.add(4), $arr2.size(), etcBut where you are passing this to a method call that really requires an array, velocity will autobox down from ArrayList to plain array, as long as the contents of the ArrayList fit the parameter array type of the method. Please sign in to reply. Reply as... Cancel Christian De Vera Talampas Ray Augé 13 Years Ago thanks ray! however i have other queries. i tried to use this line $arr2.add(1) but i noticed that it returns a value "true" (probably a flag). how can i prevent that from happening? i just want to insert an element and access it. plus if i want to access an array element of a certain index, how do i do that? Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago The only way that I have found to do this in velocity was to fudge a void method call using #set:#set ($void = $list.add($thing)) Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel jeff gerbracht Ray Augé 13 Years Ago I'm struggling with arrays in Velocity, specifically, I can't get the method TagsEntryLocalService.getEntryIds() to work though getEntry works fine. I've the following code in a template (note that in reality, each #set is on it's own line)#set( $tags=["gallery"])#set ($tagsEntryService= $serviceLocator.findService("com.liferay.portlet.tags.service.TagsEntryLocalService"))#set ($entries=$tagsEntryService.getEntryIds($getterUtil.getLong($companyId),$tags))#set ($entryid=$tagsEntryService.getEntry($getterUtil.getLong($companyId),$tags.get(0)).getEntryId())tags=$tagsentries = $entries entryID=$entryidwhich displaystags=[gallery] entries = $entries entryID=717820and it should be something liketags=[gallery] entries = [717820] entryID=717820Any Ideas??? Please sign in to reply. Reply as... Cancel
Christian De Vera Talampas Ray Augé 13 Years Ago thanks ray! however i have other queries. i tried to use this line $arr2.add(1) but i noticed that it returns a value "true" (probably a flag). how can i prevent that from happening? i just want to insert an element and access it. plus if i want to access an array element of a certain index, how do i do that? Please sign in to reply. Reply as... Cancel Ray Augé Christian De Vera Talampas 13 Years Ago The only way that I have found to do this in velocity was to fudge a void method call using #set:#set ($void = $list.add($thing)) Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
Ray Augé Christian De Vera Talampas 13 Years Ago The only way that I have found to do this in velocity was to fudge a void method call using #set:#set ($void = $list.add($thing)) Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
prabhakar m Ray Augé 13 Years Ago ray plz help me to get user id in a simple jsp portlet... im very new to liferay.. plz help me Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
Ray Augé prabhakar m 13 Years Ago request.getRemoteUser() Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
prabhakar m Ray Augé 13 Years Ago while im useing <%=request.getRemoteUser()%> im getting null value ... Please sign in to reply. Reply as... Cancel Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
Ray Augé prabhakar m 13 Years Ago Please note that the request must pass through the portal in order to get the proper result.A direct request such as /context-portlet/my.jsp will not work. Please sign in to reply. Reply as... Cancel prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
prabhakar m Ray Augé 13 Years Ago thanks mr. ray.. i got the user attributes in my jsp portlet.. thank you so much... Please sign in to reply. Reply as... Cancel
jeff gerbracht Ray Augé 13 Years Ago I'm struggling with arrays in Velocity, specifically, I can't get the method TagsEntryLocalService.getEntryIds() to work though getEntry works fine. I've the following code in a template (note that in reality, each #set is on it's own line)#set( $tags=["gallery"])#set ($tagsEntryService= $serviceLocator.findService("com.liferay.portlet.tags.service.TagsEntryLocalService"))#set ($entries=$tagsEntryService.getEntryIds($getterUtil.getLong($companyId),$tags))#set ($entryid=$tagsEntryService.getEntry($getterUtil.getLong($companyId),$tags.get(0)).getEntryId())tags=$tagsentries = $entries entryID=$entryidwhich displaystags=[gallery] entries = $entries entryID=717820and it should be something liketags=[gallery] entries = [717820] entryID=717820Any Ideas??? Please sign in to reply. Reply as... Cancel
Kuldeep Bhati 12 Years Ago Hi All,I created a custom.jsp file in which I have simple HttpSession variable as below<code>session.setAttribute("loginname", loginname);</code>My objective is to display this loginname session variable in my portal_normal.vm file, I have also tried using the following way,<code>#set( $session = $request.getSession(true) )#set( $name = $session.getAttribute(loginname) )$name</code>But still no idea, how to access HttpSession data in the velocity file, Please help on this. Please sign in to reply. Reply as... Cancel David García González Kuldeep Bhati 12 Years Ago Hi Simon, I am trying to do the same as you in Liferay 6, but I am unable to get it.Did you finally get the portlet variable you needed?Thanks! Please sign in to reply. Reply as... Cancel KK rajput David García González 12 Years Ago Hi Ray , is it working in liferay 6 ?? I am unable to make it work ?? Below is my codein Jsp :renderRequest.getPortletSession().setAttribute("attr1", "attr1");In vm :#set ($customAttribute = $request.getSession().getAttribute("attr1"))$customAttribute#set ($somePSAttribute = $request.get('portlet-session').get('portlet-attributes').get('attr1'))$somePSAttribute#set ($someASAttribute = $request.get('portlet-session').get('application-attributes').get('attr1'))$someASAttributebut none is working Please sign in to reply. Reply as... Cancel Ray Augé KK rajput 12 Years Ago Since you didn't specify the scope for the attribute, it will be a portlet attribute value and only the SAME portlet will be able to see it, therefore the web content portlet won't be able to see it.To share the attribute you need to set it in the application scope:renderRequest.getPortletSession().setAttribute("attr1", "attr1", PortletSession.APPLICATION_SCOPE);then you'll be able to see it like this:#set ($somePSAttribute = $request.portlet-session.application-attributes.attr1) Please sign in to reply. Reply as... Cancel
David García González Kuldeep Bhati 12 Years Ago Hi Simon, I am trying to do the same as you in Liferay 6, but I am unable to get it.Did you finally get the portlet variable you needed?Thanks! Please sign in to reply. Reply as... Cancel KK rajput David García González 12 Years Ago Hi Ray , is it working in liferay 6 ?? I am unable to make it work ?? Below is my codein Jsp :renderRequest.getPortletSession().setAttribute("attr1", "attr1");In vm :#set ($customAttribute = $request.getSession().getAttribute("attr1"))$customAttribute#set ($somePSAttribute = $request.get('portlet-session').get('portlet-attributes').get('attr1'))$somePSAttribute#set ($someASAttribute = $request.get('portlet-session').get('application-attributes').get('attr1'))$someASAttributebut none is working Please sign in to reply. Reply as... Cancel Ray Augé KK rajput 12 Years Ago Since you didn't specify the scope for the attribute, it will be a portlet attribute value and only the SAME portlet will be able to see it, therefore the web content portlet won't be able to see it.To share the attribute you need to set it in the application scope:renderRequest.getPortletSession().setAttribute("attr1", "attr1", PortletSession.APPLICATION_SCOPE);then you'll be able to see it like this:#set ($somePSAttribute = $request.portlet-session.application-attributes.attr1) Please sign in to reply. Reply as... Cancel
KK rajput David García González 12 Years Ago Hi Ray , is it working in liferay 6 ?? I am unable to make it work ?? Below is my codein Jsp :renderRequest.getPortletSession().setAttribute("attr1", "attr1");In vm :#set ($customAttribute = $request.getSession().getAttribute("attr1"))$customAttribute#set ($somePSAttribute = $request.get('portlet-session').get('portlet-attributes').get('attr1'))$somePSAttribute#set ($someASAttribute = $request.get('portlet-session').get('application-attributes').get('attr1'))$someASAttributebut none is working Please sign in to reply. Reply as... Cancel Ray Augé KK rajput 12 Years Ago Since you didn't specify the scope for the attribute, it will be a portlet attribute value and only the SAME portlet will be able to see it, therefore the web content portlet won't be able to see it.To share the attribute you need to set it in the application scope:renderRequest.getPortletSession().setAttribute("attr1", "attr1", PortletSession.APPLICATION_SCOPE);then you'll be able to see it like this:#set ($somePSAttribute = $request.portlet-session.application-attributes.attr1) Please sign in to reply. Reply as... Cancel
Ray Augé KK rajput 12 Years Ago Since you didn't specify the scope for the attribute, it will be a portlet attribute value and only the SAME portlet will be able to see it, therefore the web content portlet won't be able to see it.To share the attribute you need to set it in the application scope:renderRequest.getPortletSession().setAttribute("attr1", "attr1", PortletSession.APPLICATION_SCOPE);then you'll be able to see it like this:#set ($somePSAttribute = $request.portlet-session.application-attributes.attr1) Please sign in to reply. Reply as... Cancel
Max Gabrielsson 12 Years Ago Is there a way to access the action phase from a journal article. So I can set a session variable and other portlets will render accordingly? The scope would be a mvc portlet that shows detail for an Item which listens to a session variable. I want to be able to do a journal article that shows a link to the item and the details portlet will render that item from the session variable. Please sign in to reply. Reply as... Cancel
suresh yadagiri 10 Years Ago How can we get httpsession in web content VM template? Please sign in to reply. Reply as... Cancel Ray Augé suresh yadagiri 10 Years Ago You can't! You can only get a readonly map which represents any trivially serializable contents it contains. Please sign in to reply. Reply as... Cancel
Ray Augé suresh yadagiri 10 Years Ago You can't! You can only get a readonly map which represents any trivially serializable contents it contains. Please sign in to reply. Reply as... Cancel
suresh yadagiri 10 Years Ago okay. we need to access some data (ex: EmployeeDetails Bean) we get in AutoLogin hook inside content display portlet. As we have only HttpRequest and HttpResponse in Auto Login hook, i am not sure how to send data to VM template. any suggestions? Please sign in to reply. Reply as... Cancel