On Tue, January 18, 2005 1:56 pm, Peter Wu said: >> With Struts, there is no separation of page prep and control events. In >> other words, if you want to submit to the server to update your >> calendar, >> you will be responsible for rendering the rest of the page, including >> any input the user might have made since the last trip to the server. > > Does it mean that a control needs to be aware of other possible controls > when > being rendered? It seems it is not quite OO.
Well, I think it might be helpful to step back even further... If your not going to go with JSF, it might be helpful to not even think in terms of controls, but just straight HTML. Regardless of whether we're talking JSP/Struts/Java or ASP.Net, in the end it renders as HTML on the browser. The beauty of ASP.Net (and JSF from what I know of it) is that it serves as something of an abstraction layer above HTML in a sense... You drag a control onto a designer form, and "something underneath" knows how to render that control as HTML. But, absent something like ASP.Net or JSF, that "something" is generally YOU :) I don't think I'm telling you anything you don't know by the way, but because you keep using the word "control" to refer to the calendar, that leads me to believe you have a certain mindset, and it might be helpful to change that mindset :) To answer your specific question though about controls knowing about each other... The short answer is no, they don't really have to know about each other, because a control in this context really boils down to a chunk of HTML. If you have some HTML (and some scripting along with it) representing a calendar, it only has to know about other controls if that's what your application requires. If it's just a calendar for a user to select a date, and it doesn't affect anything else in the UI, then no, it can exist ignorant of everything around it. But... when you submit the form to the server to update the calendar, EVERYTHING ELSE on the page has to be aware of itself, in a sense... Imagine a page in your browser where you have your calendar, and two other text fields for First Name and Last Name (let's say the calendar is date of birth). None of those fields are related really, as far as the UI and user interaction goes. Now, when you change the month on the calendar, you want to submit to the server to update it. But, what about the other two fields? What if the user entered something in them already? Assuming they are part of the same form as the calendar, they will be submitted with the request. You of course want to show the same page, with the calendar updated, and with what the user entered still in those two text boxes. It is your code that will be responsible for this. It might be as simple as letting Struts to it's thing: the ActionForm will be populated with the two text values, assuming everything is set up and coded properly, so in your JSP you can just fill in the value from the ActionForm into those fields. Things will work as expected then. This is sort of automatic, but in ASP.Net (and JSF as I understand it), your code would just worry about the calendar change, even the part in the JSP where you fill in the text fields will be done automatically (or can be anyway). Argh, that was long and rambling :) Not sure it was very helpful either! >> (1) Do the calendar work client-side. > > I want to go for this approach. I'm thinking of creating such a control. > Let's > take the Calendar in Windows as an example. > > 1. Create the control layout by using JavaScript > 2. Store the day selected by a user in a hidden input > 3. Submit the page to the server, where the hidden input value can be > retrieved and process That's about how my calendar works, although it's a little more direct in that I don't use taglibs... I simply do an include of my calendar.inc file, which brings it the requisite HTML and scripting. The page has to call the Javascript initCalendar() > Can I do it like this? > > <calendar> > <html:hidden property=selectedDate/> > </calendar> > > Can I use the tags like above? Can the ActionForm *see* the selectedDate > hidden input in its validate() method? To be honest, I'm not sure. I tend to not use custom tags myself, so someone else may like to answer that one. If I was going to go the tag route, I would have the class that renders the <calendar> tag also render the hidden form, that way I know for sure what's going to come out and how it'll relate. Frank
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]