SapUI5 exchanging data between views - sapui5

Actually I have a problem with exchanging data between views. i have a view that conatains a selectable table and i want to get the data of the selected rows and navigate to another view to do the treatement of these data (i've already done the navigation stuff) i just don't know how to create a global model or pass the data directly to the other view (i'm new to SAPUI5). Can anybody help me with that please?
Thank you in advance.

Approach 1: Global model
You can create global model in component.js or App.controller.js
and later you can assign data (selected record) to baseModel property like below
this.getView().getModel('baseModel').setProperty('/oSelectedRecord', data)
and in other view you can access that by below
this.getView().getModel('baseModel').getProperty('/oSelectedRecord')
Approach 2: Routing with parameter
Source view changes
Destination view changes
You can check detailed example in walkthough (choose older version, in newer version you won't see much code details)

Related

Dynamically Create Sections in Swift UI List (Using CoreData)

I have a multiple Entry objects (entries) stored in CoreData that I access as a list given by a FetchRequest in my ContentView.
All entries have a date and I want to not only put all entries in a list (I have achieved that) but put them in their right SwiftUI section (that correspond to the day of the entries) in that list.
Basically, my question was answered here, but I am not sure how to implement it as I am using CoreData and don't have a user data object.
I thought about introducing a model of the list view and bind it to the list view.
I would need to incorporate the fetch request into the model and use an attribute/function to provide an [[Entry]] attribute to the view, right?
How exactly would I do this? How do I continuously maintain an [[Entry]] attribute in the model that I can access/(add to)/(delete from) from the view?
The current state of my Xcode project is almost exactly like presented in this youtube video; actually I just want to expand on this video as an exercise.

Best practice for MVC 4 Edit Views and "Hidden" parameters

I have recently added some fields for auditing purposes to existing models in an MVC 4/ Entity project. I don't need these fields to be displayed on the edit page. However, they are required fields on the model.
As it stands, the edit page still works, but on the controller side, the ModelState.IsValid check fails because the required fields that are actually set on the item are not output to the view and therefore not re-submitted when the edit page is submitted.
Is there an easy, built in way to rectify this, or if not, which of the following is best practice for this scenario? Are there more options?
1) Set up hidden fields on the view to hold the information (Not a fan of this option, passes data around too much)
2) in the controller, on submit, first load the model by ID, then set each individual parameter based on the fields present on the view (Seems like extra unnecessary work)
3) Create a constructor for the model that takes itself as a parameter and pulls any non-default values and returns a new object. Basically a merge. (Best I think, still a lot of extra work)
4) ???
Best practice is to not use your domain model inside the views. Create a view model class that contains only the id and the fields you want in the view. Pass this model to your view. Change the parameter type of the form submit action to match your new view model. This will then pass the model validation without using hidden fields. In your action method, you can then retrieve the object from the database using the id property of the view model class and update fields as required.
Hope that makes sense.
I prefer to do the 2nd option as long as I can get the existing object with a single query or db call. This lets me to keep my view clean(no hidden fields for all those other properties) and use the existing update method which updates the domain model.
Look into your code. If the update method is making updates in lot of other places(many other tables) which is really not needed, then you could possibly write a short version of the update method which updates only the relevant parts ( ex: UpdateContactDetails).

iPhone: NSFetchedResultsController for each Entity?

I have three entities with one-to-many relationships (Book <--->> Page <--->> Text)
I want to use one table view to present Book.titles, one table view for Page.no and one view to show the Text when clicking on a Page.no.
Do I need to setup up a fetchedResultsController for each entity or can I get access to a Text object
using the Book entity - Book.pages... etc?
If I understand your question correctly, you only need one fetched results controller and CoreData will do the rest.
So, you fill an NSFetchedResultsController with all the books you want to display and present them with a UITableViewController subclass. Then when the user selects one, you pass this book on to another UITableViewController subclass which uses book.pages to get and display all the pages in that book. This idea is then repeated to show the text entities.
HTH
PS - If you aren't already, you may find it useful to use xCode's Managed Object Class generator to ensure book.pages and pages.texts are correctly set up. To use this, open your .xcdatamodel file, highlight an entity and choose File->New File and choose Managed Object Class and then follow the steps.
You can access all objects via the relationships but depending on how complex your tableviews are, it may get tricky to manage the datasource methods. It's doable though!
For instance, if you decide to fetch the books, provided you have a reference to the instance you get all pages and put them in an Array with:
Book *bookItem = [self.frc objectAtIndexPath:indexPath];
NSArray *dataSource = [[book objectForKey:#"pages"] allObjets];
Another option is to create an abstract class and make it a parent of all 3 entities, then fetch using this class which will give you an array of all books, pages and text. From there you can test for the class and populate the tables accordingly.

Best approach to control access/handle objects/models data passed to View in Zend Framework

I want to pass data to views, and I've two options in my mind (if you know a better approach, please mention).
I am using Zend_Based ORM system, and coded in a way that if I add a new field in database, its automatically available within the model.
1st: I convert the model's data into array and pass the array to the view. This way I will have all the data available within the view, but model's function/operations will not be available. And incase I need specific functionality, i will be coding view helpers while there are chances that the same functionality is already coded within model. e.g. a getting a date in specific format.
2nd: Or I pass the complete model object to the view, this way I will have all the model's functions available, but view will be able to access model's save function which is a bad thing. I can add some more functionality within model to make it read-only, but it will be extra work.
any suggestions which approach is better.
According to the MVC principle it's perfectly fine to let the View allow access to the Model. So, pass the complete Model to the View.
By the way, passing arrays around will copy your data (by value), while passing objects around will not (by reference). (Assuming PHP5). Large arrays might affect your performance.

ASP.NET MVC 2: Use [Data Annotations] to reference methods that could feed DDL lists?

A generally accepted way to pass all data to a view is to have a single data model with references to both your domain model and additional data for things like drop down lists (DDL).
However, partial views (view templates too) receive only a portion of the main model, not able to access the root of the Model sent to the original view. So if your DDL lists are not static, how do the partial views get the data?
Is there a way using [Data Annotations] to reference a method which could return the possible values of a field, then use this in the partial view's DDL? Where would this method exist, in the repository?
Links or C# code examples would be very helpful.
There is no built in Data Annotations attribute that could do what you ask.
You could create your own attribute that contains a reference to a Type and the name of a static method that you can then invoke via reflection from your partial view.
Where you would place such a method depends on what you are doing, though I still think that gathering all the inputs in your controller would be better. You can always set extra items in the ViewData collection and pass those into your partial views.