Dot.Nut

Friday, January 20, 2006

DataSources in .net 2.0

It is damn ez in asp.net 2.0 to access data, thanks to the DataSource controls. There are the AccessDataSource for access databases, SqlDataSource for ANY OLE-DB compliant database, XmlDataSource for accessing XML data, and ObjectDataSource for biz objects (more on this later).

Any newbie can now juz drag a DataSource control from the toolbox and follow the wizard steps, and then choose the data-bound control and select this DataSource, and wham~ it is bound. no events, codes or anything to be written manually. All the settings are in the aspx, written by VS2005, including Select, Update, Delete and Insert statements. Even caching is supported intrinsicly by juz setting EnableCaching="true" in the datasource (SqlDataSource). damn.

But for more advanced apps which require n-tier, this might not be a best practice, especially the part where SQL is embedded directly in aspx. Well, the ObjectDataSource control is there for this purpose, which binds to biz objects. ObjectDataSource is in a later chapter, so after i go thru it, i will post my comments here :)

MasterPages in .net 2.0

When doing html for the websites, it is common to have a constant look and feel across pages, like header, menubar and footer. Having to make a change on a layout across all pages wasted time and it was common for developers to create include files for these pages. So the developer only had to update the include file to reflect the change across all pages. But include files were messy, non-standard and not supported in many visual IDEs.

MasterPages in .net 2.0 serves this issue well. It is essentially a control with contentplaceholder regions that "contain" other content pages, which could specify a MasterPageFile to dervive its container html from. the content page simply specify a master file to use, and use a content control with a matching ContentPlaceHolder ID as the master file's, then its all set to go. VS2005 supports masterpages in designer view out-of-the-box, but only for non-nested master pages.

Things to note:
  • MasterPages can nest, but designer view in VS2005 doesnt support
  • A Content control in a content page must have a matching ContentPlaceHolder ID with one of the ContentPlaceHolders the specified MasterPageFile
  • Content Page_Load fires 1st, then Master Page_Load > Content Control Events > Master Control Events
  • A Content page can access public properties defined in a master file. Use ((MasterPage)this.master).property or this.master.property if a <%@ MasterType TypeName="MasterPage" %> directive is specified in aspx.

Wednesday, January 18, 2006

my "1st" look at vs2005 and vwd.

well, here i go with my dive into asp.net 2.0. I absolutely loved .net 1.1, esp after my j2ee project, wahaha... lots of cool stuff which make my php frens go "that's cheating!!" well not everything about .net 1.1 was sweet for me... i came from a web designer background in dreamweaver and was very particular about my html code and layout. thing is, vs2003 kept "sync-ing" the HTML source with its own convention (all those MS-POSITIONING thingie) and made my head go bust. so in the end i used sharpdevelop, combo-ed with dreamweaver and CLRDebugger to develop web apps... haha, which was really slowing my progress, but still less troublesome then changing my html code all the time i update something on a form.

vs2005 kept its promise on not sync-ing the HTML wilfully! this was really a saving grace. on this point alone i could switch back to vs, but there are other cool stuff as well. now the designer and source view is click-sync, means the cursor goes to whichever line of html the designer has its focus on... intellisense is everywhere, yippee.

And the new code-behind model using partial classes is splendid! a net1.1 developer using vs2003 might not notice, but using code-behind without vs2003 was nightmare-ish... one side was the benefit of clear design-code separation, but the code-behind files done manually had to declare ALL of the controls used by the webform and kept in sync with any changes. partial class no longer has to account for this, making the code-behind file cleaner.

Other stuff in vs2005 include test server, mssql 2005 express, and so on and so on. well, i wun touch any stuff i am not experienced in... my next dive will be into masterpages, something i frequently used in .net 1.1 via wilson's masterpages, now integrated as a .net standard control :)

Nutting on this side of the blog?

Well, seeing my last post on this blog was on my skoo project using J2EE, really gives me ill feelings to write somemore.... haha. truth is I escaped from the "computer world" for a while to TW and have fun... look at my chiap blog for more info!

Well, I've graduated from my computing course and now am hunting for a job... guess i am taking my time huh... well, better find something i like than rush into something available and end up complaining all the time :P

Then, thanks to a prompt from shinchi, I've decided to take on the beta upgrade exam for MCPD web developer... since it's free and it counts to MCPD for existing MCADs, well hack why not. thing is, there isnt any study guide nor training course for this exam available yet (hence beta exam huh), and i haven't touch .Net for a while and a little rusty... further more the exam's for .Net 2.0 which I havent touch at all... damn.

So, I gotten myself a book on asp.net 2.0 to push myself to "catchup" to fellow developers (shit i hate the word fellow developers, makes me look dead-end)... murach's asp.net 2.0 upgrader's guide. It's good for any existing .net programmer i guess. simple to follow, clear examples and lists out lots of tips and notes. Well, if u wondering why i couldn't juz find some online materials on msdn or such, i am a lazy person who cannot read off the screen... yes, for a developer i cannot read off the stupid computer screen... damn my eyes hurt.

so, i will be posting stuff on this blog more often now, adding notes per chapter i go thru to remind myself on stuff and helping me for the exam!

Friday, November 11, 2005

3 cheers for creator~

Sun Java Studio Creator (formerly known as Project RAVE) delivers these benefits and helps you to create two-tier web applications that conform to the Java 2 Platform, Enterprise Edition (J2EE) BluePrints. In addition, Sun Java Studio Creator simplifies and streamlines access to databases and web services from behind dynamic HTML user interfaces as easy as drag and drop.

