Stupid Funny HTML Thing: “option” tag’s “selected” attribute usage

4 11 2009

I do know that the HTML is no longer interesting for the major half of the developers but still sometimes you need to use it. Yesterday I’ve encountered one thing that after reading specs made me laugh a lot. I’m talking about “selected” attribute of the “option” tag.
In any programming language (any general language for logical people) normal usage of attributes that are meant by their nature to bee boolean is having 2 possible values to be set: true or false.

“selected” attribute in HTML is a bit different :) To not write a lot here is a receipt:

Specifies that this option will be pre-selected when the user first loads the page.

This is a boolean attribute. If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace (i.e. either selected or selected="selected").

Possible values:

    * [Empty string]
    * selected

So you either specify

<option value="fuck" selected="selected">it</option>

if you want this option to be selected or you should miss the attribute at all. I think this should have been a joke from the dude who created this ))

UPDATE:

I would not post this if this inconvenience did not impact the thing I am doing. It imapcts so I decided to write a little JSP custom tag that fixes the problem in a nice way:

@SuppressWarnings("serial")
public class OptionsTag extends TagSupport {

	public void setDataProvider(List value)
	{
		this.dataProvider = value;
	}

	public void setItemToSelect(DataItem value)
	{
		this.itemToSelect = value;
	}

	public int doStartTag()
	{
		try
		{
			JspWriter out = pageContext.getOut();
			String selected;
			for(DataItem item: dataProvider)
			{
				if (itemToSelect != null)
				{
					selected = itemToSelect.isEqual(item)?"selected='selected'":"";
				}
				else
				{
					selected = "";
				}
				out.println("" + item.getName() + "");
			}
		}
		catch (IOException ioe)
		{
			ioe.printStackTrace();
		}
		return Tag.SKIP_BODY;
	}

	private List dataProvider;
	private DataItem itemToSelect;
}

The usage of the tag in JSPs is straightforward:

<c:if test=”<%=activityCategories!=null%>”>
<select name=”categoryId”>
<components:options dataProvider=”<%=activityCategories%>” itemToSelect=”<%=currentActivityCategory%>”/>
</select>
</c:if>





Quality

6 10 2009

Almost in any technology a developer use there are some “context” objects where you can put some values using methods like “context.setAttribute(key, value)”.

If I needed to qualify some developer’s work qaulity I would check if he clears up those attributes from the context when they are not needed anymore. I am sure 80% of developers do not bother with this.





How Twitter Guys Do Things Smart

9 09 2009

There are a lot of thins you don’t notice or analyze deeply enough until they cross into your area.

I am using Twitter few months already and I never though of why they don’t show the exact time of the tweet but instead shows something like “Posted XX minutes ago…”. Undoubtely this is good way of expressing what the end users need, since I don’t need to know exactly when my friend posted a tweet.

But after I’ve played a bit with times, time zones and date formatters in Java I found out that there is no nice way of determination the client time zone on the server. HTTP request for some unknown reason does not provide any headers for this purpose and that is why a lot of web-apps prompts you to enter your time zone when you first log in.

The only way to do the thing is to use Java Script on the client to determine the time zone and pass this info in the request. But even then you have a lot of shit with DST and other stuff.

Someone in the Twiiter team perfectly resolved the problem by suggesting that users will be happy with knowing how many minutes ago the post was written. That is much more easier to implement. Wonderful :)





Operators overloading in C#: good and bad examples

23 06 2009

While reading “CLR via C#” of Jeffrey Richter, which I must say is a great book,  I’ve come up to the section dedicated to operators overloading. I think this is quite interesting feature of the language and it can be very practical. Mr. Jeffrey has delved into very specific details of how Microsoft recommends to design operators overloading and what is his personal opinion but somehow I was not able to get the clear view on the topic. Instead I found a very short and practical article here: http://www.csharphelp.com/archives/archive135.html

