You are on page 1of 6

Web Dynpro for ABAP Thoughts on MVC and WD4A Observations

Matt Harding Business Card


Co pany! Aurora "nergy Posted on May# $$% $&&' (&!)* AM in ABAP% Web Dynpro

*u!scri! e +rint +ermalin ,

+ntrodu,tion
I'm a long time ABAPer (amongst other things) who also got involved in Web Dynpro for JA A early on! "here were a few interesting feat#res and stability iss#es in the past$ b#t the whole approa%h for WD&J was pretty straightforward and aligned to ' ( pretty well!
However, when it came to transferring my understanding of WD4J to WD4A, I was a little confused at first as the Window Controller and assistance class threw me. I had previously developed uite a few smaller WD4A apps, however, recently I had the chance to developer a larger scale development which re uired component development and leveraging all the features of We! Dynpro and came away with a few thoughts around how "#C is esta!lished and potentially a pattern for !uilding WD4A applications.

-irst for the observations!

$he Assistance Class seems to !e a much !etter glo!al data storage location than the conte%t or local varia!les withina controller &assuming they don't need to !e mapped through a conte%t(. )ot to mention, the performance is supposedly much !etter &according to *A+ help(

$he Window Controller seems to own things much more than the Component Controller ma,ing me wonder whether the Component Controller could -ust !e wrapped into the Window Controller. i.e. $he Component Controller can't navigate. !ut it can tell the window controller to navigate. All the Component Controller seems good for is interfacing and Conte%t Definitions.

It's funny how the Window in!ound plug hides its parameters &that would !e passed via the /01( within the code section where on all other plugs on views, it's there in the definition screen &that one hurt me one day(. All the tutorials out there have views navigating to other views which from an "#C pattern seems strange unless you want to throw the #iew Controller in as a real controller &I don't typically( 2$o get around this, the Component Controller can tell the Window Controller to fire plugs provided you include it as a reference in the Component Controller.

It's ,ind of annoying that if you want to reuse one interfacing component in another component multiple times, that the node structure can't really !e more than 3 deep as otherwise you need to map to new nodes within the Component Controller. i.e. $he underlying code ma,es the )ode )ame specific, henceif you had )4D53 and )4D56 and mapped an interface node to each )4D5 !ut the node you were mapping had child nodes. you would need to map these separately &or something li,e this(.

WDD4I)I$ of the component controller is correctly called prior to the Window D57A/1$ plug, !ut this means if you have parameters passed within a /01. you cannot initialise much in WDD4I)I$. &solution is to call an initialise method from the default plug on the Component Controller(

.o /hat0s this a11 about MVC2


Well my understanding of "#C is that the "odel is separate from the #iew, and the controller controls what data is retrieved from the "odel plus what view to display and what model data to pass to the #iew. *o first I was thrown !y the fact that WDDoInit is called without any application conte%t information e%cept sy8 uname that's running the application &as per my last point a!ove(. *o this got me to thin,ing97or a component that is not going to !e interfacing to another component, the Window Controller is actually more powerful than the Component Controller. )ow !ecause I have the WD4J !ac,ground,I'm going to assume that I've missed the point somewhere, and I'm still going to focus on the Component Controller !eing my main controller. /nfortunately, from an "#C perspective, the controller is more than what the Component Controller can do as I cannot navigate directly from it to a different #iew. I could fire an event and asynchronously tell a view to fire a plug &which is not a good idea(. pass parameters !ac, from methods called !y the #iew &also not great( or I could call a method on the Window Controller to fire a plug.

If I do the latter$ I wo#ld %onsider the (omponent (ontroller and Window (ontroller as one (A perfe%t mat%h made in Waldorf)! )o what does this loo* li*e+ WDD,I-I" of (omponent (ontroller . Initialises anything global loo*ing that re/#ires initialisation! )tart pl#g of Windows (ontroller . "his %alls method on the (omponent (ontroller to initialise the model data and navigate appropriately! All navigation gets initiated by the (omponent (ontroller by %alling an appropriately defined Window (ontroller whi%h fires its own o#tbo#nd pl#g to %hange views! -ote . "here will be e0%eptions to this espe%ially if yo# 1#st want a basi% navigation from one view to another li*e in a tab %ontrol or something b#t in this s%enario$ I wo#ld %onsider the iew (ontroller as a mini %ontroller /#ite %apable of performing these types of tas*s! 'ain %onte0t is all stored in the (omponent (ontroller! "he Window (ontroller 1#st handles navigation and entry points to the appli%ation! Anyway$ thats the gist of it! Im really hoping for someone from )AP ("homas perhaps 2 hint hint 2 (ongrat#lations on the birth of 3yan "homas J#ng again) to %ond#%t a 4best pra%ti%e patterns5 style presentation %overing the best 4typi%al5 approa%h to things li*e larger WD&A appli%ations$ b#t this is my short version of it for now that Id love to hear from others how they maintain the ' ( pattern within WD&A! "han*s all who got this far and hopef#lly see yo# at )D- Day in Brisbane ne0t month or at "e%h 6d Phoeni0! 'att
Matt Harding is Manager of Architecture at Aurora Energy who's passion is to design simple, intuitive and visually appealing solutions addressing functionality gaps. Add to: del.icio.us ; Digg ; 0eddit

A + off the ar34 +s there a better /ay4 -eedba,3 is /e1,o e as +5 the sa3e of 1earning6 Co ent on this /eb1og *howing messages 3 through < of <.

happy to be ,o p1ete1y /rong for

$itles 4nly "ultiple /sage

"ain $opics

4ldest 7irst

6==<8=>8?= =?:6?:66 7lorian @andlinger Ausiness Card B0eplyC Hello, while wor,ing on a pro!lem with We!Dynpro for AAA+ i stum!led over your !log entry &https:DDwww.sdn.sap.comDir-DscnDwe!logsE!logFDpu!DwlgD344=>(. I was luc,y, !ecause you e%perienced the same pro!lem li,e me.

Guote: It's ,ind of annoying that if you want to reuse one interfacing component in another component multiple times, that the node structure can't really !e more than 3 deep as otherwise you need to map to new nodes within the Component Controller. i.e. $he underlying code ma,es the )ode )ame specific, henceif you had )4D53 and )4D56 and mapped an interface node to each )4D5 !ut the node you were mapping had child nodes. you would need to map these separately &or something li,e this(. We have to use a we! dynpro component multiple times in our target we! dynpro component. $he Conte%t of the muliple used component is hierarchically structured li,e this: C4)$5H$ ; ;8I)4D5J3 ;; ; ;8I*/A)4D5J3 ;;; ; ; ;8I*/A*/AJ)4D5J3 ;;;; ; ; ; ;8IA$$0IA/$5J3J3J3 ; ; ; ;8IA$$0IA/$5J3J3J6 ; ; ;8I*/A*/AJ)4D5J6 ; ; ;8I*/A*/AJ)4D5J? ; ; ;8IA$$0IA/$5J3J3 ; ; ;8IA$$0IA/$5J3J6 ; ;8IA$$0IA/$5J3 ; ;8IA$$0IA/$5J6 ; ;8IA$$0IA/$5J?

