There are no secrets to success. It is the result of preparation, hard work, and learning from failure.

Monday, 12 December 2016

CheckBox Example

Click here and follow my SAP UI5/FIORI snippets and information Page
I have done table example with json data and given mode="MultiSelect"(meaning of this is, you can select more than one items concurrently in table).Here, I have implemented restrictions for check boxes selection and deselection.You can select and deselect the line items but once you click on start button then you would not be able to select and deselect the line items.If you click on stop button then again you can select and deselect the line items.Go through it and please let me know in case of any issue/doubt.

Application Structure



View Part

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="multiselect.S1" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="CheckBox" class="sapUiSizeCompact">
<content>
<Table width="auto" id="Tab_id" mode="MultiSelect"
selectionChange="HandleSelect">
<headerToolbar>
<Toolbar>
<ToolbarSpacer />
<Button text="Start" press="handleStart" type="Accept" />
<Button text="Stop" press="handleStop" type="Accept" />
</Toolbar>
</headerToolbar>
<columns>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Id." id="materialCol1" />
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Date" />
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Status" />
</Column>
<Column minScreenWidth="Tablet" demandPopin="true">
<Text text="Quantity" />
</Column>
</columns>
</Table>
</content>
</Page>
</core:View>

Controller Part

sap.ui.controller("multiselect.S1", {

// Application Initialization....
onInit:function(){
var that=this;
// Setting Flag....
that.startFlag='YES';
this.bindTable();
this.getView().addStyleClass("sapUiSizeCompact");

},

// Table binding method....
bindTable:function(){
var json = sap.ui.model.json.JSONModel("model/record.json");
var tableId=this.byId("Tab_id");
var columnListItemTemplate = new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{id}"
}), 
new sap.m.Text({
text : "{Date}"
}), new sap.m.Text({
text : "{Status}"
}), 
new sap.m.Input({
value:"{AQty}",
editable:false,
})
]
});
tableId.setModel(json);
tableId.bindItems("/Records", columnListItemTemplate);
},
// If you press start button then this will call....
handleStart:function(){
var that=this;
that.startFlag='NO';
},
// If you press stop button then this will call....
handleStop:function(){
var that=this;
that.startFlag='YES';
},

// If you select and deselect the check box then this will call....
HandleSelect:function(oEvent){
var that=this;
if(that.startFlag==='NO'){
if(oEvent.mParameters.listItem.getSelected()===true){
var items=oEvent.mParameters.listItems;
for(var i=0;i
items[i].setSelected(false);
}
alert("you can't select the item");
}
else{
var items=oEvent.mParameters.listItems;
for(var i=0;i
{
items[i].setSelected(true);
}
alert("you can't deselect the item");
}
}
}

});

record.json


{
"Records":[
{
"id":11000043,
"Date":"03 Oct 2016",
"Status":"Open Request",
"AQty":10
},
{
"id":11000048,
"Date":"02 Oct 2016",
"Status":"Received",
"AQty":5
},
{
"id":11000067,
"Status":"Received",
"Date":"04 Oct 2016",
"AQty":8
},
{
"id":11000069,
"Status":"Open Request",
"Date":"05 Oct 2016",
"AQty":6
},
{
"id":11000078,
"Status":"Received",
"Date":"06 Oct 2016",
"AQty":4
},
{
"id":11000079,
"Status":" Deleted",
"Date":"08 Oct 2016",
"AQty":32
},
{
"id":11000080,
"Status":"Open Request",
"Date":"10 Oct 2016",
"AQty":10
}]
}


Result



     Deselecting Line Item after clicking on start button


     Selecting Line Item after clicking on start button

     Selecting Line Item after clicking on stop button



Thursday, 17 November 2016

SAP UI5 VS WebDynpro

Click here and follow my SAP UI5/FIORI snippets and information Page
Go through it and please let me know in case of any issue/doubt.
FeaturesSAP UI5Web Dynpro
Usage scenarios
  • Application to be used both on desktop and mobile devices
  •  Casual usage scenario, targeting non SAP users
  •  Simple screens
  •  Fit for building stateless apps, both SAP and non-SAP
  •  To build desktop based web applications
  •  Suitable for developing custom UI for complex SAP business Transactions
  •  Simple and complex screens
Development Skills
  •   HTML/HTML5
  • Javascript/JQeury
  • CSS
  •   Java – for WebDynpro Java
  • ABAP–for WebDynpro ABAP
