Web Part exposing user editable properties possible?

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

Please do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.

This forum is for discussing mojoPortal development

This forum is only for questions or discussions about working with the mojoPortal source code in Visual Studio, obtaining the source code from the repository, developing custom features, etc. If your question is not along these lines this is not the right forum. Please try to post your question in the appropriate forum.

You can monitor commits to the repository from this page. We also recommend developers to subscribe to email notifications in the developer forum as occasionally important things are announced.

Before posting questions here you might want to review the developer documentation.

Do not post questions about design, CSS, or skinning here. Use the Help With Skins Forum for those questions.
This thread is closed to new posts. You must sign in to post in the forums.
3/26/2007 6:57:13 AM
Gravatar
Total Posts 2

Web Part exposing user editable properties possible?

Hallo Joe,

I have just stumbled upon mojoPortal and wanted to check out a few thing - so far I must say I'm impressed with your work!
Is it possible to use webparts that have user editable properties exposed? I have tried to get my own web part into the system - which has been very easy thanks to the import mechanism - but I have not found a way to edit the web parts properties.

I have included a sample source code for a property and for my basic rss reader web part.

Thanks again for your great work and dedication - it is really appreciated!
Chris

// sample code for a useder editable property

[Personalizable, WebBrowsable, WebDescription("Number of articles to be displayed")]
public int ItemCount
{
get { return itemCount; }
set { itemCount = value; }
}


// Here is my code for a very basic sample webpart:

using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;

namespace tripunkt.dbToolkit.Portal.WebParts
{
public class TriRssWebPart : WebPart
{
private string rssUrl;
private int itemCount;
private bool blShowImage;
private bool blShowDescription;

public TriRssWebPart()
{
this.Title = "Christophers demo Newsfeed Webpart";
this.AllowClose = true;
this.AllowMinimize = true;
}

[Personalizable, WebBrowsable, WebDescription("Show Feed Image")]
public bool ShowImage
{
get { return blShowImage; }
set { blShowImage = value; }
}

[Personalizable, WebBrowsable, WebDescription("Show Feed Description")]
public bool ShowDesciption
{
get { return blShowDescription; }
set { blShowDescription = value; }
}


[Personalizable, WebBrowsable, WebDescription("Number of articles to be displayed")]
public int ItemCount
{
get { return itemCount; }
set { itemCount = value; }
}

[Personalizable, WebBrowsable, WebDescription("URL of the RSS Feed")]
public string RssUrl
{
get { return rssUrl; }
set { rssUrl = value; }
}

[Personalizable, WebBrowsable]
public override Unit Height
{
get
{
return base.Height;
}
set
{
base.Height = value;
}
}

[Personalizable, WebBrowsable]
public override Unit Width
{
get
{
return base.Width;
}
set
{
base.Width = value;
}
}


private string GetContent()
{
StringBuilder sb = new StringBuilder();
//sb.Append(string.Format("Zeige {0} Artikel von Feed {1} an.", itemCount, rssUrl));
XmlDocument doc = new XmlDocument();
try
{
doc.Load(rssUrl);
}
catch (Exception e)
{
return string.Format("<b>Document {0} could not be loaded.</b>", rssUrl);
}
XmlElement root = doc.DocumentElement;

foreach (XmlNode channel in root.ChildNodes)
{
try
{
string channelTitle = channel["title"].InnerText;
//sb.Append("<b>" + channelTitle + "</b>");
this.Title = channelTitle;

}
catch (Exception ex) { }
if (blShowImage)
{
try
{
sb.Append(" <center><img src=\"" + channel["image"]["url"].InnerText + "\"></center><br/>");
}
catch (Exception ex) { }
}
if (blShowDescription)
{
try
{
sb.Append("<small>" + channel["description"].InnerText + "</small><br/>");
}
catch (Exception ex) { }
}
//sb.Append("</br>");
sb.Append("<ul>");

int count = itemCount;

foreach (XmlNode item in channel.ChildNodes)
{


if (item.LocalName.Equals("item") == false)
continue;

if (count < 1)
break;
count--;

sb.Append("<li>");
try
{
sb.Append("<small><b>" + item["title"].InnerText + "</b></small>");
}
catch (Exception ex) { }

try
{
sb.Append("<br/><small>" + item["description"].InnerText + "</small>");
}
catch (Exception ex) { }
try
{
sb.Append(" <small><a href = \"" + item["link"].InnerText + "\">[...]</a></small>");
}
catch (Exception ex) { }
try
{
sb.Append(" <small><a href = \"" + item["enclosure"].Attributes["url"].InnerText + "\">[->]</a></small>");
}
catch (Exception ex) { }

sb.Append("</li>");

}
sb.Append("</ul>");
}
return sb.ToString();
}

protected override void CreateChildControls()
{
{
Controls.Clear();
Literal literal = new Literal();
literal.Text = GetContent();
this.Controls.Add(literal);
ChildControlsCreated = true;
}
}

protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)
{
base.RenderContents(writer);
}
}
}
3/26/2007 7:55:09 AM
Gravatar
Total Posts 18439

Re: Web Part exposing user editable properties possible?

Hi Chris,

I will use your sample and try to get this working. I'll post here again once I have results.

Thanks,

Joe
3/26/2007 11:57:08 AM
Gravatar
Total Posts 18439

Re: Web Part exposing user editable properties possible?

Hi Chris,

I got this working and committed the changes to svn branches/2.x

Can you do a checkout and confirm that it works as expected?
If not I'll try to package up a new set of release files soon.

Thanks,

Joe
3/27/2007 12:28:36 PM
Gravatar
Total Posts 2

Re: Web Part exposing user editable properties possible?

Hi Joe,

I checked it out - I must admit what I see is pretty cool :) - my web part works as expected. I like the idea of web part support because it lessens the dependence on the underlying portal framework and developers don't need to adjust and recompile the source code for different portal systems.
However the customization seems to work only on the MyPage site - is it possible to edit the properties in the webpart-container on the other pages as well?

Thanks you
Chris


3/28/2007 5:50:14 PM
Gravatar
Total Posts 18439

Re: Web Part exposing user editable properties possible?

Hi Chris,

I'm not sure there is a good way to do that because there is no web part manager or web part zones on the other pages. I'll have to ponder that but no easy way to do that comes right to mind.

Joe
You must sign in to post in the forums. This thread is closed to new posts.