Skip to Content
0

Transfering data from one page to another and from controller to view

Feb 08 at 03:06 PM

44

avatar image
Former Member

Hello, I am trying to get the username field value from login view and send it to list controller and then display it at list view but I am getting undefined at the object I am getting at list controller. Can you please tell me what I have done wrong?

list.controller

sap.ui.define([
	"MyAssignmentsMobile/controller/BaseController"
], function (BaseController) {
	"use strict";
	return BaseController.extend("MyAssignmentsMobile.controller.List",{
		onInit: function() {
				   
        	var oRouter = sap.ui.core.UIComponent.getRouterFor(this);
            oRouter.attachRoutePatternMatched(this._onObjectMatched, this);			
        	
           	var dialog = new sap.m.BusyDialog({text:'Loading...'});
			dialog.open();
			 var oModel = new sap.ui.model.json.JSONModel(); // cria uma variavel baseado no modelo     
             this.getView().setModel(oModel); //liga a view a variavel criado do modelo   
            
			oModel.attachRequestCompleted(function() {					
				oModel.updateBindings();
				dialog.close();
			});


			
			oModel.attachRequestFailed(function(oEvent) {				
				console.log(oEvent);
				dialog.close();
			});


			oModel.loadData("http://localhost:8080/myassignments-mockserver/list_os.jsp", null, false);			 
		},
		
		   _onObjectMatched: function (oEvent) {
        	console.log( oEvent.getParameter("arguments").username);
        	
        	var obj = this._find(
        			sap.ui.getCore().getModel("username"),
        			"usernamevalue",
        			oEvent.getParameter("arguments").username
        	);
        	
         var detailModel = new sap.ui.model.json.JSONModel();
        	detailModel.setData(obj);
        	this.getView().setModel(detailModel, "detail");  
        	
        	
        	this.getView().getModel().updateBindings();
        },
		
		onLogout: function(oEvent) {
			this.getRouter().navTo("");
		},
		
	

list.view ( I use the variable after welcome)

<mvc:View xmlns:mvc="sap.ui.core.mvc" controllerName="MyAssignmentsMobile.controller.List" xmlns="sap.m">
	<Page id="list" showHeader="true" title="Welcome, {detail>/obj>/username}"    showFooter="false" showNavButton="false">
		<content>
		
	

login.view

<mvc:View xmlns:mvc="sap.ui.core.mvc" controllerName="MyAssignmentsMobile.controller.Login" xmlns="sap.m" displayBlock="true">
<!--
	<App>
		<pages>
-->
			<Page id="login" showHeader="true" title="{i18n>appTitle}" showFooter="true" showNavButton="false">
				<content>
			
					<VBox id="login-content-sap_m_NestedBox-1516213955564" alignItems="Center" direction="Column" fitContainer="true" width="auto" renderType="Div" visible="true" height="auto">
						<items>
							<HBox id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-1" alignItems="Start" direction="Row" fitContainer="true" width="100%" height="90px" justifyContent="Center" renderType="Div" visible="true" displayInline="false">
								<items>
									<Image id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-1-items-sap_m_Image-1516277780700" src="/img/ocyan_logo2.png" height="40px" width="109.578125px" densityAware="false"/>
								</items>
								<layoutData/>
							</HBox>
							<HBox id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-2" alignItems="Start" direction="Column" fitContainer="true" width="300px" height="auto" justifyContent="Start" renderType="Div" visible="true" displayInline="false">
								<items>
									<TextArea id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-2-items-sap_m_TextArea-1516214028253" rows="1" placeholder="User Name" cols="200" maxLength="200" wrapping="None" visible="true"/>
									<TextArea id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-2-items-sap_m_TextArea-1516214030292" rows="1" placeholder="Password" cols="200" maxLength="200" wrapping="None" visible="true"/>
								</items>
								<layoutData/>
							</HBox>
							<HBox id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-1516214096580" alignItems="Stretch" direction="Row" fitContainer="false" width="auto" height="80px" justifyContent="Start" renderType="Div" visible="true" displayInline="false">
								<items/>
								<layoutData/>
							</HBox>
							<HBox id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-1516214151515" alignItems="Stretch" direction="Row" fitContainer="true" width="100%" height="auto" justifyContent="Center" renderType="Div" visible="true" displayInline="false">
								<items>
									<Button id="login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-1516214151515-items-sap_m_Button-1" text="Login" type="Default" icon="sap-icon://visits" iconFirst="true" width="200px" enabled="true" visible="true" iconDensityAware="false" press="onLogin"/>
								</items>
								<layoutData/>
							</HBox>
						</items>
						<layoutData/>
					</VBox>
				</content>
				<footer>
					<Bar id="login-footer-sap_m_Bar-1516277980666" design="Footer">
						<contentLeft/>
						<contentMiddle>
							<Image id="login-footer-sap_m_Bar-1516277980666-contentMiddle-sap_m_Image-1516277992553" src="/img/maxinst_footer.png" height="50px" width="100%" densityAware="false"/>
						</contentMiddle>
						<contentRight/>
					</Bar>
				</footer>
				<headerContent>
					<Button id="login-headerContent-sap_m_Button-1516212868694" text="" type="Default" icon="/img/favicon.png" iconFirst="true" width="auto" enabled="true" visible="true" iconDensityAware="false"/>
				</headerContent>
				<subHeader/>
				<customHeader/>
			</Page>
<!--			
		</pages>
	</App>
-->
</mvc:View>

login.controller

sap.ui.define([
	"MyAssignmentsMobile/controller/BaseController",
    "sap/m/MessageBox",
    "sap/ui/core/routing/History"
    ], function(BaseController, MessageBox, History) {
    "use strict";


    return BaseController.extend("MyAssignmentsMobile.controller.Login", {
 
		onLogin: function(oEvent) {
	
			var usernametext = this.getView().byId("login-content-sap_m_NestedBox-1516213955564-items-sap_m_HBox-2-items-sap_m_TextArea-1516214028253").getValue()


			var sRouteName="list";
			this.getRouter().navTo(sRouteName, {username: usernametext});			
		},
	onInit: function () {
		
        this.mBindingOptions = {};
    	  alert('language: ' + navigator.language + '\n');
  			 
  	
        //this.oRouter = sap.ui.core.UIComponent.getRouterFor(this);
        //this.oRouter.getTarget("Login").attachDisplay(jQuery.proxy(this.handleRouteMatched, this));
        }
});
}, /* bExport= */true);
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Jamie Cawley
Feb 09 at 01:37 PM
0

What does the function _find return? Also the binding

{detail>/obj>/username}

is not correct. You have two alias in it. Maybe it should be {detail>/obj/username} if the function _find is returning something like

{ "obj": {

"username" : "value"

}}

Regards,

Jamie

Share
10 |10000 characters needed characters left characters exceeded