on 01-26-2017 5:47 AM
Hi Venkatesh ,
Yeah you need to extend ObjectPageSubsection class to add the event , but just think if you can any other control , if not than go ahead and extend
thanks
Viplove
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Viplove,
I have extended the container Object Page Sub Section as below,
……………………
…………………….
<ObjectPageSection id="educationSection" title="Education" importance="Low">
<subSections>
<osswe:ObjectPageSubSectionWithEvent title="Sub 1" press="onSub1">
<blocks>
<formblock:PersonalBlock id="idRegBlock1" columnLayout="1"/>
</blocks>
</osswe:ObjectPageSubSectionWithEvent>
<ObjectPageSubSection id="personalSectionSS2" title="Sub 2">
<moreBlocks>
<formblock:PersonalBlock id="idRegBlock2"/>
<formblock:PersonalBlock id="idRegBlock3"/>
</moreBlocks>
</ObjectPageSubSection>
</subSections>
</ObjectPageSection>
…………………..
……………………….
ObjectPageSubSecitonWithEvent.js(extended control)
sap.ui.define(["sap/ui/core/Control"], function(Control) {
"use strict";
return Control.extend("com.testObjectPage.control.ObjectPageSubSecitonWithEvent", {
metadata: {
properties: {},
aggregations: {},
events: {
"press": {}
}
},
init: function() {},
onclick: function(evt) {
this.firePress();
},
renderer: function(oRm, oControl) {
oRm.write('<li');
oRm.writeControlData(oControl);
oRm.write(">");
oRm.write('</li>');
}
});
});
Home.controller.js
jQuery.sap.declare("control.ObjectPageSubSecitonWithEvent");
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("com.testObjectPage.controller.Home", {
onPress:function(){
sap.m.MessageToast.show("sMessage");
}
});
});
Project Structure:
Output:
Error:
Can't find object class 'com.testObjectPage.control.ObjectPageSubSectionWithEvent' for XML-view - XMLTemplateProcessor.js
Please help me where I am getting error.
Actually there is nothing in aggregation in the extended control , as you are extending the Control Class not the ObjectPageSubSection Class which means you are creating the custom control but you need to extend an existing control with a press event .
check this link for that .
thanks
Viplove
Hi Viplove,
Below is the final code..
Event is firing but in wrong place.
Actually event has to fired when user selects the drop down like item .i.e. ObjectPageSubSection title as shown below,
But it is being fired when user clicks on the subsection part as shown below.
Complete code:
ObjectPageSubSectionWithEvent.js
sap.ui.define(["sap/ui/core/Control", "sap/uxap/ObjectPageSubSection"], function(Control, ObjectPageSubSection) {
"use strict";
return ObjectPageSubSection.extend("com.testObjectPage.control.ObjectPageSubSectionWithEvent", {
metadata: {
events: {
"press": {}
}
},
onclick: function(evt) {
this.firePress();
},
renderer:{}
});
});
<ObjectPageSection id="educationSection" title="Education" importance="Low">
<subSections>
<osswe:ObjectPageSubSectionWithEvent title="Extended Sub 1" press="onSub1">
<osswe:blocks>
<formblock:PersonalBlock id="idRegBlock1" columnLayout="1"/>
</osswe:blocks>
</osswe:ObjectPageSubSectionWithEvent>
<ObjectPageSubSection id="personalSectionSS2" title="Sub 2">
<moreBlocks>
<formblock:PersonalBlock id="idRegBlock2"/>
<formblock:PersonalBlock id="idRegBlock3"/>
</moreBlocks>
</ObjectPageSubSection>
</subSections>
</ObjectPageSection>
jQuery.sap.declare("control.ObjectPageSubSectionWithEvent");
sap.ui.define([
"sap/ui/core/mvc/Controller"
], function(Controller) {
"use strict";
return Controller.extend("com.testObjectPage.controller.Home", {
onSub1:function(){
//debugger;
sap.m.MessageToast.show("sMessage");
}
});
});
thanks.
Hi Viplove,
Instead of extending ,I tried with new approach by using browser events as below,
Home.controller.js
onAfterRendering: function() {
this.getView().byId("__xmlview0--idObjectPageLayout-anchBar-__xmlview0--personalSectionSS1-anchor").attachBrowserEvent("click",function(oEvent) {
sap.m.MessageToast.show("sMessage"); // it is working as expected
//But this below fragment is not rendering properly.
var oPageSubSection = this.getView().byId("personalSectionSS1");
var oFragment = sap.ui.xmlfragment("com.webileapps.testtestObjectPage.fragments.PersonalBlock");
oPageSubSection.addBlock(oFragment);
}, this);
}<br>
Home.view.xml
<ObjectPageSection id="educationSection" title="Education" importance="Low">
<subSections>
<ObjectPageSubSection id="personalSectionSS1" title="Sub 1">
<blocks>
<formblock:PersonalBlock id="idRegBlock1" columnLayout="1" />
</blocks>
</ObjectPageSubSection>
</subSections>
</ObjectPageSection><br>
But the problem is with rendering, when I click on the the ObjectPageSubSection title "Sub1" the fragment is adding as expected but in second click.
How can I rerender this?
thanks
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.