cancel
Showing results for 
Search instead for 
Did you mean: 

Couldnt accesss 2nd fragment values from controller.

0 Kudos
327

Hi,

I'm creating custom F4 help screens same as Smart Field with Value Help.

UI screen flow is from view1.view.xml->fragment1->fragment2.

For both fragment1 & fragment2, im calling from view1.controller.js and i had used addDependent().

However i'm struck while accessing fragment2 UI element values in view1.controller.js and couldnt add a panel to fragement2 dyanamically.

Any advice is deeply appreciated.

PS: Please find attached screenshot for reference.

Regards,

Natarajan

maheshpalavalli
Active Contributor
0 Kudos

It looks like there is no issue with the approach you are are following, you should provide the code that you have written to analyze the error like the places where you are instatiating the fragment and where you are trying to read the data.

BR, Mahesh

Accepted Solutions (1)

Accepted Solutions (1)

ericci
Active Contributor
0 Kudos

Usually, the problem is no about the addDependent. That method allows you to add the control (in this case the fragment/dialog) to the current view lifecycle. It means that the control will react to the same event of the view. So when you destroy the view, the fragment/dialog will be automatically destroyed.

I think that the issue is when you create the fragment. Here's a snippet of code that will help you:

		onSalesOrderItemDialogOpen: function(bFromCreate, oItemBindingContextPath) {
			this._fromCreate = bFromCreate;	
			this.getView().getModel("data").setProperty("/salesOrderItemFormCreate", bFromCreate);
			
			if (!this._oEditDialog) {
				this._oEditDialog = sap.ui.xmlfragment(this.getView().getId(), "com.techedge.training.SAPUI5Training.view.fragment.dialog.SaleOrderItemEditDialog", this);
				this.getView().addDependent(this._oEditDialog);
			}
			
			this._oEditDialog.bindElement( oItemBindingContextPath );
			// toggle compact style
			jQuery.sap.syncStyleClass("sapUiSizeCompact", this.getView(), this._oEditDialog);
			this._oEditDialog.open();
		},

As you can see when I create the sap.ui.xmlfragment I'm passing to it three parametes. The first one is the one that you need to specify. It is the view ID. This is is foundamental when in your controller you want to retrieve a fragment element with an ID. If you don't specify the view ID the this.getView().byId() will not work.

Answers (1)

Answers (1)

junwu
Active Contributor
0 Kudos

https://ui5.sap.com/#/topic/5da591c5a5a54740948acfe56b22fbc3

study that chapter to understand what you are missing......