asp

Creating URL’s in Mono Rail

Posted on Март 6, 2008. Filed under: .net, asp, Castle project, coding, Monorail |

They got a very simple URLHelper for Castle Project, it is used like:

$UrlHelper.For("%{action='YourAction'}")

And it DOES NOT take additional parameters, like some «id» or sth in a form, that would not make you specify all special symbols, ‘=’, ‘?’ and ‘&’ .. I should mention lack of up-to-date documentation. After googling for some time I realized, it would be better to write my own one. (I hope, I did not reinvent the will) I called it MyUrlHelper, extending it from AbstractHelper. To use it with NVelocity, supply it with action (yes, it does not takes controller as a parameter now) and a dictionary as the second parameter:

$MyUrlHelper.For("YourAction", "%{id=$item.id}")

and it will output a correctly formed URL. Place it in «Helpers» directory under your VS project and name it MyUrlHelper (by default). Then in corresponding controller, the one that passes data to your views, write something like this:

[Helper(typeof(YourProjectNamespace.Helpers.MyUrlHelper))]
public class YourController : BaseController
{
}

and it’s gonna work. Be sure, you explicilty mention MyUrlHelper in HelperAttribute attached to the controller, otherwise it won’t work!
It can be used without any restrictions, download it from depositfiles.com

UPD: Well, it seems, I reinvented the will ;) I had I version of MonoRail v 1 RC3, that had non-virtual methods of UrlHelper, but accordingly to this forum thread http://forum.castleproject.org/viewtopic.php?p=11283 they made them virtual on about Dec 27, 2007.

Читать запись полностью | Make a Comment ( None so far )

Posted on Март 6, 2008. Filed under: .net, asp, Castle project, coding, Monorail |

I am building a real world web app with Castle Project right now. So, the debugging is done for IE. And I encountered two different things of interest:
1. Javascript-based form validation as it’s implemented for Castle Project does not work in Opera. Even more, pressing submit button in Opera causes a big stack trace of errors. Correct me, if I’m wrong, that’s because IE’s lack of standarts. I really
dont know what’s the problem is, because I’m not a tough javascript programmer.
2. IE automagically handles OPTION tag insertions into select lists. I have complex form, with a lot of selects, most of them have other selects as parents. E.g. City has District and Street as children. So I want to populate District and Street using ajax call invoked using onchange event hook of City select. I have two invocations for each one of the two. I pass District Select Id to the Ajax.Request object. And what I wanted to do was to simply get a lot of lines like

...
< value="district_id">district_name
...

by parsing my NVelocity template. And actually the code did return right list of options. But when it tried to insert them into District Select (with javascript using innerHTML property, I think. read about Prototype js library here) in IE 6 that resulted in messed tags (i use IE Developer Toolbar to see changes):

...
district_name<>< /option>< /option>< //option>
...

In Opera however, that didn’t happen and it worked just as it was expected to. So after 2 hours of trying to understand what’s going on, I found explanation to this. The thing is, MS does not allow option tag insertions without corresponding select tags. So, be concerned about this.

Читать запись полностью | Make a Comment ( None so far )

Make Monorail return right content-type header

Posted on Март 6, 2008. Filed under: .net, asp, Castle project, coding, javascript, Monorail |

Recently I had a task of adding some drag and drop abilities to a layer, representing chat window on a web page. Users can move it and resize it. I knew it to be a hard javascript task because the solution had to be crossbrowser. So I chose javascript library by walterzorn for it’s great customization features and fully documented process of installation. Using it is like this:

  <script type="text/javascript">  <!--

SET_DHTML('chat-window'+CURSOR_MOVE+RESIZABLE+TRANSPARENT+MINWIDTH+200+MINHEIGHT+150);  //-->

</script>  </body></html>

As you can see we are using only div layer Id to make it dragndroppable and also we use a set of predefined global constants that allow us to use some new abilities. Isn’t it great, you guys? But the installation documentation mention the fact this awesome library work only in HTML, not in XHTML (that’s really a contra with a lot of modern websites) because it uses document.write() which is not supported by XHTML specification. That’s why I needed my website to send Content-type: text/html header so that Firefox, Opera, Safari and others could use html 4.01 specification.. One can ask himself: why not using doctype and meta tag to specify specification (sorry for that one recursion)? The point is, those browsers judge the document by Content-Type header. Using great LiveHttpHeaders plugin for firefox I found out that there is application/xhtml+xml header returned from server. It turns out that if in Web.config I have

<viewEngines v iewPathRoot="Views">

<add xhtml="true" type="Castle.MonoRail.Framework.Views.NVelocity.NVelocityViewEngine, Castle.MonoRail.Framework.Views.NVelocity" />

then View layer of Monorail overrides any headers that I try to give it using Response.ContentType = «text/html»

The solution that makes monorail return «text/html» header is to set xhtml attribute to false. You still may not manipulate headers in arbitrary manner, but you can customize the behaviour choosing between «application/xhtml+xml» and «text/html».

Читать запись полностью | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...