Reputation: 83
I'm trying to get page structure name. I made hook and writing checking every page structure name.
I used JournalStructureLocalServiceUtil.getStructure()
but it didn't work and gave me errors and when i used JournalStructureLocalServiceUtil.getStructures()
it gave me the result
[{uuid=6e12b579-c03e-4bd1-a4b3-45c6259807c7, id=10802,groupId=88,
companyId=1, userId=2, userName=Haider Ghaleb, createDate=Wed Sep 05 12:23:43 GMT
2012, modifiedDate=Mon Sep 10 16:23:46 GMT 2012, structureId=10801,
parentStructureId=, name=Restriction, description=Testing testing, xsd= }]
Here i can find the structure name "Restriction". Anyone can help me in this, Also i used
BeanParamUtil.getString(article, request, "structureId")
BeanParamUtil.getLong(article, request, "groupId", scopeGroupId)
To get the structure ID and group ID.
Upvotes: 1
Views: 2629
Reputation: 83
Thank you @Jonny, now we have 2 methods of getting the Structure Name
First Method (Yours):
<%
String structureId2 = article.getStructureId();
long groupId2 = article.getGroupId();
String structureName = JournalStructureLocalServiceUtil.getStructure(groupId2, structureId2).getName(Locale.US, true);
%>
<h3>Structure Name 2="<%= structureName %>"</h3>
Second Method (mine):
<%
String structureId= BeanParamUtil.getString(article, request, "structureId");
long groupId1 = BeanParamUtil.getLong(article, request, "groupId", scopeGroupId);
JournalStructure js=(JournalStructure)JournalStructureLocalServiceUtil.getStructure(groupId1, structureId);
%>
<h2>Structure Name="<%= js.getName() %>"</h2>
Both will get the right answer. Thanks a lot. I will post another question in a while regarding sending password from hook, and validate on the same page if the password is right or no, if yes, then it will display the content.
If you can help in this i will appreciate.
Upvotes: 1
Reputation: 2683
You were nearly there with getting the name of the Structure! Try the following code:
String structureName = JournalStructureLocalServiceUtil.getStructure(groupId, structureId).getName(Locale.US, true);
Where "groupId" and "structureId" are the ones you've grabbed via BeanParamUtil or as Prakash has suggested (and it's also a better way):
String structureId = article.getStructureId();
long groupId = article.getGroupId();
The part that says getName(Locale.US, true);
will get the name of the structure with the Locale for US, or if there isn't one for the Locale US it will return the default Locale version.
This should do the trick for you.
Upvotes: 1