It is not possi!le to map the conte%t node &)4D5J3( of !oth used components in the target component. 0enaming is only allowed for the root node. Aut there are still naming conflicts with the child nodes. Also mapping each child node seperatly and renaming it doesnKt wor,, !ecause We!Dynpro seems to have a !ug in this case. When changing the lead selection of the mapped )4D5J3, it does not affect the data stored in the su!nodes. *o in the su!nodes there is still the data !elonging to the old lead selection. Do you ,now or have you found a solution for this pro!lemE Is it really not possi!le to use the same we! dynpro component multiple times and mapping the hierarchically structed conte%tE

I also opened a thread in sdn for it: http:DDforums.sdn.sap.comDthread.-spaEthreadIDF3466L44MtstartF?=

"ultiple /sage 6==<8=>8?= =?:N4:6< "att Harding Ausiness Card B0eplyC Hi 7lorian,

/nfortunately, I didnKt do e%tensive investigation to try resolve this though it was o!vious the meta data used meant thereKs no easy solution. I -ust went with a flat structure which was annoying !ut it did the -o!. "ay!e name your flat structure in a hierarchical way to at least ma,e it reada!leE Oood luc,, "att

1in, to 7loor +lan "anager Developers Ouide 6==<8=N86> 6?:3=:46 "att Harding Ausiness Card B0eplyC Just thought IKd add the lin, to the 7+" guide for completeness: https:DDwww.sdn.sap.comDir-DscnDgoDportalDprtrootDdocsDli!raryDuuidD<=f?cfd684Pd=86!3=8!?a!8ea!f?4N6ccN=

