More in this section

Forums / General Discussions / Fluent API for inserting Controls

Fluent API for inserting Controls

10 posts, 0 answered
  1. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    09 Aug 2010
    Link to this post
    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
  2. mattc
    mattc avatar
    105 posts
    Registered:
    11 Aug 2007
    10 Aug 2010
    Link to this post
    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
  3. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    10 Aug 2010
    Link to this post
    Thanks a million Matt, I am glad you liked it :)
    Hope to get to meet some day
    Cheers
    Lino
  4. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    11 Aug 2010
    Link to this post
    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
  5. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    11 Aug 2010
    Link to this post
    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

  6. Ivan Dimitrov
    Ivan Dimitrov avatar
    16072 posts
    Registered:
    12 Sep 2017
    11 Aug 2010
    Link to this post
    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
  7. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    11 Aug 2010
    Link to this post
    Thanks Ivan,

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

    Lino
  8. Bob
    Bob avatar
    330 posts
    Registered:
    30 Dec 2016
    11 Aug 2010
    Link to this post
    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
  9. Lino
    Lino avatar
    45 posts
    Registered:
    06 May 2005
    11 Aug 2010
    Link to this post
    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
  10. Georgi
    Georgi avatar
    3583 posts
    Registered:
    28 Oct 2016
    12 Aug 2010
    Link to this post
    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
10 posts, 0 answered