Click Event in a Carousel

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
billcross
Posts: 30
Joined: Thu Apr 07, 2016 3:01 am

Click Event in a Carousel

Post by billcross »

I created a copy of xDemoCarouselDesign and I am using it to display various types of product information. I would like to open a detail page when the user clicks a particular item but I am unable to access the click event for the carousel. Is there a way to do this ?
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Click Event in a Carousel

Post by Stewart Marshall »

There are a couple of ways of handling this situation.

The first technique, and best practice, is to create a shared component instance that is used by the reusable parts in the carousel. The parts invoke a "DoSomething" method in the shared object and it can fire an event that other reusable parts can respond to. This is an excellent technique for managing the interaction of multiple reusable parts used to construct complex UIs.

The alternative is that a user defined event is fired and detected in the reusable part containing the Carousel itself.

http://vlforum.lansa.com.au/viewtopic.php?f=3&t=29&p=52 describes a very similar scenario.
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
billcross
Posts: 30
Joined: Thu Apr 07, 2016 3:01 am

Re: Click Event in a Carousel

Post by billcross »

I tried using the method described in the topic but had an issue getting it to work.

I used a define statement like the one below to access the current carousel

Define_Com Class(#HLWEBCAR) Name(#CurrentCarousel) Reference(*Dynamic)

but when I tried to assign it to the current one #CurrentCarousel <= #HomeCarousel.Currentitem *As #HLWEBCAR at run time it fails.

Is this because the definition for the HomeCarousel looks like this

Define_Com Class(#PRIM_CARO<#HLWEBCAR>) Name(#HomeCarousel)
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Click Event in a Carousel

Post by Stewart Marshall »

I assume the error is something like "Failure while casting object of type PRIM_CARO.CarouselItem to type HLWEBCAR"

The assignment should read

#CurrentCarousel <= #HomeCarousel.Currentitem.Design *As #HLWEBCAR

If you only refer to CurrentItem, you're referring to the underlying list item in the carousel. By attaching .Design on the end, the reference is the reusable part instance.
Last edited by Stewart Marshall on Wed Jul 06, 2016 9:00 am, edited 2 times in total.
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
billcross
Posts: 30
Joined: Thu Apr 07, 2016 3:01 am

Re: Click Event in a Carousel

Post by billcross »

I had tried that and got the errors below

Feature name Part is not a member of component type PRIM_CARO.CarouselItem.

#HomeCarousel.Currentitem.PART *As #HLWEBCAR is not a component.
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Click Event in a Carousel

Post by Stewart Marshall »

It should have been .Design and NOT .Part

My mistake. Sorry for the confusion.

I've updated my previous comment
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Click Event in a Carousel

Post by Stewart Marshall »

The ItemClick and ItemDoubleClick events will be available in SP1
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
billcross
Posts: 30
Joined: Thu Apr 07, 2016 3:01 am

Re: Click Event in a Carousel

Post by billcross »

This now works but I'm having an issue properly detecting the transition from one item of the carousel to the next. I thought ItemGotFocus would be the event to use but it does not seem to fire when the carousel item is changed. What event should be used ?
User avatar
Stewart Marshall
Posts: 417
Joined: Thu Nov 05, 2015 5:25 pm

Re: Click Event in a Carousel

Post by Stewart Marshall »

It seems that you've discovered a bug. ItemGotFocus isn't firing correctly for Carousel in the GA.

This will be resolved in SP1.

In the meantime, a simple shared object will do the job for you. In the attached export, I've modified the sample to include a third object (xDemoWebCarouselHandler). This is defined in both the design and the carousel as Scope(*Application) meaning that there can only ever be one instance of it.

The design executes a method in the Handler, which in turn fires an event. This is detected by the Carousel which in this case shows the ID, but could of course do whatever you want.

Using shared objects to simplify communications between multiple parts is an extremely powerful feature and is very much worth getting to grips with.

regards
Attachments
Carousel.zip
(11.22 KiB) Downloaded 1667 times
Stewart Marshall

Independent IT Consultant
www.marshallfloyd.com.au
Post Reply