Skip to Content
avatar image
Former Member

when to put text and layout data in new control

Hi ,

I've created new control via extend and I want to know where should I put the text:... and layoutData

Here how its done in regular way

var oTitle = new sap.ui.core.Title({

                    text: "{i18n>title_test}",

                    layoutData: new sap.ui.layout.GridData({

                        span: "L12 M12 S12"

                    })

                });

I've composite control which I use the title like following and I need to applay both the layout and text

extend....

metadata: { aggregations: { title: { type: "sap.ui.core.Title", multiple: false },
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    avatar image
    Former Member
    Nov 03, 2015 at 07:42 AM

    Hey Joerg Ben

    Adding that title as a public aggregation to your control means that any user using your control can go ahead and add any entire sap.ui.core.Title with or without specified layout data. So if your control's name is MyCustomControl and they want to specify a title for it, they will do the following:


    var customControl = new MyCustomControl();

    customControl.setAggregation('title',

    {

         new sap.ui.core.Title({text: "{i18n>title_test}"});

    })


    If you want the title element to specifically have that layoutData and just want a user to specify the text part it might be better to make that aggregation private and do the following in your init function of your custom control :

    this.setAggregation('_title',

    {

         new sap.ui.core.Title(

         {

                   layoutData: new sap.ui.layout.GridData(

                   {

                            span: "L12 M12 S12"

                   })

         });

    })

    In your metadata specify a new property:

    metadata:

    {

         properties:

         {

              "titleText" : {type : "string", defaultValue: "Title"}

         }

    }

    Then a user can do the followiing:

    var customControl = new MyCustomControl();

    customControl.setTitleText("I want this Title");


    In your control just remember to set the specified text now in the titleText property to your Title aggregate.

    This can be done in the render function of your control:


    Add comment
    10|10000 characters needed characters exceeded

  • Nov 03, 2015 at 04:39 AM

    I do not see that you need to reapply the text and layout. Maybe you can shed some lights on what you wish to do.

    -D

    Add comment
    10|10000 characters needed characters exceeded

    • HI Joerg

      sap.ui.core.Title is not a control. It is an element. That's it does not have a renderer. It does not know how to render itself.

      What do you want the composite control to do?

      Thanks

      -D

  • avatar image
    Former Member
    Nov 02, 2015 at 08:32 PM

    HI All,

    Any Idea how to achieve them?

    Thanks!

    Add comment
    10|10000 characters needed characters exceeded