留言板
How can I store Web Content with JAVA ?
Rüdiger Kowalski,修改在12 年前。
How can I store Web Content with JAVA ?
New Member 帖子: 22 加入日期: 11-8-16 最近的帖子
Hi, I want to read, change and update web content out of a JSF portlet programmatically.
Reading works fine:
static public String leseWebContent(final String title) throws PortalException, SystemException
{
String content = "";
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
content = jad.getContent();
return content;
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
return content;
}
}
Changing by using a PrimeFaces component works fine:
<prime:editor id="edit" value="#{hilfstextController.webContent}" height="320" width="480" />
(Getter method of webContent calls method "leseWebContent()")
Updating does not work:
static public void schreibeWebContent(final String title, final String webContent) throws PortalException, SystemException
{
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
jad.setContent(webContent);
? ? ?
JournalArticleLocalServiceUtil.updateJournalArticle(ja);
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
}
}
JounalArticleDisplay object contains the changed content. The method "JournalArticleLocalServiceUtil.updateJournalArticle()" however expects a JournalArticle object as parameter. Does anybody know a solution for this problem?
So I'm a JAVA newbie and I'm happy about every answer.
Best regards Rüdiger
Reading works fine:
static public String leseWebContent(final String title) throws PortalException, SystemException
{
String content = "";
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
content = jad.getContent();
return content;
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
return content;
}
}
Changing by using a PrimeFaces component works fine:
<prime:editor id="edit" value="#{hilfstextController.webContent}" height="320" width="480" />
(Getter method of webContent calls method "leseWebContent()")
Updating does not work:
static public void schreibeWebContent(final String title, final String webContent) throws PortalException, SystemException
{
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final long groupId = td.getScopeGroupId();
final String languageKey = fc.getExternalContext().getRequestLocale().toString();
try
{
final JournalArticle ja = JournalArticleLocalServiceUtil.getArticleByUrlTitle(groupId, title);
final JournalArticleDisplay jad = JournalContentUtil.getDisplay(ja.getGroupId(), ja.getArticleId(), ja.getTemplateId(), languageKey, td);
jad.setContent(webContent);
? ? ?
JournalArticleLocalServiceUtil.updateJournalArticle(ja);
}
catch (final Exception ex)
{
System.out.println(ex.getMessage());
}
}
JounalArticleDisplay object contains the changed content. The method "JournalArticleLocalServiceUtil.updateJournalArticle()" however expects a JournalArticle object as parameter. Does anybody know a solution for this problem?
So I'm a JAVA newbie and I'm happy about every answer.
Best regards Rüdiger
Nagendra Kumar Busam,修改在12 年前。
RE: How can I store Web Content with JAVA ?
Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
Hi Rudiger,
I never worked on PrimeFaces BUT i will give my idea how you can change the same.
Anyway you are getting article by groupId & urlTitle.
Here
>> content is latest content you are getting from form
>> articleId is articleId of article you got using groupId & urlTitle
>> version you may need to increment according to current version of the article - check default JournalArticle impl for ref.
Please let us know if this works for you
Thanks,
- Nagendra Kumar
I never worked on PrimeFaces BUT i will give my idea how you can change the same.
Anyway you are getting article by groupId & urlTitle.
JournalArticleLocalServiceUtil.updateContent(groupId, articleId, version, content)
Here
>> content is latest content you are getting from form
>> articleId is articleId of article you got using groupId & urlTitle
>> version you may need to increment according to current version of the article - check default JournalArticle impl for ref.
Please let us know if this works for you
Thanks,
- Nagendra Kumar
Rüdiger Kowalski,修改在12 年前。
RE: How can I store Web Content with JAVA ?
New Member 帖子: 22 加入日期: 11-8-16 最近的帖子
Hi Nagendra,
first of all thanks for your quick reply. I acted on your suggestion and it works fine !
But now I have the next problem. In case of missing web content, I want to create one out of my form (JSF portlet). My idea was to use JournalArticleLocalServiceUtil.addJournalArticle( article ), but I don't know how to create a article.
Maybe you can help me in this issue too?
Thanks Rüdiger
first of all thanks for your quick reply. I acted on your suggestion and it works fine !
But now I have the next problem. In case of missing web content, I want to create one out of my form (JSF portlet). My idea was to use JournalArticleLocalServiceUtil.addJournalArticle( article ), but I don't know how to create a article.
Maybe you can help me in this issue too?
Thanks Rüdiger
Nagendra Kumar Busam,修改在12 年前。
RE: How can I store Web Content with JAVA ?
Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
I didn't get what you really mean by missing web content. Can you be elaborate a bit more on the same.
Rüdiger Kowalski,修改在12 年前。
RE: How can I store Web Content with JAVA ?
New Member 帖子: 22 加入日期: 11-8-16 最近的帖子Nagendra Kumar Busam:
I didn't get what you really mean by missing web content. Can you be elaborate a bit more on the same.
Hi Nagendra,
yes, of course. I'm developing a portlet with several input fields. Beside every field there is a button, which will show a help dialog with field depending information. This help information should be placed in a web content. So when the button is clicked for the first time and there is no matching web content, I want to create and store one.
Thanks Rüdiger
Rüdiger Kowalski,修改在12 年前。
RE: How can I store Web Content with JAVA ?
New Member 帖子: 22 加入日期: 11-8-16 最近的帖子
I've got it !
Thanks to all for your help !!!
final FacesContext fc = FacesContext.getCurrentInstance();
final ThemeDisplay td = (ThemeDisplay) fc.getExternalContext().getRequestMap().get(WebKeys.THEME_DISPLAY);
final ServiceContext sc = new ServiceContext();
sc.setAddCommunityPermissions(true);
sc.setAddGuestPermissions(true);
sc.setScopeGroupId(td.getScopeGroupId());
sc.setCompanyId(td.getCompanyId());
sc.setUserId(td.getUserId());
JournalArticleLocalServiceUtil.addArticle(td.getUserId(), td.getScopeGroupId(), "", true, 1.0, title, "", webContent,
"general", "", "", 11, 24, 2011, 9, 0, 0, 0, 0, 0, 0, true, 0, 0, 0, 0, 0, true, true, false, "", null,
null, title.toLowerCase(), sc);
Thanks to all for your help !!!
Nagendra Kumar Busam,修改在12 年前。
RE: How can I store Web Content with JAVA ?
Liferay Master 帖子: 678 加入日期: 09-7-7 最近的帖子
Good you got it working.
I have one question why can't you just use Language.properties file to keep you help text for your custom portlet
I have one question why can't you just use Language.properties file to keep you help text for your custom portlet
Rüdiger Kowalski,修改在12 年前。
RE: How can I store Web Content with JAVA ?
New Member 帖子: 22 加入日期: 11-8-16 最近的帖子
Hi Nagendra,
our customer wants to create his own help information with rich text editing features. Therefore we decided to use PrimeFaces <p:editor> component for manual input and Liferay web content for storing.
As I already told you, I'm very new in Java developing and in Liferay (nearly 6 months) and I don't know how to use language properties file. Is there any documentation about this, respectively where can I find it?
Thanks Rüdiger
our customer wants to create his own help information with rich text editing features. Therefore we decided to use PrimeFaces <p:editor> component for manual input and Liferay web content for storing.
As I already told you, I'm very new in Java developing and in Liferay (nearly 6 months) and I don't know how to use language properties file. Is there any documentation about this, respectively where can I find it?
Thanks Rüdiger
Oliver Bayer,修改在12 年前。
RE: How can I store Web Content with JAVA ?
Liferay Master 帖子: 894 加入日期: 09-2-18 最近的帖子
Hi Rüdiger,
please refer to this WIKI. If you have any other questions feel free to ask again.
Greets Oli
please refer to this WIKI. If you have any other questions feel free to ask again.
Greets Oli
Anil Sunkari,修改在12 年前。
RE: How can I store Web Content with JAVA ?
Expert 帖子: 427 加入日期: 09-8-12 最近的帖子
Hi Rüdiger,
I'm not sure but still i'm giving you my idea about your query.You can try this
JournalArticle journalArticle = new JournalArticleImpl();
journalArticle.setArticleId();
""
""
etc..
JournalArticleLocalServiceUtil.addJournalArticle(journalArticle);
Thanks,
Anil Sunkari
Rüdiger Kowalski:
Hi Nagendra,
first of all thanks for your quick reply. I acted on your suggestion and it works fine !
But now I have the next problem. In case of missing web content, I want to create one out of my form (JSF portlet). My idea was to use JournalArticleLocalServiceUtil.addJournalArticle( article ), but I don't know how to create a article.
Maybe you can help me in this issue too?
Thanks Rüdiger
I'm not sure but still i'm giving you my idea about your query.You can try this
JournalArticle journalArticle = new JournalArticleImpl();
journalArticle.setArticleId();
""
""
etc..
JournalArticleLocalServiceUtil.addJournalArticle(journalArticle);
Thanks,
Anil Sunkari