With this easy-to use development environment, you can focus on quickly designing user interfaces and coding business logic. Creator is a full-fledged Java development environment that simplifies coding with a rapid visual designer, a smart code editor, synchronized editing, source code management, and easy deployment features.

Oh yeah. that's wat we believed in during the start of our J2EE project. drag-n-drop, faces components integrated support, easy as that.

When creating a 1-2 page example, sure. all i had to do was to drag an inputText component into the page and viola, it appears there. cool. Wait till we have 20... 50... 100+ pages... Hey, wat's taking studio creator so long to load? 2-3mins passed. no news. crap. oh. it's scanning for files and changes i think. hmm. i think i want to remove a file inside a folder. right-click and press delete, simple as that! hey, why isn't creator responding? oh. 10mins passed. i think i better end task. oh. gotta wait for creator to load again. yippee.

I think i want to add a html table inside creator to layout my components... hey? how do i add a table? damn. drap-n-drop for the faces components. html? type in code view brother. hey, my design view for the page is gone! damn. guess i better type all in code view to save trouble. since it has auto code completion right? saves me trouble, all i have to do is type a space and.... hey, how come there's nothing for faces tags? oh. only have code completion for normal html. crap. but i can't see my design view! how am i gonna add my faces components then? hmm. guess i have to type it all by myself while referencing the api from sun... hey, then wats the difference from using notepad?

For a big project, luckily i have my teammates to share the burden.... each person develop a module, and pass the codes to one another. simple. got any updates, all i have to do is get the updated files from a teammate, update it inside the project folder, and creator will auto update for me.... yippee. build, deploy... hey! its still the old code!! wat happened? i overwrote them in the folder... how come its still the old files??? damn. creator seem to keep a cache of files *somewhere*, and it uses back the old ones! crap. i guess i have to open up each file that my teammate developed, open up mine, copy-paste his codes into my file explicitly for creator to see this code is wat i want!

Faces components are really useful. all kinds of regularly-used controls like textboxes, buttons all integrated inside the creator ui... ok. i need a file upload for this page... now wheres that fileupload faces component.... hey? dun have? oh! there isn't an upload component! damn. wonder how others do this... go check out the useful sun tutorials.. hmm cannot find. go to sun forums, wow! java programmers are really cool! many of them write their own fileupload custom component. wow. wonder if anyone cared to share how they do this? hmm. noone posted any examples. damn. i'm a java newbie... dun know how to build this custom component... well, i guess the class JSTL must have a fileupload i can use! Yes! wait till i integrate this into my faces page.... wait! cannot use JSTL together with faces components on a same page?? oh no! wat am i going to do?? guess i have to use a popup window that contains the JSTL without ANY jsf, then use some javascript hack to get the value back to the faces page! wow. wat a newbie i am...

hmm. Maybe its becos i am a newbie? thats why i take on average 2-3hours to create a simple module... if i have more time, i will post more escapades of my newbie experiences with creator!

Sunday, October 30, 2005

A label for my thoughts...

In asp.net, it was common to have a label web control somewhere in my page that i will update upon performing some server action (eg update to db, delete a record, etc)... all i had to do was do it on my button click event, etc, like:

protected void Button_Click(Object obj, EventArgs e) {
// some action to update
myLabel.Text = "Some action performed!";
}


and it works all the time. yippee. fast and simple.

In java server faces, there was also an equivalent (i think) in the form of a outputText face component. It also has a setValue() method to update its value. So it was natural for me to do the same in .net style, given my liking for .net:

public String Button_Action() {
// some action to update
myOutputText.setValue("Some action performed!");

return null;
}


problem is, this doesn't work in jsf all the time! Some pages work, some dun. It really took me a long time to figure out wat was wrong... such a simple thing i wanted to do, but there was no error, no exception, nothing to tell me wat went wrong...

Until i realize it was "standard" to attach something called an actionListener, that i should attach to the outputText tag, so that it will execute everytime some action occurs:

// in my jsp:
<h:outputtext id="myLabel" actionlistener="#{backingBean.myListener}" ...>

// in my backing bean
public void myListener(ActionEvent ae) {
myLabel.setValue("some action perform!");
}


then only can i get the status to be displayed correctly everytime! Does that mean i have to create 10 actionListeners for 10 different status messages??

Sunday, October 23, 2005

The back button!!

Our team is currently on a j2ee project with jsf using studio creator. Fun. Due to some mechanism with the "session" scope and "request" scope thingie, we often run into problems when the user navigates to a listing page, clicks on link A, goes to page A, then presses the back button to go back to listing page, clicks on link B, but still page A shows up!! It seems that the listing page has its request cached inside, so by pressing the back button on the browser and clicking on ANY link will result in the browser resubmitting the cached request! so what we have to do is to:

create a back button/link inside the page A that allows the browser to clear the cached request and create a new and correct request.

But: some pages do not come from just a single listing page! does that mean we have to create X links for X pages where page A comes from? no way!

New post! sorta...

I've decided to create another blog to complain about my projects, work and programming crap! esp my escapades with dot.net and hatred for j2ee! remember, its http://pchia.blogspot.com!

If you are not programming siao, or entered by mistake, go to my ChiaP blog instead! thats where i complain about life, love (huh?) and crap hahaha.