Thanks, jumping in for help.
I tried your given code, i found that the page html source doesnt has any element with a name '#messages'. As per my understanding, its the apex engine which checks for any error, if found it shows it by adding an element id '#messages', but here on my requirement its not the apex engine which has detected the error, its my functional logic which wants to report a message. On a normal and error free page condition, we usually dont find '#message' element. I'm curious on how apex inbuilt engine is reporting an error to a page?