Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
kujah legend
Help with hooks please.
November 22, 2011 7:27 AM
Answer

kujah legend

Rank: New Member

Posts: 6

Join Date: November 14, 2011

Recent Posts

Hello all,

I have been trying to modify the message boards portlet by giving it a thread expiry function via Hooks.

My liferay is connected to an Oracle (10g) database and I have modified the MBThread table to add an extra column (expiryDate). The portal definitely takes data from the oracle database.

I am struggling to discover the way to actually write the date values back into my new column and hoping someone could provide some guidance.

I've been looking around the forums and trying various things but as I am new to Liferay and portlet development my progress is very little.

When looking through the liferay source, there seems to be numerous classes (LocalService, Service, Persistance, etc etc) which become involved. However, I am struggling to follow the flow of the data (how we get from pressing the "publish" button on the thread to writing the values into the database).

Most examples i've come across seem to be of extensions (which is why i'm wondering if trying to use a hook is the correct method). And there doesn't seem to be any comprehensive tutorial on hooks when it comes to stuff involving database modifications.

All help is appreciated!

Thanks!

P.S I am using Liferay 6.0.6, Tomcat6, Oracle 10g
Ranvijay Singh
RE: Help with hooks please.
November 22, 2011 8:49 AM
Answer

Ranvijay Singh

Rank: New Member

Posts: 16

Join Date: June 2, 2011

Recent Posts

Hi,
Have you check this article for interaction with database. As modifying a table,requires re-generating service classes by using service builder xml file. Also check expando concept for extending liferay table.
Thanks,
Nagendra Kumar Busam
RE: Help with hooks please.
November 22, 2011 10:00 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 638

Join Date: July 7, 2009

Recent Posts

Please check the attachment & let us know about your response
Attachment

Attachments: 2011-11-22_2327.png (41.3k)
kujah legend
RE: Help with hooks please.
November 22, 2011 10:36 AM
Answer

kujah legend

Rank: New Member

Posts: 6

Join Date: November 14, 2011

Recent Posts

Hello,

Thanks both for response.

@Ranvijay: Yeah i've been taking a look at various examples such as the ones you have linked to me. However I get confused due to my lack of experience. I have been using service builder to generate template classes and then writing some custom code but when I get to the part of editing the JSP files, I can't see how the services/persistence and other classes are used to write back to the database. Perhaps I am overlooking something here as i'm not used to working with Liferay/Portlets?

@Nagendra: Yes exactly so. I have managed to make a expiry form appear on the "new message" page by using the following:

 1    <aui:field-wrapper>
 2        <aui:input model="<%=MBThread.class %>" bean="<%=thread%>"label="Expiration Date" name="expirationDate" value="<%= expiryDate %>" />
 3       
 4          <div>
 5            <liferay-ui:input-date
 6              dayParam="dateDay"
 7              dayValue="<%= expiryDate.get(Calendar.DATE) %>"
 8              disabled="<%= false %>"
 9              firstDayOfWeek="<%= expiryDate.getFirstDayOfWeek() - 1 %>"
10              monthParam="dateMonth"
11              monthValue="<%= expiryDate.get(Calendar.MONTH) + 6 %>"
12              yearParam="dateYear"
13              yearValue="<%= expiryDate.get(Calendar.YEAR) %>"
14              yearRangeStart="<%= expiryDate.get(Calendar.YEAR) %>"
15              yearRangeEnd="<%= expiryDate.get(Calendar.YEAR) + 100 %>"
16            />
17
18        &nbsp;
19
20            <liferay-ui:input-time
21              amPmParam="dateAmPm"
22              amPmValue="<%= expiryDate.get(Calendar.AM_PM) %>"
23              hourParam="dateHour"
24              hourValue="<%= expiryDate.get(Calendar.HOUR) %>"
25              minuteParam="dateMinute"
26              minuteValue="<%= expiryDate.get(Calendar.MINUTE) %>"
27              minuteInterval="<%= 1 %>"
28            />
29
30          </div>
31    </aui:field-wrapper>


I have also prepared the database table (MBThread) with a new column (expiryDate) to receive the data.
I am stuck in everything that happens in between; How do I extract the data from that new message page and stick it into the database?
Attachment

