1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Custom Metafield in newsView

Custom Metafield in newsView

5 posts, 0 answered
  1. KMac
    KMac avatar
    133 posts
    Registered:
    15 Dec 2008
    08 May 2009
    Link to this post
    Hello,

    I've created a custom datefield in a newsview that I want to be optional. I've added the necessary web.config entries, added the raddatetimepicker to the admin interface and added a literal to the public control template. Everything works fine until I try to view the public side. I get: 

    Object reference not set to an instance of an object.

    The reason this is happening is I already had some news items created before adding the custom metafield and they are obviously all null. If I go back and edit all of them to have a date in them all works fine, but I don't want to have a date in all of them only certain ones that need it. The rest I'd like to keep null. Is something I'm missing here because obviously it's ok to have null items for other fields like Author or Summary?
  2. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    09 May 2009
    Link to this post
    Hello Kalvin MacLeod,

    Meta data can't be null, it either exists or doesn't exist. However, UI elements that show meta data can be optional.

    We initialize the metafields controls with something like:
    For every metafield in the provider, if there is a control with the same id, extract its value.

    We save in much the same manner:
    For every mandatory mentafield in the provider, get its control and save its value.

    Mandatory are all fields that are declared as such in web.config.

    The above was about the admin part.

    Here is what applies to ContentView-based controls:
    according to the metafield type, the following control must be used:
    • ShortText or LongText: either ITextControl or HyperLink
    • DateTime: Telerik.Cms.Web.UI.DateTimeLiteral or ITextControl
    ContentView tries to find a control with the appropriate type and id, but if it doesn't it should throw no exceptions. I spent a lot of time analysing the code and didn't find any potential problems.

    Perhaps if you gave us a step-by-step instructions on how to reproduce the exception, we wil be able to find a solution for your problem.

    Greetings,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. KMac
    KMac avatar
    133 posts
    Registered:
    15 Dec 2008
    11 May 2009
    Link to this post
    Hi Dido,

    This happens on a previously populated set of news items. I wanted to add a new date field where there wasn't one before, so all the old items do not have any information for this new field.

    Here's what I did:

    Added the metafield tag to the web.config:

    <add key="News.CaseLaw_Date" valueType="DateTime" visible="True" searchable="True" sortable="True" defaultValue="#Now"/>

    On the Admin side, I copied the NewsItemEdit and NewsItemInsert from the Embedded Templates, modified the controlsConfig.xml file and adding the following radDateTimePicker to each like so:

    <li><asp:Label ID="Label9" AssociatedControlID="CaseLaw_Date" runat="server">

     

     

     

     

     

    <asp:Literal ID="Literal3" runat="server" Text="Case Law Date"></asp:Literal>

     

     

     

     

     

    <em id="Em2" runat="server"></em></asp:Label>

     

     

     

     

     

    <telerik:RadDateTimePicker ID="CaseLaw_Date" runat="server" ToolTip="Date">

     

     

     

     

     

    </telerik:RadDateTimePicker>

     

     

     

     

     

    </li>

    At this point everything works fine. I can go in and edit the news items and add pick a case law date.

    But when I try to add the following to a customized Sitefinity-->ControlTemplates-->News-->Modes-->ListPageMaster.ascx control I get the error stated previously: 

    <asp:Literal ID="CaseLaw_Date" runat="server" Text="{0}" />

    So basically I just want to show the CaseLaw_Date on the public side and if there is no date chosen (like the old news entries) show nothing and if there is a date available (like news items going forward) show it.

     

  4. Dido
    Dido avatar
    149 posts
    Registered:
    24 Sep 2012
    12 May 2009
    Link to this post
    Hi Kalvin MacLeod,

    I can't reproduce the error. Would you send me your web.config, ConstrolsConfig, database, the three templates (master mode, edit /create news item) and a screen shot of the error. You can attach files if you open a support ticket.

    Regards,
    Dido
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. KMac
    KMac avatar
    133 posts
    Registered:
    15 Dec 2008
    12 May 2009
    Link to this post
    Thanks Dido,

    I upgraded to the latest version and the problem went away. Case closed.
Register for webinar
5 posts, 0 answered