Platforms & tools
  •   SAP Java stack
  • SAP ABAP stack
  • SAP HANA XS
  • Non SAP Web Application servers like TOMCAT
  • Eclipse with UI5 plugins
  •   SAP Java stack – for WebDynpro Java
  • SAP ABAP stack – for WebDynpro ABAP
  • NetWeaver Developer Studio(NWDS) and NetWeaver Development
    Infrastructure(NWDI)
UI Features
  •   Latest web UI features available
  • Ability to customize and extend
  •   Limited UI features
  • Limited extension and customization possible
Browser rendering
  •   Runs 100% on browser
  •   All UI events client side
  •   The applications runs on the server side
  •   Majority of UI events are server side, minimum client side events
Application Performance
  •   High performing due to client side events
  • Browser rendering is faster as HTML content size is minimal
  •   Frequent performance issues due to multiple server round trips
  • Amount of HTML content generated is high, impacting the browser rendering performance
Mobile support
  • Fully supported with dedicated mobile libraries
    for UI
  • Not supported
Models
  • Supports OData,& JSON
  • Supports Java, ABAP, Web services models
UI Design
  • UI design requires extensive coding in HTML and Javascript
(SAP is currently developing new UI5 development
environment with drag and drop features
  • Wizard driven UI design with minimal coding
    required

Wednesday, 19 October 2016

Drag Drop in SAPUI5

Click here and follow my SAP UI5/FIORI snippets and information Page
I have implemented drag and drop functionality in SAPUI5. You can drag the item from list and drop in table.You can't add(drop) same item in table.Go through it and please let me know in case of any issue/doubt.

Application Structure



View Part

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="dragdrop.S1" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Drag Drop">
<content>
<List id="dragableList" width="500px" class="dragList" items="{data>/}">
<items>
<StandardListItem title="{data>id}" />
</items>
</List>
<Table id="dropableTable" inset="false" class="table">
<columns>
<Column hAlign="Center">
<Text text="Id" />
</Column>
<Column hAlign="Center">
<Text text="Name" />
</Column>
<Column hAlign="Center">
<Text text="Mob" />
</Column>
</columns>
<items>
</items>
</Table>
</content>
</Page>
</core:View>

Controller Part

    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-core');
    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-widget');
    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-mouse');
    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-sortable');
    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-droppable');
    jQuery.sap.require('sap.ui.thirdparty.jqueryui.jquery-ui-draggable');
    jQuery.sap.require('sap.m.MessageBox');
    sap.ui.controller("dragdrop.S1", {
    // Initialization......
    onInit:function()
{
var oSortableList = this.getView().byId("dragableList");
 var listId = oSortableList.getId();
 var listUlId = listId + "-listUl";
 var materialModel = new sap.ui.model.json.JSONModel();
 var oDropableTable = this.getView().byId("dropableTable");
 var tableId = oDropableTable.getId();
 var materials = [
 {id: "1089", Name: "vikas ", Mob: "1234567890"},
 {id: "1090", Name: "nikhil ", Mob: "555554345"},
 {id: "1091", Name: "prashant ", Mob: "1236454656"},
 {id: "1092", Name: "rohit ", Mob: "5657775757"}
 ];
 materialModel.setData(materials);
 this.getView().setModel(materialModel, "data");

 // Make list draggable.....
 oSortableList.onAfterRendering = function() {
        if (sap.m.List.prototype.onAfterRendering) {
            sap.m.List.prototype.onAfterRendering.apply(this);
        }
 $("#"+listUlId+" li").draggable({
        helper: "clone"
      });
    }

// Make table droppable.....
 oDropableTable.onAfterRendering = function() {
        if (sap.m.Table.prototype.onAfterRendering) {
            sap.m.Table.prototype.onAfterRendering.apply(this);
        }
 $("#"+tableId).droppable({
      drop: function( event, ui ) {
      var listElementId = ui.draggable.context.id;
      var draggedElement = sap.ui.getCore().byId(listElementId);
      var oPath = draggedElement.getBindingContext("data").getPath();
      var split = oPath.split("/");
  var i = split[split.length-1];
  var materialData = materialModel.getData();

  for(var k=0;k<oDropableTable.getItems().length;k++)
  {

  //If item already present in the table then it will prevent to add.....
  if(materialData[i].id===oDropableTable.getItems()[k].getAggregation("cells")                                   [0].getText())
  {
  sap.m.MessageBox.show(materialData[i].id+"  already added to table");
  return;
  }
  }
      oDropableTable.addItem(
         new sap.m.ColumnListItem({
         cells: [
               new sap.m.Text({text: materialData[i].id}),
                new sap.m.Text({text: materialData[i].Name}),
                new sap.m.Text({text: materialData[i].Mob})
                ]
         })
        );
      }
 })
    }
}
});

Result


    There is no item in table.You can drag item from list and add(drop) in table.

   
    One item has been added(dropped) in table from list.  


   Three items have been added(dropped) in table from list.

 
    If you add(drop) same item in table from list then it will not add(drop) and show one validation message.


Thursday, 15 September 2016

Factory Function Example 2

Click here and follow my SAP UI5/FIORI snippets and information Page
This is another example of factory function,in which heterogeneous controls are added in same column.This is beauty of factory function.It plays very important role in table binding,list binding...etc.Go through it and please let me know in case of any issue/doubt.

Application Structure



View Part

core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
controllerName="view.S1" xmlns:html="http://www.w3.org/1999/xhtml">
<Page title="Factory Function">
<content>
<Table id="tabId">
<columns>
<Column>
<Text text="Name" />
</Column>
<Column>
<Text text="Mobile" />
</Column>
<Column>
<Text text="E-mail" />
</Column>
</columns>
        </Table>
</content>
</Page>
</core:View>


Controller Part

sap.ui.controller("view.S1", {
onInit : function() {
//calling method...........
this.tableBindMethod();
},
// called method.................
tableBindMethod : function() {
var that = this;
var json = new sap.ui.model.json.JSONModel("model/record.json")
var tabId = this.byId("tabId");
tabId.setModel(json);
tabId.bindItems("/Records", function(Id, path) {
return new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{name}"
}),

// calling method..............
that.factoryfunction(Id, path),

new sap.m.Text({

text : "{email}"
}) ]
})
});
},

