Master-Detail view - SAPUI5 : Passing argument from Master to Detail controller - data-binding

In Master controller, on selection of item in the list, I am calling the detail view and binding the model data.
Master Controller:
itemSelected: function(result)(
var app = sap.ui.getCore().byId("appId");
var list = sap.ui.getCore().byId("mainListId");
var selectedItem = list.getSelectedItem();
var selectedPath = selectedItem.oBindingContexts.MainList.sPath;
var Item = sap.ui.getCore().getModel("MainList").getProperty(selectedPath);
var endPoint = Item.Endpoint;
console.log(endPoint);
var oModel =new sap.ui.model.json.JSONModel(Item);
sap.ui.getCore().setModel(oModel,'DetailItem');
app.toDetail('idDetail','slide')
},
Detail View:
I am able to bind the model data here in oTable.
oTable.bindRows("DetailItem>/");
1.How store the model data in a variable? (tried: sap.ui.core().getModel(modelname).getData() and similar others. This gives undefined, as it gets read even before the ItemSelected function in the Master controller is called.)
How to bind/get the model data into Detail controller after the itemSelected function is called?
Thanks!

You can set the model to i.e. a view by using the following statement:
this.getView().setModel(oModel, "modelID");

Related

Xamarin Form passing parameters between page keep a hard link to it

