Skip to Content
0
Nov 21 at 01:50 PM

SAP UI5 Master Detail - Bindelement does not work for the 2nd call

163 Views Last edit Nov 22 at 03:22 AM 4 rev

Hi there,

I have a list page to show all the employees and when I click the first data, I can successfully get the odata with the right data, e.g employeeSet('001')

But when I pressed back to the list and select another employee, e.g employeeSet('002'), it's still referring to the first data, when I debugged, the ID already being called as '002'.

But the textbox still showing the 1st data (001), what should I do?

When I refresh the page manually, the 2nd data is appearing.

Here's my detail view and the controller

<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" xmlns:html="http://www.w3.org/1999/xhtml"
	controllerName="app.employeeEmployee.controller.employee">
	<App>
		<pages>
			<Page title="page">
				<content>
					<VBox width="100%" direction="Column" id="__vbox0">
						<items>
							<Text text="{Firstname}" id="__text0"/>
							<Text text="{Lastname}" id="__text1"/>
						</items>
					</VBox>
				</content>
			</Page>
		</pages>
	</App>
</mvc:View><br>
		onInit: function() {
			var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
			oRouter.getRoute("employee").attachMatched(this._onRouteFound, this);
		},

	// Custom Method to bind the elements using the Event Arguments
		_onRouteFound: function(oEvt) {
			var oArgument = oEvt.getParameter("arguments");
			var oView = this.getView();
			oView.bindElement({
				path: "/employeesSet('" + oArgument.Kodeemp + "')",
				events: {
					change: this._onBindingChange.bind(this),
					dataRequested: function(oEvent) {
						oView.setBusy(true);
					},
					dataReceived: function(oEvent) {
						oView.setBusy(false);
					}
				}
			});
		},
		_onBindingChange: function(oEvent) {
			var oElementBinding = this.getView().getElementBinding();
			// No data for the binding
			if (oElementBinding && !oElementBinding.getBoundContext()) {
				this.getRouter().getTargets().display("notFound");
			}
		}