Splitting up pages in a Seam application - jboss

I'm quite new to Seam and am working on a relatively large project at work. The application is quite complicated in that there's a lot going on a single page at any time. I'm trying to figure out how to structure this and would like some feedback.
A good example to base this on would be Facebook (or a similar social media app). Facebook has a ton of stuff going on the screen. If all that logic were in a single view and backing bean, the files would be monolithic in size.
The way I see it is you'd have different components. For example, in Facebook, there'd be a component that handles showing your friends or friends in common with another person, there'd be another component handling invitations, suggestions, etc, etc.
All this is separate functionality being displayed on a single page however, in some cases, although being separate components, they're related at the end of the end. For example, if I click something in the main screen (i.e. not the elements in the sidebars) that generates an ajax request, a component in the sidebar might need to be updated automatically or rerendered.
Further than just sidebar components, there might be multiple disparate elements in the main area of a page (for example, a tabbed area where each panel could, in actuality be a separate or a separate view of the page).
It would be ugly if I had to handle everything in a single backing bean or something similar. It makes sense to me that each of these disparate elements have their own controllers (backing beans?) and what not. If I do an action in component x, it's bean could fire an event that could be listened to from component y's bean (thus causing component y to be rerendered).
Any ideas or resources I could look at?

Seam certainly allows division of pages into multiple fragments with separate backing components. They can be quite independent but can also interact.
To learn it, start with the Seam tutorial at JBoss and the book Seam in Action.
For the Ajax interaction you're looking for, you might also want to look at the RichFaces Developer Guide.

Related

How does Headless CMS offers Page Management/Builder Capability?

We are using a traditional CMS that also offers API (Rest & GraphQL) to expose content on top of page builder capabilities, I want to understand:
How to know if my traditional CMS is also a true Headless CMS?
Can a headless CMS offer Page management capability or it can only
create the content pieces that can be tagged & exposed via API to
multiple channels?
If that is the case, then doesn't my front-end logic needs to take
care of a lot of things while rendering the page to understand which
content will go first & which one last?
Wouldn't this create a tight coupling between CMS & Front End (be
it in the form of taxonomy)?
Is there any real advantage for Content authors in headless CMS as I
believe they will lose the drag & drop / WYSWYG features that is common
in traditional CMS?
Thanks
Your CMS is truly headless only if the content is completely separated from the context it is displayed in, that is, you should be able to change the destination of where the content goes, and have your front end determine where and how to layout the content. If your CMS controls or entirely owns this, it is no longer headless. If you're using contentful, this can be made easier by their JSON responses that come in a very structured order. In this case you are providing some context, but it is not anywhere near a dependency. These responses from the API are editable. So you can easily change this dependent on the destination of the content.
Yes it can, Headless CMS's provide enough metadata (ID's Slugs etc.) for you to create variable routing on your web application. Contentful also has the capability to attach SEO information with new content types. Keep in mind, a Page can be a content type that holds other content types. In this sense, your pages should be able to accept generic component objects, which will render a specific layout for each. Then that layout is backed with content from contentful.
As far as understanding which goes first, this can be inferred by the structured JSON response that comes from contentful or other headless CMS's. So it isn't much work to layout the order of things correctly. Here is an example from their docs. If your entry is a single entry that contains other types of content, they come in the order that they appear within the headless CMS, which means editors can shift things up and down as they choose.
https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/entries/entry/get-a-single-entry/console
to put it shortly, yes. You have to do a larger amount of work on the front end to accommodate this, but there are benefits long term. Once you have a suite of content types and layouts, eventually, the editors can become autonomous.
The advantage for editors is more of a safety for developers. Because they are locked into only editing content, it is impossible for an editor to make mistakes regarding style, positioning, or responsiveness. They also do not need to learn new technologies if you decide to change the front or backed of your web application. All the editors can see is the content magically appearing on the website. If they want to change the layout of a section, they don't need to contact you for these types of changes, so long as you've implemented that layout for a component. It keeps everything uniform, and allows for teams to effectively manage releases for new content.

View and Servlets in website class-diagram?