I try the new Shell of Xamarin Form 4 for a small project.
I have a list of order, then someone chooses an order and start picking some inventory for this order with barcode. To be simple, I use 2 views and 2 viewmodel.
The process is:
1. User select an order the click a button "pickup"
2. I use ViewModelLocator (TinyIoc) to resolve the correct ViewModel of the pickup view
3. I call Initialize on the new ViewModel and pass some parameters needed. Like a list of items needed to be pickup.
4. Open the view in modal state.
I don't understand that if I change some qty in the list I pass on the second viewmodel, then hit the back button (modal view close). The quantity changed is now in the original viewmodel. How this is possible? I was thinking that passing parameter to a function do not share the same variable but just copy it??
Viewmodel of the first view (look at the Initialize function the List passed and the JobEnCours object)
private async Task GoPickup()
{
Device.BeginInvokeOnMainThread(async () =>
{
if (this.CodeJob != null && this.CodeJob != "")
{
this.IsBusy = true;
PrepChariotSP3ViewModel vm = ViewModelLocator.Resolve<PrepChariotSP3ViewModel>();
await vm.InitializeAsync(this._jobEnCours, this.ComposantesPick.ToList()) ;
await Shell.Current.Navigation.PushAsync(new PrepChariotSP3Page(vm));
this.IsBusy = false;
}
});
}
the the Initialize code on the second Viewmodel (look I set the JobEnCours.Description=Test)
public async Task InitialiseAsync(Job jobEnCours, List<ComposantePick> composantePick)
{
Title = "Ceuillette: " + jobEnCours.CodeProd;
this._jobEnCours = jobEnCours;
this.ComposantesPick = new ItemsChangeObservableCollection<ComposantePick>();
foreach(ComposantePick c in composantePick)
{
this.ComposantesPick.Add(c);
}
jobEnCours.Description = "test";
So, If I do the back button, then in the first VM the JobEnCours.Description is now set to "test" how this is possible?!
Any idea?

How to bind transient oData object to detail view

In my SAPUI5 app I'm using odata v4 model to communicate with the server. I have a detail view that binds to an existing object something like this:
// Controller code:
this.getView().bindElement({
path: "/Objects(" + this.m_ObjectId + ")",
model: "modelName"
});
If I want to create a new item in that view instead, I'm not binding to an existing item of course. From the documentation I saw that one should create new items like this:
var oModel = this.getModel("modelName");
var oListBinding = oModel.bindList('/Objects');
var oNewKap = oListBinding.create({
'OBJECT_ID': 0,
'SOME_PROP': 'Test'
});
The question now his, how to bind that newly created (transient) object to my view? If I do a
this.getView().bindElement({
path: "/Objects(0)",
model: "modelName"
});
The app will try to fetch an existing item from the server again...
Any help is appreciated!
You may do this.getView().setBindingContext(oNewKap)

Getting fragment's id into detail controller

I'm working on a sap fiori Master-Detail application on sap web ide.
i want to filter a table i have on detail view based on an ID i will get from a list in master view.The table's detail view is located in a fragment. I created a js function to filter that table in the detail controller but i can't seem to have the id of the table in the fragment.
Here's my detail-controller's code:
this._oView = this.getView();
this._oView.attachAfterRendering(function() {
var sPath1 = "Qmnum";
var sOperator1 = "EQ";
var sValue1 = "10000000";
var oFilter1 = new sap.ui.model.Filter(sPath1, sOperator1, sValue1);
var oBinding = this.byId("tableid").getBinding("items");
oBinding.filter(oFilter1);
});
i tried using also this
sap.ui.getCore().byId();
&
this.getView().byId();
but still undefined.
If XML fragments are used within XML views, giving the view ID as
fragment ID will allow calling this.byId(…) in the view’s controller
to retrieve controls inside the fragment.
var oFragment = sap.ui.xmlfragment(this.getView().getId(), "my.useful.VerySimpleUiPart" );
Initialize the fragment and attach it to the current view:
// Init fragment
var oFragment = sap.ui.xmlfragment("herePutJourneyToFragment.fragmentName", this.getView().getController());
// Attach the fragment to the current view
this.oView.addDependent(oFragment);
After that you should be able to find the table in you view:
var oTable = this.byId("tableid");
EDITED 13:45 150317 bellow:
Tutorial.

Error :There is No ViewData

I am new to mvc4(asp.net(vb.net), razor engine )..
This is annoying me. It works perfectly on the load and if I complete the form and submit it.
It shows the following error.
There is no viewdata of type'iEnumerable'that has
the key CustomerGroupId
In Controller(Get )
Function Create() As ActionResult
_Engine = CType(HttpContext.Application("Engine"), Engine)
ViewBag.CustomerSubGroup = New SelectList(_Engine.RteCustomerSubGroupFactory.CodeFactory.Values)
ViewBag.RateList = New SelectList(_Engine.RteRateListFactory.Values)
Return View()
End Function
In View(.vbhtml)
<table>
<tr><td>Code </td><td>#Html.TextBox("Code")</td></tr>
<tr><td>Name</td><td>#Html.TextBox("Name")</td></tr>
<tr><td>Customer Sub Group Name </td><td>#Html.DropDownList("CustomerSubGroupId")</td></tr>
<tr><td>Rate List</td><td>#Html.DropDownList("RateList")</td></tr>
<tr><td>IsDisabled</td><td>#Html.CheckBox("IsDisabled")</td></tr>
Shows the error in the line of
<tr><td>Customer Sub Group Name </td><td>#Html.DropDownList("CustomerSubGroupId")</td></tr>
In your Action of your Controll,er you have to add a key with the same Id you have used on the View, to apply on the DropDownList, for sample:
ViewBag.CustomerSubGroupId = New SelectList(_Engine.RteCustomerSubGroupFactory.CodeFactory.Values)
ViewBag.RateList = New SelectList(_Engine.RteRateListFactory.Values)
Return View()
in view, you can use:
#Html.DropDownList("CustomerSubGroupId")
#Html.DropDownList("RateList")
The reason is the ViewBag encapsulates the ViewData, that's why the message says you do not have the key on the ViewData.

Flex Advanced Data Grid w/ hierarchical data: How to access currentTarget fields on dragdrop event?

So this is driving me crazy. I've got an advanced data grid with a dataprovider that's an array collection w/ hierarchical data. Each object (including the children) has an id field. I'm trying to drag and drop data from within the ADG. When this happens, I need to grab the id off the drop target and change the dragged object's parentid field. Here's what I've got:
public function topAccountsGrid_dragDropHandler(event:DragEvent):void{
//In this function, you need to make the move, update the field in salesforce, and refresh the salesforce data...
if(checkActivateAccountManageMode.selected == true) {
var dragObj:Array = event.dragSource.dataForFormat("treeDataGridItems") as Array;
var newParentId:String = event.currentTarget['Id'];
dragObj[0].ParentId = newParentId;
} else {
return;
}
app.wrapper.save(dragObj[0],
new mx.rpc.Responder(
function():void {
refreshData();
},
function():void{_status = "apex error!";}
)
);
}
I can access the data I'm draggin (hence changing parentId) but not the currentTarget. I think the hierarchical data is part of the problem, but I can't find much in the documentation? Any thoughts?
event.currentTarget is not a node, it's the ADG itself. However, it's quite easy to get the information you want, since the ADG stores that data internally (as mx_internal).
I'm using the following code snippets (tested with Flex SDK 4.1) in a dragOver handler, but I guess it will work in a dragDrop handler too.
protected function myGrid_dragDropHandler(event:DragEvent):void
{
// Get the dragged items. This could either be an Array, a Vector or NULL.
var draggedItems:Object = getDraggedItems(event.dragSource);
if (!draggedItems)
return;
// That's our ADG where the event handler is registered.
var dropTarget:AdvancedDataGrid = AdvancedDataGrid(event.currentTarget);
// Get the internal information about the dropTarget from the ADG.
var dropData:Object = mx_internal::dropTarget._dropData;
// In case the dataProvider is hierarchical, get the internal hierarchicalData aka rootModel.
var hierarchicalData:IHierarchicalData = dropTarget.mx_internal::_rootModel;
var targetParent:Object = null;
// If it's a hierarchical data structure and the dropData could be retrieved
// then get the parent node to which the draggedItems are going to be added.
if (hierarchicalData && dropData)
targetParent = dropData.parent;
for each (var draggedItem:Object in draggedItems)
{
// do something with the draggedItem
}
}
protected function getDraggedItems(dragSource:DragSource):Object
{
if (dragSource.hasFormat("treeDataGridItems"))
return dragSource.dataForFormat("treeDataGridItems") as Array;
if (dragSource.hasFormat("items"))
return dragSource.dataForFormat("items") as Array;
if (dragSource.hasFormat("itemsByIndex"))
return dragSource.dataForFormat("itemsByIndex") as Vector.<Object>;
return null;
}
var dropData:Object = mx_internal::dropTarget._dropData;
should be
var dropData:Object = dropTarget.mx_internal::_dropData;
Try this.

Resources