// called method.......
factoryfunction : function(Id, Cpath) {
var key = Cpath.getProperty("key");
if (key === "L") {
return new sap.m.Link({
text : "{mobile}"
})
}
  else if (key === "C") {
return new sap.m.CheckBox({
selected : true,
})
} else if (key === "I") {
return new sap.m.Input({
value : "{mobile}"
})

} else {
return new sap.m.Text({
text : "{mobile}"
})
}
}
});

record.json

 {"Records":[
 {
"name":"vikas Kumar",
"mobile":123,
"email":"v@gmail.com",
"key":"L"
},
{
"name":"Nikhil Kumar",
"mobile":111,
"email":"nik@gmail.com",
"key":""
},
{
"name":"Bhaskar Kumar",
"mobile":444,
"email":"Bhasker@gmail.com",
"key":""
},
{
"name":"Rohit Kumar",
"mobile":2222,
"email":"Rohit@gmail.com",
"key":"C"
},
{
"name":"Ram Kumar",
"mobile":133323,
"email":"Ram@gmail.com",
"key":""
},
{
"name":"Vishal Kumar",
"mobile":123123123,
"email":"vishal@gmail.com",
"key":""
},
{
"name":"raju Kumar",
"mobile":656566,
"email":"raju@gmail.com",
"key":"I"
}
]}


Result                                                                                                                                     



Wednesday, 14 September 2016

Factory Function

Click here and follow my SAP UI5/FIORI snippets and information Page
With the help of factory function,you can place different controls in same column based on some conditions. This approach is much more flexible and allows complex or heterogeneous data to be displayed.Go through it and please let me know in case of any issue/doubt.

Example 1 :-

Application Structure

View Part                                                                                                                                 

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
xmlns="sap.m" controllerName="view.S1" xmlns:html="http://www.w3.org/1999/xhtml"
class="sapUiSizeCompact" xmlns:vikas="sap.ui.layout.form">
<Page id="pageId">
<content>
<Table id="tabId">
<columns>
<Column>
<Text text="Name" />
</Column>
<Column>
<Text text="Mobile" />
</Column>
<Column>
<Text text="E-mail" />
</Column>
</columns>
        </Table>
</content>
</Page>
</core:View>                                                                                                                                     

Controller Part                                                                                                                   