I'm about to develop this small website, its basically a simple web app to store informations about patients for a doctor.
The company i have got the assignment from demands an introducton with a class diagram, honstly, i have done this already but only for standalone apps, i'm very new in designing class diagrams for websites.
What i'm using is the Ivar Jacobson's iterative metho with usecases, where a usecase includes:
Actors, scenario (representing user-system interactions when all goes fine), and worse case scenatio (solutions when something goes wrong).
By applying this i came to a good conclusion, a well prepared class diagram.
My problem is that i'm doubting whether or not i should include jsp views and servlets(in my case action beans since i use Stripes) in the diagram, i mean, the bridge between the business-classes and the user are the jsp-views and the provided info are going to be processed by the servlets (or action beans), would you include them in the class diagram?
For a small project tis might be not that relevant but what if you have a project with 30 views and 20 servlets, the diagram would become messy and huge.
Do you have some tips about it?
Thank you
If the only reason you need the class diagram is to satisfy the client, best find out what they're looking for first.
If however they're not specific (and ignoring the cynical options) I'd suggest the following:
Create a "Domain Model" diagram. i.e. capture the concepts in the domain and their inter-relationships. So Doctor, Patients and associated stuff.
Don't create a "design" class diagram - i.e. no jsps, servlets, etc. If necessary create a simple architecture picture instead showing how the application is layered.
Rationale: a domain model is good for checking scope and verifying domain rules (relationships). A "design" class diagram only obfuscates that. A proliferation of jsps, controllers, etc. hides the underlying architecture pattern while distracting from the useful stuff in the domain model.
hth.

GWT MVP introduction questions

I have read a lot of gwt-mvp questions that are asked here, but since i'm totally new to this design pattern I would like to ask some questions:
[1] The Activity-Place pattern is a different pattern than mvp?
[2] In the MVP pattern presenters contain the logic. Now the logic of the widgets/controls is defined in the Activities?
[3] The CustomPlace classes are fixed (as the Eclipse plugin constructs them) or can i put data/methods and what kind?
[4] What is the use of the Presenter interface inside a CustomView? What data/methods would make sense to add into it?
[5] I want to build an application that will use many data structures that will be saved into a database. I have read some other posts here and I will make the Model part of MVP live inside each Activity. So i think to create each time the data structures of each activity at start and load its values (if necessary from db) and will update the database after the user goes to another view. What do you think about this approach?
Let's start by debunking one myth: Activities/Places have nothing to do with MVP. Places is about navigation, Activities are about "componentizing" the UI wrt Places. On the other hand, MVP is a design pattern, it's about how to organize your code.
Many people are using their activities as their MVP-presenters, but it's not enforced. The GWT team is trying a new approach where the activity is distinct from the presenter (work underway in the mobilewebapp sample if you want to follow what's going on there). You could also have your activity being your view and making use of an "internal" presenter (similar to how Cell widgets work)
A Place is more or less a URL. You can put whatever you want in it. I'd suggest making places immutable though: build a Place, goTo it, make use of its properties to build your UI.
That's about MVP then. This is only needed to decouple your view and presenter, mostly to make mocking in unit tests easier (this is particularly of the view interface though, not much for the presenter one, unless writing a test harness for you views). In some cases, you might also want to use the same view with distinct presenters; they'll all implement the same interface so the view can talk back to them.
How about the closing of the window/tab? I'd rather use a periodic auto-save, or an explicit save button; and implement mayStop so it prompts the user when there are unsaved changes (similar to how most desktop office apps work —e.g. MS Word or LibreOffice—, and GMail if you try to navigate away before your mail draft is auto-saved)
The Activity-Place is an implementation of the pattern. Google introduced gwt-mvp pattern at Google IO, but only provided it's implementation as part of GWT about a year later.
Yes Activities contain business logic. No, widgets/controls usually do not contain any logic, they just fire events based on user action. The logic that acts upon those events is written by user and resides elsewhere.
I don't use Eclipse, so wouldn't know about Places generated by it. Normally custom Places can contain custom fields and methods. For example they can contain custom place token arguments, i.e. if place token is "#place:id1", than your custom Place could contain field holding this argument.
When View needs to call/access Activity, it does so via Presenter, which Activity implements. For example when user enters all data in a for and presses submit, then you could have a method in Presenter named submit(formData).
Preparing/loading data in activity.start(..) is a normal way of doing things. If particular activity is used a lot, then you might consider caching the data if appropriate.

How can I use the new GWT MVP framework?