I think all authors should focus first on the topic itself and only then on their critics about how Microsoft or other compilers/languages producers do their job.





Be Careful with Renderers

17 06 2009

After we added one fancy renderer to ADG to highlight our search results in case user performed a search I noticed that vertical scrolling slowed down way too much.

After some investigation we found the culprit: in case when no search was performed the renderer filled the cells with white solid fill using beginFill() and endFill(). We substituted this to just graphics.clear() and everything was fixed. So it appears that beginFill() – endFill() is quite expensive though primitive operation. Not funny :)





The First Law of Software Development

3 06 2009

Today I have produced the first funny law of software development: if you’ve got to deal with a hairy DB then no matter of your effort you’d get a hairy application :)





FX -> SL

22 05 2009

It seems to me folks that I will start mastering Silver Light.

I’ve invested few hours of my time just to read as much of possible forums, etc. as I could to see what community is thinking.

Multiplying it by everything I’ve heard from the guys I’m working with the conclusion is to install all needed staff and start coding for SL. Seems it is already mature enough for not being a headache.





Focus Management for UI Components

3 03 2009

A very simple post, just in case if someone will have the same problem.

I’ve got a screen, actually a form with a sequence of UI components, some are standard flex components like TextArea and some are custom. One custom component was ignored while user used “Tab” key to navigate from one field of the form to another.

I wanted to fix it very fast and started with hacks like adding an event listener to the previous component’s focusOut event and calling setFocus() method of that custom component. But that was not working like it should so I went to the Adobe Help and found out a very simple and proper fix: what ever your component is, if it inherits from UIComponent you can just add an implements IFocusManagerComponent instruction and current FocusManager which deals with the focus management on the form will handle your custom component in a standard nice way:

focus-management

This all works very simple when you understand that focus management in Flex seems to be design using the Composite pattern. Thanks Max for noticing this.

You can read here about the IFocus Manager component.

Cheers





A Door, a Ladder or Just a Hole?

25 02 2009

The subject I will describe few lines below is very simple from one point of view and at the same time it needs a lot of reflection to evaluate possible answers.
In software development EVERYTHING can be implemented in various ways. Somehow developers always choose one certain solution and implement it. How do they know if the solution chosen is the best one? Or let’s rephrase it, do they know that there were other possible ways to go? :p

I will describe one very simple case that can appear at almost any average project.
Suppose you have a CarDiller service which can return you a list of cars available for selling.
So somewhere there is a method CarDiller.getCars(): List

Everything works nice but some day your customer tells you “Listen to me, son, it would be nice if we have one more page on our site where we show only cars for girls. Can we do this?”.
Of course you will tell “Yes, we can”. I don’t doubt you can, do I? ))
The question is HOW will you do it.
At the very surface I already see 3 possible ways:

  1. A door:
    We extend backend method and it becomes CarDiller.getCars(girls: Boolean): List
    Then in one plays we call CarDillers.getCars(GIRLS) and in other place we call CarDiller.getCars(ALL)
  2. A ladder:
    We create one more backend service method: CarDiller.getCarsForGirls():List and use just it where needed
  3. Just a Hole
    We can do everything on the client. I mean filter cars that are good for girls from the bulk of all cars.

Maybe there are more ways but for now even these three are pretty enough.
I would like to hear some smart people in comments telling me pros/cons of each of 3 solutions. I am not an idiot and can write a lot about such pros/cons but maybe there are ways to determine in general which solution would be always BEST, no matter of particular details. Or there are no such abstract criterias?





Image Objects Recognition

24 02 2009

I’ve tried to implemetn a program that can recognized separate objects on the image with a single white background. For example a text is a pretty candidate for such thing.

First version is not yet ideal but it already can be useful for making some funny animation stuff.

To give you the impression what it can do here is a screenshot that shows which “objects” it can already recognize:

Recognized objects

Recognized objects

It merges some symbols together but I will fix it soon :)