Differences between a PortletRequest and a PortletResponse object - portlet

I understand that the Request objects (RenderRequest, ActionRequest, ...) contains the request we made, and the Response objects the response from the portlet...
But how, step by step everything works ?
If I take an example, I have a portlet with a little form. When I click onto the Send button, what is into the ActionRequest and the ActionResponse and when ? And after this first processing, what contains the RenderRequest and the RenderResponse objects?
Thanks for your help !
P.S: I don't use Spring MVC

I think the answer you seek is available in the JSR specs; either the old one (http://jcp.org/en/jsr/detail?id=168) or the new one (http://jcp.org/en/jsr/detail?id=286) depending on your environment.
The specs are free to download and give a fair overview of the concepts.

Related

How do I create actors that express hierarchical structures in akka?

I recently started developing using akka event sourcing/cluster sharding, and thanks to the online resources I think I understood the basic concepts and how to create a simple application with it. I am however struggling to apply this methodology in a slightly more complex data structure:
As an example, let's think about webpages and URLs.
Each Page can be represented with an actor in the cluster (having its unique id as the path of the page, e.g. /questions/60037683).
On each page I can issue commands such as
Create page (so if the page does not exist, it will be created)
Edit page (editing the details of the page)
Get page content (and children)
Etc.
When issuing commands to single pages, everything is easy as it's "written on the manual". But I have the added the complexity that a web page can have children, so when creating a "child page" I need the parent to update references to its children.
I thought of some possible approaches, but they feel incomplete.
Sending all events to the single WebPage and when creating a page, finding the parent page (if any) and communicate that a new child has been added
Sending all events to the single WebPage, and when creating a page, the message is sent to the parent, and then it will create a new command that will tell the child to initialize
Creating an infrastructure as WebPageRepository that will keep track of the page tree and will relay CRUD commands to all web page actors.
My real problem is, I think, handling the return of Futures properly when relaying messages to other actors that have to actually perform the job.
I'm making a lot of confusion and some reading resources would be greatly appreciated.
Thanks for your time.
EDIT: the first version was talking about a generical hierarchical file-system-like structure. I updated with the real purpose, webpages and urls and tried to clarify better my issues
After some months of searching, I reached the conclusion that what I'm doing is trying to have actors behave transactionally, so that when something is created, the parent is also updated in a safe manner, meaning that if one operation fails, all operations who completed successfully are rolled back.
The best pattern for this, in my opinion, proved to be the saga pattern, which adds a bit of complexity to the whole process, but in the long run it does what I needed.
Basically I ended up implementing the main actor as a stand alone piece (as it should be) that can receive create commands and add children commands.
There is then a saga actor which takes care of creating the content, adding the child to the parent and rolling back everything if something fails during the process.
If someone else has a better solution, I'll be glad to hear it out

Backbone sync request sequence

I've got a Backbone web application that talks to a RESTful PHP server. For PUT and POST it matters in which order the requests arrive at the server and for GET it matters in which order the responses arrive at the client.
The web application does not need to be used concurrently by multiple users, but what might happen is that the user changes its name twice really fast. Then the order in which the server processes PUT /name/Ann and PUT /name/Bea determines whether the name is set to Ann or Bea.
Backbone.Safesync and Backbone.Sync.AjaxQueue are two libraries that try to solve this problem. Doesn't Safesync only solve the problem with GET? Sync.AjaxQueue is outdated, but might serve as inspiration to implement a custom queued sync function. Making sync synchronous would solve the problem. If a request is only sent after the previous response is received, then only one request is processed at a time.
Any advice on how to proceed?
BTW: I don't think using PATCH requests would solve anything, because in my example the same attribute is changed twice.
There's a few ways to solve this, here's two:
add a timestamp to all requests, store it in the DB as "modified" and let the server check whether the timestamp of the new request is later than the one in the DB in order to be valid
use Promises to delay the second request from being made before the first one is responded on, there's a promise/deferred mechanism built into jquery, but you can also use a 3rd party one, for instance Q or when
If you can afford the delay, an easy approach is to set the async option to false when you call whatever method you're calling that results in the Backbone.sync. For example, in the appropriate model(s) simply override the default sync method to include the additional option.

One or two managedObjectContext

I am currently developing an application which makes HTTP request (via AsiHTTPRequest) then parse a JSON stream. Basically there is a tableView/NSFetchedResultsController, which print objects fetched from coreData, and the refresh is hand-done via a UIButton. I want my page to see the changes (so I implemented the NSFetchedResultsController).
But if the user refresh in the underground for instance, then the parsing will be differed, waiting for the answer of the request. Meanwhile the user can navigate and click on a Core Data object, which ca be deleted while he's reading it.
What would happen ?
Also, what is the best moment to save the context ?
Or is it better to use 2 context and then synchronise them ?
Thanks in advance for your opinions.
Niels
With a good use of the NSFetchedResultsControllerDelegate, only one NSFetchedResultsControllerDelegate is sufficient.
Hope it helps,
Niels

GWT: RPC and MVP and Place Tokenizer

I'm just starting off on my first attempt at the MVP architecture in GWT.
My understanding is that the job of PlaceTokenizer.getPlace(String) is to take the token in the URL after the hash, parse it, and return a Place with the object to which that token refers.
In my application, I have a resource (say, a video), which I tokenize by the video's unique id. Then my getPlace method ought to take this id, and retrieve the video information from the server. Is this the right approach?
As far as how to execute this, the only way that I could figure out would be to have my RemoteService right on the PlaceTokenizer, and make the call right in that getPlace method. Something about this made me hesitate. It seems like the call would be better suited for the Activity or somewhere else.
Is this how it's done? If not, is there a better way?
Your Place doesn't need to download the video. It could just contain the video's id.
Your Activity will receive the Place, which has the video id, and now the Activity can do the downloading or whatever heavy lifting you want.
So: Your PlaceTokenizer only needs to know enough to store the video id in the Place. Let the Activity do the work after that. The only function of getPlace is to turn a String into a Place.
It helped me to mentally rename Place to PlaceTag. The place objects really do not represent places - they represent tags or pointers to places. The actual place is represented by, terribly, the Activity.
if i may help clarifying the place signification a little more. Your place object is a serializable representation of the state of your client. it will help the activity restoring the screen to its former state by containing all the information you need to build it back.

how to get OutputStream

I want to get an image from a response but I don't know how to get the OutputStream.
I know in jsp, it is:
response.getOutputStream()
but what is it in liftweb ?
Thanks a lot.
In Lift, there are very few cases (none that I can think of) where you need the outputStream.
If you are returning a composed HTML page, Lift's templating system takes care of collecting the HTML to send back to the browser.
If you are returning a response from a web service, you return a subclass of LiftResponse from your handler function, for example: XmlResponse(bar)
If you are streaming a file or something else, there's a special case LiftResponse: StreamingResponse
Please bring your question to the Lift community http://groups.google.com/group/liftweb/topics?hl=en and we can have a conversation about what your goal is and how to achieve that goal.
Thanks!