Liferay 7: Retrieved custom field value using javascript api jsonws return java.lang.NullPointerException
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'm very new to liferay, I've created a page custom field using 'control panel > configuration > custom fields > page'. My goal is to retrieve the value from the page custom field and display the value in my custom portlet. One of the methods I've tried is using ExpandoValue/get-data API from the liferay json web service and this API is generated from localhost:8080/api/jsonws. Below is the generated javascript API:
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
However, this api throws me an error: java.lang.NullPointerException. I'm thinking that this error occurs due to the permission given to the custom field. So, I've ticked View and Update permissions for Guest. But the issue persists.
My question is what triggered this error and how to fix it and is there any other solution I can use to retrieve the value from the page custom field?
Thanks in advance.
Edit
I had misunderstanding in assigning the attributes for the api and here is the new api as suggested by Olaf.
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
It works fine. However it only took the default value but not the value assign for that particular pages.
javascript node.js reactjs liferay
add a comment |
I'm very new to liferay, I've created a page custom field using 'control panel > configuration > custom fields > page'. My goal is to retrieve the value from the page custom field and display the value in my custom portlet. One of the methods I've tried is using ExpandoValue/get-data API from the liferay json web service and this API is generated from localhost:8080/api/jsonws. Below is the generated javascript API:
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
However, this api throws me an error: java.lang.NullPointerException. I'm thinking that this error occurs due to the permission given to the custom field. So, I've ticked View and Update permissions for Guest. But the issue persists.
My question is what triggered this error and how to fix it and is there any other solution I can use to retrieve the value from the page custom field?
Thanks in advance.
Edit
I had misunderstanding in assigning the attributes for the api and here is the new api as suggested by Olaf.
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
It works fine. However it only took the default value but not the value assign for that particular pages.
javascript node.js reactjs liferay
1
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53
add a comment |
I'm very new to liferay, I've created a page custom field using 'control panel > configuration > custom fields > page'. My goal is to retrieve the value from the page custom field and display the value in my custom portlet. One of the methods I've tried is using ExpandoValue/get-data API from the liferay json web service and this API is generated from localhost:8080/api/jsonws. Below is the generated javascript API:
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
However, this api throws me an error: java.lang.NullPointerException. I'm thinking that this error occurs due to the permission given to the custom field. So, I've ticked View and Update permissions for Guest. But the issue persists.
My question is what triggered this error and how to fix it and is there any other solution I can use to retrieve the value from the page custom field?
Thanks in advance.
Edit
I had misunderstanding in assigning the attributes for the api and here is the new api as suggested by Olaf.
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
It works fine. However it only took the default value but not the value assign for that particular pages.
javascript node.js reactjs liferay
I'm very new to liferay, I've created a page custom field using 'control panel > configuration > custom fields > page'. My goal is to retrieve the value from the page custom field and display the value in my custom portlet. One of the methods I've tried is using ExpandoValue/get-data API from the liferay json web service and this API is generated from localhost:8080/api/jsonws. Below is the generated javascript API:
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
However, this api throws me an error: java.lang.NullPointerException. I'm thinking that this error occurs due to the permission given to the custom field. So, I've ticked View and Update permissions for Guest. But the issue persists.
My question is what triggered this error and how to fix it and is there any other solution I can use to retrieve the value from the page custom field?
Thanks in advance.
Edit
I had misunderstanding in assigning the attributes for the api and here is the new api as suggested by Olaf.
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
It works fine. However it only took the default value but not the value assign for that particular pages.
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
Liferay.Service(
'/expandovalue/get-data',
{
companyId: themeDisplay.getCompanyId(),
className: 'com.liferay.portal.model.Page',
tableName: 'CUSTOM_FIELDS',
columnNames: 'pageDetail',
classPK: themeDisplay.getUserId()
},
function(obj) {
console.log(obj);
}
);
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
Liferay.Service(
'/expandovalue/get-data',
{
companyId: 20115,
className: 'com.liferay.portal.kernel.model.Layout',
tableName: 'CUSTOM_FIELDS',
columnName: 'details',
classPK: themeDisplay.getLayoutId()
},
function(obj) {
console.log(obj);
}
);
javascript node.js reactjs liferay
javascript node.js reactjs liferay
edited Jan 3 at 15:42
A.Shah
asked Jan 3 at 3:20
A.ShahA.Shah
11
11
1
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53
add a comment |
1
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53
1
1
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53
add a comment |
1 Answer
1
active
oldest
votes
If memory serves me right, the stock remote API can't be used by unauthenticated users, but requires at least a logged in user (on top of the regular permissions of course).
You can test for this by accessing the API from logged in accounts with the same permissions. If it works there, then this is what you're running into.
However, when I interpret the call in your question correctly, the current user id would be the primary key for the custom field that you're looking at (looking at your classPK
value). For a custom field on the page, I'd have expected a page id (layoutId in Liferay-API-terms). And while I'm seeing this, I notice com.liferay.portal.model.Page
in your snippet. I've not seen that class, and pages can rather be found in com.liferay.portal.kernel.model.Layout
(Assuming Liferay 7.1)
This makes me wonder what you're trying to achieve here - are you rather looking for a user-specific field (that would then be a custom field on the user) or really a page-specific field? Anyways - as this is an answer, not a comment, it might give enough hints to try out and come closer to a solution.
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015903%2fliferay-7-retrieved-custom-field-value-using-javascript-api-jsonws-return-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If memory serves me right, the stock remote API can't be used by unauthenticated users, but requires at least a logged in user (on top of the regular permissions of course).
You can test for this by accessing the API from logged in accounts with the same permissions. If it works there, then this is what you're running into.
However, when I interpret the call in your question correctly, the current user id would be the primary key for the custom field that you're looking at (looking at your classPK
value). For a custom field on the page, I'd have expected a page id (layoutId in Liferay-API-terms). And while I'm seeing this, I notice com.liferay.portal.model.Page
in your snippet. I've not seen that class, and pages can rather be found in com.liferay.portal.kernel.model.Layout
(Assuming Liferay 7.1)
This makes me wonder what you're trying to achieve here - are you rather looking for a user-specific field (that would then be a custom field on the user) or really a page-specific field? Anyways - as this is an answer, not a comment, it might give enough hints to try out and come closer to a solution.
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
add a comment |
If memory serves me right, the stock remote API can't be used by unauthenticated users, but requires at least a logged in user (on top of the regular permissions of course).
You can test for this by accessing the API from logged in accounts with the same permissions. If it works there, then this is what you're running into.
However, when I interpret the call in your question correctly, the current user id would be the primary key for the custom field that you're looking at (looking at your classPK
value). For a custom field on the page, I'd have expected a page id (layoutId in Liferay-API-terms). And while I'm seeing this, I notice com.liferay.portal.model.Page
in your snippet. I've not seen that class, and pages can rather be found in com.liferay.portal.kernel.model.Layout
(Assuming Liferay 7.1)
This makes me wonder what you're trying to achieve here - are you rather looking for a user-specific field (that would then be a custom field on the user) or really a page-specific field? Anyways - as this is an answer, not a comment, it might give enough hints to try out and come closer to a solution.
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
add a comment |
If memory serves me right, the stock remote API can't be used by unauthenticated users, but requires at least a logged in user (on top of the regular permissions of course).
You can test for this by accessing the API from logged in accounts with the same permissions. If it works there, then this is what you're running into.
However, when I interpret the call in your question correctly, the current user id would be the primary key for the custom field that you're looking at (looking at your classPK
value). For a custom field on the page, I'd have expected a page id (layoutId in Liferay-API-terms). And while I'm seeing this, I notice com.liferay.portal.model.Page
in your snippet. I've not seen that class, and pages can rather be found in com.liferay.portal.kernel.model.Layout
(Assuming Liferay 7.1)
This makes me wonder what you're trying to achieve here - are you rather looking for a user-specific field (that would then be a custom field on the user) or really a page-specific field? Anyways - as this is an answer, not a comment, it might give enough hints to try out and come closer to a solution.
If memory serves me right, the stock remote API can't be used by unauthenticated users, but requires at least a logged in user (on top of the regular permissions of course).
You can test for this by accessing the API from logged in accounts with the same permissions. If it works there, then this is what you're running into.
However, when I interpret the call in your question correctly, the current user id would be the primary key for the custom field that you're looking at (looking at your classPK
value). For a custom field on the page, I'd have expected a page id (layoutId in Liferay-API-terms). And while I'm seeing this, I notice com.liferay.portal.model.Page
in your snippet. I've not seen that class, and pages can rather be found in com.liferay.portal.kernel.model.Layout
(Assuming Liferay 7.1)
This makes me wonder what you're trying to achieve here - are you rather looking for a user-specific field (that would then be a custom field on the user) or really a page-specific field? Anyways - as this is an answer, not a comment, it might give enough hints to try out and come closer to a solution.
answered Jan 3 at 8:14


Olaf KockOlaf Kock
37.3k74677
37.3k74677
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
add a comment |
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
hi Olaf, thanks for the quick reply, this is so helpful and olaf is right, I'm using wrong className and classPK. I had misunderstanding/unclear in using the attributes for this api. After made a changes to the api. Now it works fine and it does return the value. However, it only took the default value from the page-custom field. But not the value assign for that particular pages.
– A.Shah
Jan 3 at 15:31
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
Issue solved, I change the classPK value to themeDisplay.getPlid() :)
– A.Shah
Jan 7 at 6:39
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015903%2fliferay-7-retrieved-custom-field-value-using-javascript-api-jsonws-return-java%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Hi, do you have a stracktrace? This might help here.
– Andre Albert
Jan 3 at 8:03
please provide a stack trace, my experience with NPE´s and accessing Expandos is that the corresponding ExpandoColumn instance does not exist. ... or ... how did you get the classname ? as Olaf already has recognized .. the Class Page does not exist , therefore the access towards the ExpandoTable/ ExpandoRow will crash.. if you created the expando in the UI, the column, table and row will already exist.. So it may be only the wrong classname ... have a try and give feedback ..
– André
Jan 3 at 11:53