on 07-07-2015 3:03 AM
Dear experts, i am getting the form in two cases as screen shot shown. Any experts can help me to check what is difference between these two codes.
<Page id="SFT" navButtonPress="onNavBack" showNavButton="true" title="Simple Finance">
<headerContent>
<Button icon="sap-icon://home" id="homeButton" press="onHomePressed"/>
</headerContent>
<subHeader>
<Toolbar>
<Button id="PLS" press="onPressPLS" text="Profits And Lost Statement"/>
<ToolbarSpacer/>
<Button id="PA" press="onPressPA" text="Profitability Analysis"/>
<ToolbarSpacer/>
<Button id="CBD" press="onPressCBD" text="Cost Break Down"/>
</Toolbar>
</subHeader>
<content>
<ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%">
<viz:Popover id="idPopOver"></viz:Popover>
<viz:VizFrame height="3700px" id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%"></viz:VizFrame>
</ScrollContainer>
<form:SimpleForm columnsL="1" columnsM="1" columnsS="1" emptySpanL="1" emptySpanM="1" labelSpanL="4" labelSpanM="5" layout="ResponsiveGridLayout"
maxContainerCols="2" minWidth="1024">
<form:content>
<Label text="Year To Date"/>
<DatePicker change="handleChange" id="DPRevenue" placeholder="Enter Date "/>
<Text text=""/>
<Label text="Revenue"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" id="DPExpense" placeholder="Enter Date "/>
<Text text=""/>
<Label text="Expense"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" id="DPProfit" placeholder="Enter Date"/>
<Text text=""/>
<Label text="Period to Profit Changed"/>
<Text text="{}"/>
</form:content>
</form:SimpleForm>
</content>
</Page>
and
var oPopOver = new sap.viz.ui5.controls.Popover();
var oVizFrame = new sap.viz.ui5.controls.VizFrame({
vizType: "bar",
width: "100%",
height: "3700px"
});
var oScrollContainer = new sap.m.ScrollContainer({
height: "100%",
width: "100%",
horizontal: false,
vertical: true,
focusable: true,
content: [oVizFrame]
});
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions: [{
name: "Item Category",
value: "{Item Category}"
}, {
name: 'City',
value: '{City}'
}],
measures: [{
name: 'Revenue',
value: '{Revenue}'
}],
data: {
path: "/book"
}
});
oVizFrame.setDataset(oDataset);
oVizFrame.setModel(oModel);
var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "valueAxis",
'type': "Measure",
'values': ["Revenue"]
}),
feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "categoryAxis",
'type': "Dimension",
'values': ["Item Category"]
}),
feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({
'uid': "color",
'type': "Dimension",
'values': ["City"]
});
var scales = [{
'feed': 'color',
'palette': ['#FF0000', '#CC00FF', '#6600FF']
}];
oVizFrame.setVizProperties({
valueAxis: {
label: {
formatString: 'u'
}
},
plotArea: {
dataLabel: {
visible: true,
formatString: "#,##0"
}
},
legend: {
title: {
visible: false
}
},
title: {
visible: true,
text: 'Revenue by City and Item Category'
},
xAxis: {
scale: {
fixedRange: true,
minValue: 0,
maxValue: 1400000
}
}
});
oVizFrame.addFeed(feedValueAxis);
oVizFrame.addFeed(feedCategoryAxis);
oVizFrame.addFeed(feedColor);
oVizFrame.setVizScales(scales);
oPopOver.connect(oVizFrame.getVizUid());
var SForm = new sap.ui.layout.form.SimpleForm({
layout:sap.ui.layout.form.SimpleFormLayout.ResponsiveGridLayout,
minWidth:1024,
maxContainerCols:2,
labelSpanL:4 ,
labelSpanM:5 ,
emptySpanL:1 ,
emptySpanM:1 ,
columnsL:1,
columnsM:1,
columnsS:1,
content:[new sap.m.Label({
text: "Year To Date "
}),
new sap.m.DatePicker({
placeholder : "Enter Date",
change:"handleChange"
}),
new sap.m.Label({
text: "Revenue "
}),
new sap.m.Text({
text: "{}"
}),
new sap.m.Label({
text: "Year To Date "
}),
new sap.m.DatePicker({
placeholder : "Enter Date"
}),
new sap.m.Label({
text: "Expense "
}),
new sap.m.Text({
text: "{}"
}),
new sap.m.Label({
text: "Year To Date"
}),
new sap.m.DatePicker({
placeholder : "Enter Date"
}),
new sap.m.Label({
text: "Period to Profit Changed "
}),
new sap.m.Text({
text: "{}"
})
]
});
oPage.removeAllContent();
oPage.addContent(oScrollContainer);
oPage.addContent(SForm);
}
after pressed Home Button:
Not sure why this is happening because it is really hard to see from your code. You could maybe check the generated DOM and see where the extra width is coming from.
But taking a step back, why are you creating the same view in both XML and JavaScript? Why not reuse the same XML in a fragment and call that from your onHomePressed event? That way you don;t have to maintain two separate instances
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
call like this,
sap.ui.xmlfragment("YOUR XML", this);
JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui
Programmatically Instantiating XML Fragments - User Interface Add-On for SAP NetWeaver - SAP Library
You first create a fragment based on the view you want to display:
<core:FragmentDefinition xmlns="sap.m" xmlns:core="sap.ui.core">
<Page id="SFT" etc...
//etc
</Page>
</core:FragmentDefinition>
and give it the proper name.fragment.xml
Then define a global variable in your controller which will hold a reference your fragment for re-use:
oMyFragment : null;
reference that fragment in your code:
if (!oMyFragment) {
oMyFragment = sap.ui.xmlfragment("name", this); //add reference to controller 'this'
}
you can then include oMyFragment wherever you want.
Dear Experts, sorry for a bit long for this comment. I am the first time using the fragment and faced some problems. Hope expert can guide me. Do correct me if any part i did wrong
Thanks.
The simpleFinanceFragment was created based on view.
In controller, i declared oMyFragment as global variable and onHomePressed event as shown
console:
inside simpleForm.fragment.xml: (I wonder how to set the viz properties in the bold part since i only call the fragment at the onHomePressed event?)
<core:FragmentDefinition xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:form="sap.ui.layout.form"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:viz="sap.viz.ui5.controls">
<Page id="SFT" navButtonPress="onNavBack" showNavButton="true" title="Simple Finance">
<content>
<ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%">
<viz:Popover id="idPopOver"></viz:Popover>
<viz:VizFrame height="1700px" id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%"></viz:VizFrame>
</ScrollContainer>
<form:SimpleForm layout="ResponsiveGridLayout" minWidth="1024" maxContainerCols="2" labelSpanL="4" labelSpanM="5" emptySpanL="1" emptySpanM="1" columnsL="1" columnsM="1" columnsS="1" >
<form:content>
<Label text="Year To Date" />
<DatePicker id="DPRevenue" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Revenue" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPExpense" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Expense" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPProfit" placeholder="Enter Date" change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Period to Profit Changed" />
<Text text="{}" />
</form:content>
</form:SimpleForm>
</content>
</Page>
</core:FragmentDefinition>
Hi Santhosh, may i know u meant the fragment folder created inside the web content is as shown in the first screen shot?
The second screen shot showed that i put nothing in the namespace there, what should put for the namespace for this line (oMyFragment = sap.ui.xmlfragment("NameSpace.simpleForm", this);) ?
ya. But i am not sure where is going wrong.
1)
2) Inside simpleForm,fragment.xml:
<core:FragmentDefinition xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:form="sap.ui.layout.form"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:viz="sap.viz.ui5.controls">
<Page id="SFT" navButtonPress="onNavBack" showNavButton="true" title="Simple Finance">
<content>
<ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%">
<viz:Popover id="idPopOver"></viz:Popover>
<viz:VizFrame height="1700px" id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%"></viz:VizFrame>
</ScrollContainer>
<form:SimpleForm layout="ResponsiveGridLayout" minWidth="1024" maxContainerCols="2" labelSpanL="4" labelSpanM="5" emptySpanL="1" emptySpanM="1" columnsL="1" columnsM="1" columnsS="1" >
<form:content>
<Label text="Year To Date" />
<DatePicker id="DPRevenue" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Revenue" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPExpense" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Expense" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPProfit" placeholder="Enter Date" change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Period to Profit Changed" />
<Text text="{}" />
</form:content>
</form:SimpleForm>
</content>
</Page>
</core:FragmentDefinition>
3) onHomePressed event:
onHomePressed: function(){
oMyFragment = sap.ui.xmlfragment("Fragment.simpleForm",this); //add reference to controller 'this'
oMyFragment.open();
}
4) console :
Here it's shows your xml fragment is not found. Give "Absolute path for your file" and try,
sap.ui.controller("YOUR CONTROLLER", {
oMyFragment: null,
onInit: function() {
},
onHomePressed: function(oEvent){
this.oMyFragment = sap.ui.xmlfragment("/Fragment.simpleForm",this); //add reference to controller 'this'
this.oMyFragment.open();
},
No, sorry for that,
In index.html you are written like this
data-sap-ui-resourceroots='{"view": "./"}'
means "view" is the naming convension. through "view" you can call any of the file directly.
so inside that method call your xml fragment file like this,
onHomePressed: function(oEvent){
this.oMyFragment = sap.ui.xmlfragment("view.simpleForm",this); //add reference to controller 'this'
this.oMyFragment.open();
}
Okay.
Here i am going to provide you a solution.
Right Click on your view folder.
Create file and provide a name like this. vizframe.fragment.xml
Here vizframe is our fragment name.
Now write your code of fragment in this file and don't forget to save it.
I have develop a simple application.
This is code of my view.
<core:View controllerName="view.View1" xmlns:core="sap.ui.core" xmlns:form="sap.ui.layout.form" xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc" xmlns:viz="sap.viz.ui5.controls" xmlns="sap.m">
<Page id="SFT" navButtonPress="onNavBack" showNavButton="true" title="Simple Finance">
<headerContent>
<Button icon="sap-icon://home" id="homeButton" press="onHomePressed"/>
</headerContent>
<subHeader>
<Toolbar>
<Button id="PLS" press="onPressPLS" text="Profits And Lost Statement"/>
<ToolbarSpacer/>
<Button id="PA" press="onPressPA" text="Profitability Analysis"/>
<ToolbarSpacer/>
<Button id="CBD" press="onPressCBD" text="Cost Break Down"/>
</Toolbar>
</subHeader>
</Page>
</core:View>
This is code in index.html.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta http-equiv='Content-Type' content='text/html;charset=UTF-8'/>
<script src="resources/sap-ui-core.js"
id="sap-ui-bootstrap"
data-sap-ui-libs="sap.m"
data-sap-ui-xx-bindingSyntax="complex"
data-sap-ui-resourceroots='{"view": "./"}'
data-sap-ui-theme="sap_bluecrystal">
</script>
<!-- only load the mobile lib "sap.m" and the "sap_bluecrystal" theme -->
<script>
sap.ui.localResources("view");
var app = new sap.m.App({initialPage:"idView1"});
var page = sap.ui.view({id:"idView1", viewName:"view.View1", type:sap.ui.core.mvc.ViewType.XML});
app.addPage(page);
app.placeAt("content");
</script>
</head>
<body class="sapUiBody" role="application">
<div id="content"></div>
</body>
</html>
index.html is auto generated. Don't change it.
This is code in my fragment.
<core:FragmentDefinition xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:form="sap.ui.layout.form"
xmlns:core="sap.ui.core">
<form:SimpleForm layout="ResponsiveGridLayout" minWidth="1024" maxContainerCols="2" labelSpanL="4" labelSpanM="5" emptySpanL="1" emptySpanM="1" columnsL="1" columnsM="1" columnsS="1" >
<form:content>
<Label text="Year To Date" />
<DatePicker id="DPRevenue" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Revenue" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPExpense" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Expense" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPProfit" placeholder="Enter Date" change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Period to Profit Changed" />
<Text text="{}" />
</form:content>
</form:SimpleForm>
</core:FragmentDefinition>
Till now we have developed our fragment.
Now we have to include this file in our project but you are getting error.
On searching after SCN, i found that Component.js is of great use in SAPWEB IDE.
Now right click on your project name. New File and provide the name Component.js
Keep this in mind that C is in uppercase.
Now i have written this code in my Component.js file.
jQuery.sap.declare("view.Component");
sap.ui.core.UIComponent.extend("view.Component", {
metadata : {
rootView : "view.View1",
dependencies : {
libs : [
"sap.m",
"sap.ui.layout",
"sap.viz"
]
},
config : {
sample : {
files : [
"View1.view.xml",
"View1.controller.js",
"vizframe.fragment.xml"
]
}
}
}
});
Then this simple code in my controller to check if this is working.
var oPage; // Global Variable
sap.ui.controller("view.View1", {
onInit: function() {
oPage = this.getView().byId("SFT");
var frg = sap.ui.xmlfragment("view.vizframe", this);
oPage.addContent(frg);
}
});
and it worked.
This is the output.
You can check that i have not written SimpleForm code in xml view. It is being displayed from fragment.
Regards
Dhananjay
Hi Dhananjay, I sincerely thanks and appreciate for your help. I really like the way u guided me. I have some questions regarding to your solution:
1) The 1st line u wrote jQuery.sap.declare("view.Component"); in Component.js, may i know the "view" in the view.Component is your namespace? If i created the project without namespace, what should i put ya? Is ok i put jQuery.sap.declare("SimpleFinanceFragment.Component");in Component.js?
2)Can i put the below code in my onHomePressed event?
var frg = sap.ui.xmlfragment("view.vizframe", this);
oPage.addContent(frg);
1. exactly "view" is the namespace. declared as globally in component.js.
If you not declared namespace then for each view or any file you need to call means, you should give absolute path for that file.
means you need to give full path to access that file.
2. yes you can put, when you press on that button, In that time it will be displayed.
Hay LOH,
I find a good link for you regards xml fragment, Refer this you will get clear picture,
Step 10: Detail XML Fragments - UI Development Toolkit for HTML5 (SAPUI5) - SAP Library
Hi Dhananjay, i am curious why my home button is still not functioning after followed your guidance .
simpleForm.fragment.xml :
<core:FragmentDefinition xmlns="sap.m"
xmlns:l="sap.ui.layout"
xmlns:form="sap.ui.layout.form"
xmlns:mvc="sap.ui.core.mvc"
xmlns:core="sap.ui.core"
xmlns:viz="sap.viz.ui5.controls">
<form:SimpleForm layout="ResponsiveGridLayout" minWidth="1024" maxContainerCols="2" labelSpanL="4" labelSpanM="5" emptySpanL="1" emptySpanM="1" columnsL="1" columnsM="1" columnsS="1" >
<form:content>
<Label text="Year To Date" />
<DatePicker id="DPRevenue" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Revenue" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPExpense" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Expense" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPProfit" placeholder="Enter Date" change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Period to Profit Changed" />
<Text text="{}" />
</form:content>
</form:SimpleForm>
</core:FragmentDefinition>
Component.js :
jQuery.sap.declare("view.Component");
sap.ui.core.UIComponent.extend("view.Component", {
metadata: {
rootView: "view.SimpleFinance",
dependencies: {
libs: [
"sap.m",
"sap.ui.layout",
"sap.viz"
]
},
config: {
sample: {
files: [
"SimpleFinance.view.xml",
"SimpleFinance.controller.js",
"simpleForm.fragment.xml"
]
}
}
}
});
controller part:
onHomePressed: function(){
var frg = sap.ui.xmlfragment("view.SimpleFinance", this);
oPage.addContent(frg);
}
-index.html maintained as usual (no change)
ya, i have changed it but still it shown me the id duplicate. The ID are bold as shown.
In my view.xml:
<content>
<ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%">
<viz:Popover id="idPopOver"></viz:Popover>
<viz:VizFrame height="1700px" id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%"></viz:VizFrame>
</ScrollContainer>
<form:SimpleForm layout="ResponsiveGridLayout" minWidth="1024" maxContainerCols="2" labelSpanL="4" labelSpanM="5" emptySpanL="1" emptySpanM="1" columnsL="1" columnsM="1" columnsS="1" >
<form:content>
<Label text="Year To Date" />
<DatePicker id="DPRevenue" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Revenue" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPExpense" placeholder="Enter Date " change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Expense" />
<Text text="{}" />
<Label text="Year To Date" />
<DatePicker id="DPProfit" placeholder="Enter Date" change="handleChange" class="sapUiSmallMarginBottom"/>
<Text text="" />
<Label text="Period to Profit Changed" />
<Text text="{}" />
</form:content>
</form:SimpleForm>
</content>
in simpleForm.fragment.xml :
<core:FragmentDefinition xmlns:core="sap.ui.core" xmlns:form="sap.ui.layout.form" xmlns:l="sap.ui.layout" xmlns:mvc="sap.ui.core.mvc"
xmlns:viz="sap.viz.ui5.controls" xmlns="sap.m">
<form:SimpleForm columnsL="1" columnsM="1" columnsS="1" emptySpanL="1" emptySpanM="1" labelSpanL="4" labelSpanM="5" layout="ResponsiveGridLayout"
maxContainerCols="2" minWidth="1024">
<form:content>
<Label text="Year To Date"/>
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPRevenue1" placeholder="Enter Date "/>
<Text text=""/>
<Label text="Revenue"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPExpense1" placeholder="Enter Date "/>
<Text text=""/>
<Label text="Expense"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPProfit1" placeholder="Enter Date"/>
<Text text=""/>
<Label text="Period to Profit Changed"/>
<Text text="{}"/>
</form:content>
</form:SimpleForm>
</core:FragmentDefinition>
remove id from your fragment.xml and view.xml and check it once.
All id's of date.
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPRevenue1"placeholder="Enter Date "/>
<Text text=""/>
<Label text="Revenue"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPExpense1"placeholder="Enter Date "/>
<Text text=""/>
<Label text="Expense"/>
<Text text="{}"/>
<Label text="Year To Date"/>
<DatePicker change="handleChange" class="sapUiSmallMarginBottom" id="DPProfit1" placeholder="Enter Date"/>
All in bold.
But viewing both looks same. very difficult to ans this type of questions yar,.
in 1st view Revenue and expense is binding with some value so in the screen it's showing [object]
In 2nd view you are not binded any thing. so its showing nothing in the Revenue and expense.
sap.m lib is responsive, so based on the data shown in the view. It will change the screen.
so in 1st screen its coming [object] and not in 2nd screen. that's the reason your views are different.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ya LOH CHUN WOOI,
Data Picker size is reduced because of the Revenue and Expense object is holding some values as displayed [object]. so automatically screen will be responsive in 1st view, already mentioned in previous comment.
Hi Santosh,
I don't think this is the case. I tried this to resolve it by putting text here but the answer is same. I don't think why this is happening. Is there any difference in responsiveness of JS view and XML view?
Because due to this only this is displaying this two difference.
Perhaps a ticket must be raised to SAP for this concern after waiting for some expert suggestions.
What do you say?
ok sure, Dhananjay, i will try it. Is it the default width in the XML view and JS view are different? Second question is if i put the code of onHomePressed event inside the fragment and called it in onHomePressed at controller, is it fine i am using this method? i have pasted the code and screen shot as shown in the previous conversation.
User | Count |
---|---|
85 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.