sap.ui.controller("view.S1", {
onInit : function() {
//calling method...........
this.tableBindMethod();
},
// called method.................
tableBindMethod : function() {
var json = new sap.ui.model.json.JSONModel("model/record.json")
var tabId = this.byId("tabId");
tabId.setModel(json);
tabId.bindItems("/Records", function(Id, path) {
var key = path.getProperty("key");
if (key === "R") {
return new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{name}"
}), new sap.m.Text({
text : "{mobile}"
}), new sap.m.Text({
text : "{email}"
}) ]
}).addStyleClass("redclass");
} else if (key === "G") {
return new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{name}"
}), new sap.m.Text({
text : "{mobile}"
}), new sap.m.Input({
value : "{email}"
}) ]
}).addStyleClass("greenclass");
} else if (key === "Y") {
return new sap.m.ColumnListItem({
cells : [ new sap.m.Text({
text : "{name}"
}), new sap.m.Text({
text : "{mobile}"
}), new sap.m.Text({
text : "{email}"
}) ]
}).addStyleClass("yellowclass")
} else {
return new sap.m.ColumnListItem({
cells : [ new sap.m.Link({
text : "{name}"
}), new sap.m.Text({
text : "{mobile}"
}), new sap.m.Text({
text : "{email}"
}) ]
})
}
});
}
});

record.json

{"Records":[
{
"name":"vikas Kumar",
"mobile":123,
"email":"v@gmail.com",
"key":"R"
},
{
"name":"Nikhil Kumar",
"mobile":111,
"email":"nik@gmail.com",
"key":""
},
{
"name":"Bhaskar Kumar",
"mobile":444,
"email":"Bhasker@gmail.com",
"key":""
},
{
"name":"Rohit Kumar",
"mobile":2222,
"email":"Rohit@gmail.com",
"key":"Y"
},
{
"name":"Ram Kumar",
"mobile":133323,
"email":"Ram@gmail.com",
"key":""
},
{
"name":"Vishal Kumar",
"mobile":123123123,
"email":"vishal@gmail.com",
"key":""
},
{
"name":"raju Kumar",
"mobile":656566,
"email":"raju@gmail.com",
"key":"G"
}
]}

style.css                                                                                                                              

.redclass {
background-color:red ! important;
}
.yellowclass{
background-color:yellow ! important;
}
.greenclass{
background-color:green ! important;
}
                                                                         

Result                                                                                                                                 

                                                   

                                                                                                                                                           

Restrict user to manually enter in Date Picker

Click here and follow my SAP UI5/FIORI snippets and information Page
Date Picker would not allow to user to enter anything.You can only select the date.Go through it and please let me know in case of any issue/doubt.

Write below lines in view

<DatePicker displayFormat="dd MMM YYYY" valueFormat="dd MMM YYYY"
id="datePickerId" width="30%">
</DatePicker>

Write below lines in controller

onInit:function()
{
this.byId("datePickerId").setDateValue(new Date());
var date=this.byId("datePickerId").getDateValue();

},
onAfterRendering:function()
{
$("#"+this.byId("datePickerId").sId+"-inner").prop("readonly", true) ;
},

Result




Thursday, 28 July 2016

Use of Internationalization

Click here and follow my SAP UI5/FIORI snippets and information Page

Internationalization
Internationalization is a design process that ensures a product (usually a software application) can be adapted to various languages and regions without requiring engineering changes to the source code. Think of internationalization as readiness for localization. Internationalization can save significant expense, time, and headaches for everyone involved. Sometimes written as "i18n", internationalization evolved from a growing demand for multilingual products and applications, a process called localization.Go through it and please let me know in case of any issue/doubt.

How to Use
//  It is used to get properties file(localization file).
 var mConfig = this.getMetadata().getConfig();

// It will give Module path.Task is component name.
 var sRootPath = jQuery.sap.getModulePath("Task");
      var i18nModel = new sap.ui.model.resource.ResourceModel({
            bundleUrl : [ sRootPath, mConfig.resourceBundle ].join("/")
        });
        this.setModel(i18nModel, "i18n");
sap.ui.model.resource.ResourceModel as a named model. This all code you have to write in init() method of the component file.

File Declaration

FileName_Language code_Country code.properties
messageBundle_gu_IN.properties

Example :-

Application Structure



View Part

<core:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"
  xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:f="sap.ui.layout.form"
  controllerName="Task.view.S1" xmlns:html="http://www.w3.org/1999/xhtml">