$han,s John and $horsten 6==<8=N86> =6:?>:?? "att Harding Ausiness Card B0eplyC It loo,s li,e I may not !e too far off the mar, !ased on everyoneKs comments and itKs great to get other peopleKs approaches &which are all fairly similar(.

)ote 8 IKve -ust remem!ered the 7+" document that was pu!lished not long ago &which doesnKt come up in the search( so IKll give that a read and see if that changes my thin,ing. "att

*eparation of Concerns 6==<8=N86P 36:3<:3> $horsten 7ranQ Ausiness Card B0eplyC Hi "att, $han,s for sharing your insights. ItKs nice to see that others, too, are still trying to get the !est grip on how and where to cut when using We! Dynpro. :( $his is what I try to do: R "a,e the WD layer thin, it should !e a pure /I layer. Ausiness o!-ects and !usiness logic should not !e implemented in a WD component, they should only !e RusedR there. R 5ncapsulate the model and the technical details of accessing at least it in a faceless component within the same WD development component &WD4J(. R If reuse of the faceless component is the least !it li,ely or the application is large enough to -ustify further modulariQation, give it a WD development component of its own. R Design the component interface &especially the conte%t( of the faceless model component with the needs of the consuming component and view controllers in mind. Avoid showing details of the technicalities of how the model is accessed &05G/5*$J!la!a!la nodes(. R 7ollow the "#C pattern. @eep views clear of process and !usiness logic, ,eep the model component clear of /I ,nowledge, and have the main component controller !ro,er !etween them or Spull the stringsS. R Assume that views will !e used in different screen layouts. Oive them clear interfaces and ma,e them as agnostic of their environment as possi!le. R @eep the window controllers as lean as possi!le. $hey are !etween the component controller and the view

controller and can often remain empty. Aut if ,nowledge a!out navigation and different layouts must !e programmed, put that into the window controller.

Cheers, $horsten

$here are many ways to adopt the "#C pattern ... 6==<8=N86N 3<:N=:4? John +atterson Ausiness Card B0eplyC Hi "att, I too have !een loo,ing for a pattern for !usiness logic accessing when developing larger we!dynpro applications, loo,ing at *A+ applications for guidance my findings are

8 the lean sales order application SlordJmaintainS uses a faceless component which facades the model logic &C1J140DJ"4D51JAD"I)(. 8 the travel e%pense application S7I$5J5H+5)*5*S 8 the 7+" controlls component usage and application parameters allowing data to !e shared !etween components, on the whole the assistance class is used for sharing class data and manipulating the screen ui elements. After reading the 7+" Coo,!oo, it loo,s li,e the *hared Data Component is a standard approach !ut does that mean that we are to create faceless components for separation of concerns. cheers J*+

$here are many ways to adopt the "#C pattern ... 6==<8=N86? =N:=4:6< *ergio 7errari Ausiness Card B0eplyC Hi "att, I try to adopt the "#C pattern as much as possi!le too. I had the opportunity to develop some relevant WDA applications and at the !egin I tried to find the TsuggestedU "#C pattern. I often say that *A+ !uild $441s &e.g. WDA( and A++1ICA$I4)*&e.g. 5CC, *0"( and I try to develop custom applications in the same way as *A+ does. Aefore defining Smy wayS, I studied a lot of standard WDAs !ut to !e honest until *A+ 5CC 5h+? I found nothing I li,ed so much. $hey were !asically AIO WDC &several views and few component reutiliQation( with AIO Component Controller &large Component Controller methods and few "odel Classes(. In these days a colleague is -ust implementing *A+ 5CC 5h+4 and I'm loo,ing forward to studying the new WDAs. I'll also soon have the opportunity to login into a *A+ *0" >.= that is WDA !ased. What I would add to your considerations is that the We! Dynpro WiQard is really very very powerful !ut unfortunately it implements everything in the We! Dynpro Component itself &e.g new methods in custom controllers, new conte%t node, new statements in local methods and so on( and pro!a!ly it's not so "#C oriented. $he most important consideration is indeed related to 7+" 2 7loorplan "anager. It's the new and strategic way to implement WDA. At the !eginning it's a !it comple% !ut it add new options in terms of fle%i!ility, modulariQation and configuration. Vou should try 7+" &availa!le since )W >.=3( and even if your considerations will !e still important, you should reallocate them to the new a!straction layer.

+ersonally, within the large WDA pro-ects IKm conducting, I instructed my team to implement as less code as possi!le within WDC. Instead we define and implement the "4D51s as classic AAA+ 44 Classes &*564( to represent the Ausiness 4!-ects &Customer, Invoice,9( and we save into WD Assistance Class the instances of the "4D51s &AAA+ 44 Classes(. We specialiQe the "4D51s via new Classes to add some functions dedicated to We! Dynpro &e.g. conte%t management( or we implement specific methods into the assistance class &also for the multi8language feature(. *o all the modules of the WDC &and even the su!components via shared Assistance Classes ( access the "4D51s via an attri!ute of the assistance class &e.g. wdJassist8Icustomer8IgetJid& ((. In my team, we accept to lose some interesting features of the WD WiQard to stay more aligned to "#C or to say !etter we use the wiQard as a starting point and then we cutMpaste pieces of code auto generated code in the right module of "4D51. *ome of the main !enefits are: the possi!ility to use powerful AAA+ tools li,e &*earchD0eplace(, Code Inspector, 5asy $est from *564 of each method without going trough the whole application, where8used8list that within a WDC wor, with some restrictions.

*ergio

$here are many ways to adopt the "#C pattern ... 6==<8=N86? 3P:3P:N< "att Harding Ausiness Card B0eplyC $han,s for the detail *ergio.

7+" is availa!le to me and in all honestly, is something I havenKt loo,ed into too greatly. "y understanding of 7+" is that itKs uite a specified /I style &which is standard(, !ut my re uirements have !een uite specialised. $hat said, I need to research 7+" more and get my hands dirty with a demo to understand it !etter. /nfortunately, help.sap.com is a little wordy for learning this &more pictures please( and no one has really produced a Show to from scratchS guide to accelerate my learning !ut hopefully I can pic, this up. And in terms of 44 classes, youKre tal,ing my language, and thatKs how IKve done it too. $hough I do admit to letting my 44 classes return O/I structures sometimes for simplicityDperformance reasons &IKm not an academic when it comes to 44(. 4h 8 And the wiQard...Well IKm loo,ing forward to >.=6 for statement chaining as I always seem to !e cleaning up my code after I use the wiQard &removing redundant element tags for e%ample(. $han,s again for the feed!ac,, "att

$han,s 6==<8=N866 66:=?:=3 Duraira- Athavan 0a-a Ausiness Card B0eplyC $han,s "att, 5%cellent o!eservations and than,s for sharing the same.

0egards 0a-a *howing messages 3 through < of <.

You might also like