Attachments: Example.png (72.8k)
Jeffrey Paul Handa
RE: Help with hooks please.
November 22, 2011 11:16 AM
Answer

Jeffrey Paul Handa

LIFERAY STAFF

Rank: Expert

Posts: 474

Join Date: December 1, 2008

Recent Posts

Hi Kujah,

It's never recommended to modify the database structure of any of Liferay's database tables. This is going to lead to upgrade problems in the future. It is preferred to use a Custom Field (expando) or create a new service with a one-to-one relationship to the original service.

One approach that I would consider to solve your problem would be:

1. Create a JSP Hook to add the form field -- Just like you have done.

2. Create an EXT Plugin to customize the Struts Action that is currently processing the form submission. The struts action is what's extracting the form data and calling the service layer. In your custom struts action, extend the original action and override the run method to call the service layer and also update the custom field (expando).

Let me know if you need help to determine the proper struts action to override.

By the way, I've recommended this approach because you mentioned that you're on 6.0 CE. If you were on the latest 6.0 EE or 6.1 CE you could use a Hook for both the JSP and overriding the struts action.
Nagendra Kumar Busam
RE: Help with hooks please.
November 22, 2011 12:18 PM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 638

Join Date: July 7, 2009

Recent Posts

I totally agree with you Jeff.

One thing i want to know i was looking into LR 6.1 CE B4

I had a look into MD Messages related code. Actually controller in this case was EditMessageAction extends com.liferay.portal.struts.PortletAction (this in turn extends org.apache.struts.action.Action )

After looking into Overriding and adding struts actions from hook plugins If my understanding is correct i need to go with second approach where my custom class (struts-action-impl) extends BaseStrutsPortletAction - second approach in the blog

Thanks,
- Nagendra Kumar
kujah legend
RE: Help with hooks please.
November 22, 2011 1:17 PM
Answer

kujah legend

Rank: New Member

Posts: 6

Join Date: November 14, 2011

Recent Posts

Hi Both,

@Jeffrey: Ok this sounds very similar to the guide Ranvijay mentioned so I will study this again to see if I can decipher it some more. What's clear now is that this feature must be implemented via an extension rather than a hook. You are correct in noticing the version of Liferay I must use. It will most likely be tomorrow before I come back with more questions since I have finished work for the day emoticon

@Nagendra: I am limited to using Liferay 6.0.6 so unfortunately the new action hook features are not available to me emoticon

Thank you both for the help so far! Please keep an eye on this thread as i'm bound to come back with more questions ;)

Cheers!
kujah legend
RE: Help with hooks please.
November 24, 2011 6:28 AM
Answer

kujah legend

Rank: New Member

Posts: 6

Join Date: November 14, 2011

Recent Posts

Hi again,

Ok so I have been following the "Extend Liferay Tables" example mentioned above and I think i'm on the right track.

I created a new table with the service builder to hold the expirydate data and the table holds threadID and messageID so it knows what the expiry date is for.
I then implemented extra code in my MBMessageExtLocalServiceImpl and MBMessageExtLocalServiceUtil classes and also overrid the EditMessageAction class with my own modified version of the updateMessage() method. I then modified the struts-config-ext.xml file to tell liferay where the new action class is.

Deployed this, and tried to post a thread but in my console I keep getting the following two messages (And pressing the "publish" button just returns me to the top of the page):

14:17:27,069 INFO [PortalImpl:3841]
14:17:57,085 INFO [PortalImpl:3829] Current URL /poller/send generates exception: null

It's not a very informative message but just wondering if you have any guesses to what this problem could be?

Thanks

P.S I haven't included any code because there are multiple classes I modified. But let me know if you want to take a look emoticon
kujah legend
RE: Help with hooks please.
November 25, 2011 7:49 AM
Answer

kujah legend

Rank: New Member

Posts: 6

Join Date: November 14, 2011

Recent Posts

Anyone know what the problem could be?
Nagendra Kumar Busam
RE: Help with hooks please.
November 30, 2011 7:12 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 638

Join Date: July 7, 2009

Recent Posts

Can you attach the code if you can