<Page   navButtonPress="navLaunchPad" id="page">
<content>
<l:Grid defaultSpan="L12 M12 S12" width="auto">
<l:content>
<f:SimpleForm id="SimpleFormChange354" minWidth="1024"
maxContainerCols="2" editable="true" layout="ResponsiveGridLayout"
labelSpanL="3" labelSpanM="3" emptySpanL="4"
emptySpanM="4" columnsL="1" columnsM="1" class="editableForm">
<f:content>
<Label  id="l1"/>
<Input/>
<Label  id="l2"/>
<Input/>
<Label  id="l3"/>
<Input/>
</f:content>
</f:SimpleForm>
</l:content>
</l:Grid>
 </content>
    <footer>
      <Toolbar  >
        <ToolbarSpacer />
        <ActionSelect
id="select_id"
change="check_language">
<items>
<core:Item key="English_1" text="English"/>
<core:Item key="marathi_1" text="Marathi"/>
<core:Item key="hindi_1" text="Hindi"/>
<core:Item key="Gujarati_1" text="Gujarati"/>
</items>
</ActionSelect>
      <Button id="b" type="Accept"></Button>
    </Toolbar>
    </footer>
  </Page>
</core:View>


Controller Part

jQuery.sap.require("sap.ui.core.mvc.Controller");
jQuery.sap.require("sap.m.MessageBox");
jQuery.sap.require("jquery.sap.resources");
sap.ui.core.mvc.Controller.extend("Task.view.S1", {
onInit:function()
{  
this.sLocale="en_US";
 this.surl="i18n/messageBundle.properties";
 // Calling Method..............
this.lan_M(this.sLocale, this.surl);
},

// When you select item from ActionSelect then this method will fire..........
 check_language:function()
  {
var key=this.getView().byId("select_id").getSelectedKey();
 if(key==="hindi_1")
 {
 this.sLocale ="hi_IN";
  this.surl="i18n/messageBundle.properties";
       }
 else if(key==="English_1")
 {
 this.sLocale="en_US";
 this.surl="i18n/messageBundle.properties";
 }
 else if(key==="Gujarati_1")
 {
 this.sLocale="gu_In";
 this.surl="i18n/messageBundle.properties";
 }
 else if(key==="marathi_1")
 {
this.sLocale="mr_In";
 this.surl="i18n/messageBundle.properties";
 }
 // Calling Method..............
 this.lan_M(this.sLocale,this.surl);
 },
  
// Called Method................
lan_M:function(sLocale,surl)

var oBundle = jQuery.sap.resources({url :this.surl, locale:this.sLocale});
 var l1=this.getView().byId("page").setTitle(oBundle.getText("Title"));
 var l1=this.getView().byId("l1").setText(oBundle.getText("name"));
 var l1=this.getView().byId("l2").setText(oBundle.getText("mobile"));
 var l1=this.getView().byId("l3").setText(oBundle.getText("email"));
 var l1=this.getView().byId("b").setText(oBundle.getText("submit"));
}
 });
messageBundle_en_US.properties

Title=Practice
name=Full Name
mobile=Mobile
email=E-mail
submit=Submit

messageBundle_gu_IN.properties

Title:\u0AAA\u0ACD\u0AB0\u0AA5\u0ABE
name=\u0A86\u0A96\u0AC1 \u0AA8\u0ABE\u0AAE
mobile=\u0AAE\u0ACB\u0AAC\u0ABE\u0A87\u0AB2
email=\u0A87 \u0AAE\u0AC7\u0AB2
submit=\u0AAB\u0ACB\u0AB0\u0ACD\u0AAE \u0AB8\u0AAC\u0AAE\u0ABF\u0A9F

messageBundle_hi_IN.properties

Title=\u0905\u092D\u094D\u092F\u093E\u0938
name=\u092A\u0942\u0930\u093E \u0928\u093E\u092E
mobile=\u092E\u094B\u092C\u093E\u0907\u0932
email=\u0908-\u092E\u0947\u0932
submit=\u092B\u093E\u0930\u094D\u092E \u091C\u092E\u093E \u0915\u0930\u0947\u0902

messageBundle_mr_IN.properties

Title=\u0938\u0930\u093E\u0935
name=\u092A\u0942\u0930\u094D\u0923 \u0928\u093E\u0935
mobile=\u092E\u094B\u092C\u093E\u0907\u0932
email=\u0908-\u092E\u0947\u0932
submit=\u092B\u0949\u0930\u094D\u092E \u0938\u093E\u0926\u0930 \u0915\u0930\u093E

Note

Don't worry,how to write code for hindi, marathi...etc.
Example:- If you want to write "submit" in hindi and marathi,just go to google and search submit in hindi and copy hindi word,paste in your properties file.It would be automatically converted into code.

Result

By default selection is English

 selected hindi


  selected marathi