I need a tutorial for the new GWT MVP framework which is presented here.
The description Google gives is a little bit short for me. What are the meanings of — and how do I use — the following?
Activities
Places
Eventbus
ClientFactory
PlaceHistoryMapper
ActivityMapper
Also, where are the models in this new framework?
Places
These are classes that encode information about where your program has navigated. You might make a Place that means, "I'm on the home screen," and another one that means "I'm editing the user with id 52384. I think a better name for these would be PlaceTags, because they are not actually a place themselves - they just indicate where your program is. The URL is hooked to Places in a PlaceHistoryMapper, in which you can say, "hey, #home should generate a HomeScreenPlace and #edituser:52384 should generate a EditUserPlace (maybe constructed with a field you set to 52384).
Activities
These start and stop your code. Each Activity has a start method that is called when appropriate. You determine what "when appropriate" means by making an ActivityMapper, which has a function called getActivity. getActivity accepts a Place, and you have to decide which Activity to return. If the Place is whatever you've coded to mean "I'm on the home screen," you might return a HomeScreenActivity, and if the Place means "I'm editing the client with id 523584," you might return a EditClientActivity. You can add methods or a constructor to an activity to pass in an id like 523584.
EventBus
This is an object the different parts of your program use to communicate. If you don't want to, you don't need to know very much about it - you can just plug it in where indicated in Google's documentation (that you linked to)
ClientFactory
This is a centralized object whose only responsibility is making other objects. You can also skip this concept if you want to simplify things - you'll just be missing out on the central organization of your objects. The advantage is that if you want to switch them out later for, say, a mobile version, or a mocked-up-for-testing version, you can do so all at once within a single place and the rest of your program doesn't have to change at all. You can also reuse the same objects easily when coordinating from a central place, so you don't have to re-create the whole main screen every time someone goes to #home.
Your Actual Program
All this stuff is just for navigation. Your models, views, and presenters are all set up in each Activitys start() method, which the framework calls when your app should navigate to a new place. In the start method you should start up your presenter (usually using a new instance) and start up your display (usually reusing an instance - the client factory is good for this). When you've created your display, you let the framework know by setting it as the widget for the AcceptsOneWidget that the framework passed into your start method.
This is incomplete, but a good supplement to the docs you mentioned: http://code.google.com/intl/de-DE/webtoolkit/doc/latest/DevGuideMvpActivitiesAndPlaces.html
I would also recommend you to carefully listen to the Google I/O presentations, they are a golden key to understand the GWT philosophy:
http://www.google.com/events/io/2010/
http://www.google.com/events/io/2009/
Specially these ones (try to keep a more holistic view of the MVP framework). They do not talk about the real GWT implementation but they give you basic knowledge of MVP. I still am an 8 months noob, so from noob to noob :)
Ray Ryan's overview of the MVP paradigm. Great resource (it was an enlightening for me).
http://www.google.com/events/io/2009/sessions/GoogleWebToolkitBestPractices.html
http://www.google.com/events/io/2010/sessions/architecting-production-gwt.html
Daniel Danilatos's testing for GWT. Here you will understand why all the fuzz for MVP!
http://www.google.com/events/io/2010/sessions/gwt-continuous-build-testing.html

Should I separate RESTful API controllers from "regular" controllers?

This seems like an elementary question, but after a lot of searching around I can't seem to find a straightforward explanation:
If I'm building a web application that is going to be accessed largely through a web browser, but that will also support some API requests in a RESTful way, should there be a large degree of separation between the two?
On one hand, it seems a large amount of the functionality is the same, with identical data presented in different views (HTML vs. XML/JSON). But on the other hand, there are certain things I need to present to the browser that doesn't quite fit a RESTful approach: how to get an empty form to create a new instance of a resource and how to get a pre-populated form to edit an existing resource.
Should these two different methods of accessing the system by funneled through different controllers? Different methods in the same controller? The exact same methods with a switch for view type?
Your core controllers don't have to change, but that doesn't mean you can't have some extra ones solely to support you UI. For example, both of the Form examples you have can be unique to the Web API. Your entry URIs can certainly have links to those pages for both the machine and user interface, just don't expect the machine users to actually use them.
Also, if your machine clients are simply XML/JSON, then those representations don't need those links at all to the forms, since they'll not use them, and they don't "work" in JSON/XML anyway. You can manage that through Content negotiation.