English 中文(简体)
How to use the Liferay "comments framework"?
原标题:

I m trying to use the built-in comments functionality within a JSF 2.0/ICEfaces portlet application (the application is running fine already). Unfortunately there seems to be no detailed documentation about the comments stuff yet so I hope somebody can give me some pointers how to create and retrieve comments that should be linked to a single integer.

To be more clear... I d like to (re-)use the "Page Comments" portlet s functionality within my custom portlet, but only the underlying service, not the UI part.

I already figured out that MBMessageServiceUtil.addDiscussionMessage(...) is used by that portlet through the EditDiscussionAction class. Unfortunately I have no clue what I should provide as parameter values. Could anybody shed some light on this? The javadoc is kind of... short ;-)

public static MBMessage addDiscussionMessage(long groupId,
                                             String className,
                                             long classPK,
                                             String permissionClassName,
                                             long permissionClassPK,
                                             long threadId,
                                             long parentMessageId,
                                             String subject,
                                             String body,
                                             ServiceContext serviceContext)

Cheers, tamm0r

问题回答

This is going to be long but here is the play by play.

  1. In your view, you re going to grab the MBMessageDisplay object.
    MBMessageDisplay messageDisplay =
       MBMessageLocalServiceUtil.getDiscussionMessageDisplay(
          themeDisplay.getUserId(), themeDisplay.getScopeGroupId(),
          MyModelEntry.class.getName(), myModelEntry.getTasksEntryId(),
          WorkflowConstants.STATUS_APPROVED);
  1. MBMessageDisplay will contain vital data like the threadId and parentMessageId, so be sure to post this data as well.

  2. In the "Controller" where you make the call mentioned in your post grab the ServiceContext from the request like so:

    ServiceContext serviceContext = ServiceContextFactory.getInstance(
       MyModelEntry.class.getName(), actionRequest);
    
  3. So you now have all the parameters required.

    long groupId - Group (Organization or Community usually) you re writing the comment in.
    String className - MyModelEntry.class.getName()
    long classPK - MyModelEntry s Primary Key or ID
    String permissionClassName - Model where the permission checker should look, typically the same as className
    long permissionClassPK - Its Primary Key or Id
    long threadId - From MBMessageDisplay.
    long parentMessageId - From MBMessageDisplay.
    String subject - the subject
    String body - the body
    ServiceContext serviceContext - from Request in step 3.
    

Hope this helps!





相关问题
VS 10 mangles html comments?

Using the latest VS 10 we created html markup, then commented it with html comments. The file on disk is not mangled, but when it renders, it renders the html comment tags, then removes some of the ...

Comments & OpenSource software [closed]

This may sound like a foolish question or an observation, but i have seen that most of the times when one tries to look at the opensource code, there are no comments or just one or two lines at the ...

Including commented Class declaration in implementation file

Everyone knows the advantages of a more readable code. So in order to make my code more readable what i do normally is include the commented class declaration in the implementation file of that class....

pair programming with comments [closed]

Over the years, I ve discovered that green-programmers tend to read the comments rather than the code to debug issues. Does having one person document the other person s code (and vice-versa) with ...

Commenting JavaScript functions á la Python Docstrings

It is valid JavaScript to write something like this: function example(x) { "Here is a short doc what I do."; // code of the function } The string actually does nothing. Is there any reason, ...

热门标签