Fluent API for inserting Controls

Posted by Community Admin on 03-Aug-2018 23:59

Fluent API for inserting Controls

All Replies

Posted by Community Admin on 09-Aug-2010 00:00

The Fluent API does not allow for the insertion of a Control into a Page Object.


I would like to see:

App.WorkWith().Page(myPage).Controls().add(MyControl, "placeholder")

Or something of that kind, so far the Controls() have no way of adding to a placeholder on a page.

Cheers
Lino

Posted by Community Admin on 10-Aug-2010 00:00

Yup second that! Need to be able to populate the page as well as create it :)

Just watched your fluent API screencast Lino, was a great intro, thanks!

Matt

Posted by Community Admin on 10-Aug-2010 00:00

Thanks a million Matt, I am glad you liked it :)

Hope to get to meet some day
Cheers
Lino

Posted by Community Admin on 11-Aug-2010 00:00

Hi Lino,

You are right, there is still no fluent api for that. We have plans to have this too :)
Actually the fluent API is there but it is not visible at this level for this facade. You may add controls on page creation:

App.WorkWith()
            .Page()
            .CreateNew() //create new page, working with Page facade
            .Do(p => p.Name = "Page1")
            .Control()   //access to Control facade
                .CreateNew() //Create new Control, working with Control facade
                .Do(c => c.Caption = "My New Control in placeholder1")
                .Do(c => c.PlaceHolder = "Placeholder1")
                .Done() //Exit the Control facade, we are now back to Page facade
            .Control()
                .CreateNew()
                .Do(c => c.Caption = "My New Control in placeholder2")
                .Do(c => c.PlaceHolder = "Placeholder1")
                .Done() //Exit the control facade
            .CreateNew() //will be called for the page facade
            .Do(p => p.Name = "Page2")
            .SaveChanges();

Sincerely yours,
Georgi
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2010 00:00

Thanks Georgi,


Yes that would be great!  I will wait until this is moved from protected to public as the current code you just sent will not compile because of the encapsulation.

.CreateNew() on a Page Facade is protected at the time being


Error 1 'Telerik.Sitefinity.Fluent.Pages.PageFacade.CreateNew(Telerik.Sitefinity.Pages.Model.PageNode, System.Guid, Telerik.Sitefinity.Pages.Model.PageData, Telerik.Sitefinity.Fluent.Pages.PageType)' is inaccessible due to its protection level

Posted by Community Admin on 11-Aug-2010 00:00

Hi Lino,

We are keep working on the API and makes some changes. We appreciate your input here and we will make the changes that will give you more flexibility using the API. Apart from that there is a way to add a control on a page to a given holder with standard API. You can use mgr.CreateControl<PageControl>(control, holderID). Then you can call PageNode.Page.Controls.Add(mycontrol); and save the changes with SaveChanges() of PageManager class.

Regards,
Ivan Dimitrov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2010 00:00

Thanks Ivan,


Much appreciated!
I will give it a try, thanks again.

Lino

Posted by Community Admin on 11-Aug-2010 00:00

Hi Lino,

Let me shed some light on the pages API. Actually the CreateNew(...) method is meant to be protected and I guess the example that Georgi wrote is a bit older. You should call CreateNewStandardPage() or CreateNewPageGroup() method to create new page. We are going to also introduce external page soon. The reason these are separate methods is because they return different facades. Although, in both cases we are working with page nodes both have very different characteristics, for example controls don't make sense for page groups.

Here is the correct code:

App.WorkWith()
   .Page()
   .CreateNewStandardPage() // returns standard page facade
      .Do(pn =>
      
        pn.Title = "My Test Page";
      )
      .CheckOut()    // creates a draft vresion and locks the page
         .Control()  // the fluent API allows adding conrols only to drafts
         .CreateNew(new Label() Text = "My Test Label" , "Content")
         .Done()
      .Publish()
      .SaveChanges();

Be aware that currently there is no easy way to control the order of the controls within a place holder with the API. This is due to the fact that the controls in a place holder can be mixed with controls coming from a chain of inherited page templates. Sitefinity allows you to insert controls between controls defined in a base template. Currently we rely on the UI layer to get information about the siblings of a control, but we are going to move this logic to the fluent API.
I hope this can help you better understand our ideas. We are open for suggestions and now is the best time for discussing the API design.

Greetings,
Bob
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

Posted by Community Admin on 11-Aug-2010 00:00

Thanks Bob,


Great to hear from you, hope all is well in Sofia :)

I get the idea of where the API is heading, I will send you an email with my findings and will also try to make some videos and blogs on the subject ASAP.

The code you sent unfortunately causes "Object reference not set to an instance of an object" when the CreateNew() on the control is introduced.  Maybe it is working for a build after the Beta?

Cheers
Lino

Posted by Community Admin on 12-Aug-2010 00:00

Hello Lino,

That's correct.. 
We'll have this in the Dev. Manual by the end of the week!

Sorry for the inconvenience. 

Greetings,
Georgi
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed