cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5: How to dynamically create sections/subsections/blocks with forms inside objectPageLayout?

Francesco
Explorer
0 Kudos

Hello experts,

As the title implies, I have to dinamically create(from controller I guess) sections and all their children aggregations inside an objectPageLayout.

All I have now is an oData response which contains two Objects inside an Array, this means I have to create 2 sections containing ObjectPageSubsections and blocks both containing forms inside. How would I go about doing this?

Thanks alot to those who will answer.

View Entire Topic
Thajunniza
Advisor
Advisor

Hi,

You can loop your array and use the below code reference inside the loop to create object page dynamically.

var oObjPage = that.getView().byId("__ObjectPageLayout");

//Add Object page Section

var sId = "__" + sType + "HR";

var oSection =

sap.uxap.ObjectPageSection({

titleUppercase: false, id: sId, title: "{i18n>HR_COMMENTS}"

});

oObjPage.addSection(oSection);

//Add SubSection

var oSubSection = new sap.uxap.ObjectPageSubSection({

titleUppercase: false

});

oSection.addSubSection(oSubSection);

//Add a form to Subsection

sId = "__" + sType + "HRForm";

var oForm = new sap.ui.layout.form.SimpleForm(

{

id: sId,

editable: true,

layout: "ColumnLayout",

labelSpanXL: 4,

labelSpanL: 5,

labelSpanM: 5,

labelSpanS: 12,

adjustLabelSpan: false,

emptySpanXL: 0,

emptySpanL: 2,

emptySpanM: 2,

emptySpanS: 0,

columnsXL: 2,

columnsL: 1,

columnsM: 1,

singleContainerFullSize: true

});

oSubSection.addBlock(oForm);

//Add content to form

var sPath = "test”

oForm.addContent(new sap.m.Label({

text: "{i18n>COMMENT_HR}"

}));

oForm.addContent(new sap.m.TextArea({

value: sPath,

enabled: false

}));

Francesco
Explorer
0 Kudos

Seems working, thanks alot!