|
Re: How Does Language Impact Framework Design?
|
Posted: Jan 16, 2008 8:00 AM
|
|
> > You say that Wicket is an excellent web framework...why > do > > you have to write things twice? one time in the HTML > file > > and one in Java. > > > > My company considered Wicket a year ago but we did not > > choose it because of this problem: we had to write > things > > twice. > > > > The only solution (that no one has done yet, I don't > know > > why) is to completely eliminate all kinds of HTML/XML > and > > write web applications in Java only, with a framework > that > > mimics a GUI library (i.e. widget trees) but produces > > HTML/Javascript. > > What, exactly, did you have to write twice? You have to > write a Wicket ID twice -- once in the Java component and > once as an attribute in the HTML to link the Java with the > HTML, but that's about it. You do have the option > sometimes of coding into the HTML sample display elements > that will be replaced by the Java component, if you want > to get a more realistic sense of what the page will look > like once the Java component replaces the sample elements > with the real once based on the model -- but you don't > have to do that.
Ok. Let's see some examples. Let's start with the Hello World example.
You have to write the following Java code:
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
public class HelloWorld extends WebPage
{
/**
* Constructor
*/
public HelloWorld()
{
add(new Label("message", "Hello World!"));
}
}
And this HTML:
<html> <body> <span wicket:id="message" id="message">Message goes here</span> </body> </html>
Which is pretty much the same: an HTML page declared twice, once as HTML and once as a label object inside a page object.
Ok, let's go to another example: the GuestBook. The Java code is:
public final class GuestBook extends WebPage
{
/** Use a Vector, as it is synchronized. */
private static final List commentList = new Vector();
private final ListView commentListView;
public GuestBook()
{
add(new CommentForm("commentForm"));
add(commentListView = new ListView("comments", commentList)
{
public void populateItem(final ListItem listItem)
{
final Comment comment = (Comment)listItem.getModelObject();
listItem.add(new Label("date", comment.date.toString()));
listItem.add(new MultiLineLabel("text", comment.text));
}
});
}
public final class CommentForm extends Form
{
private final Comment comment = new Comment();
public CommentForm(final String componentName)
{
super(componentName);
add(new TextArea("text", new PropertyModel(comment, "text")));
}
public final void onSubmit()
{
final Comment newComment = new Comment();
newComment.text = comment.text;
commentList.add(0, newComment);
commentListView.modelChanged();
comment.text = "";
}
}
}
The above code builds a page with a text area, a submit button, and a list of strings.
Then we need this HTML:
<html> <body> <form wicket:id = "commentForm"> Add your comment here: <p> <textarea wicket:id = "text">This is a comment</textarea> <p> <input type = "submit" value = "Submit"/> </form> <p> <span wicket:id = "comments"> <p> <span wicket:id = "date">1/1/2004</span><br> <span wicket:id = "text">Comment text goes here.</span> </p> </span> <wicket:remove> <p> 1/2/2004<br/> More comment text here. </p> </wicket:remove> </body> </html>
Which builds again the same thing.
And I am asking you: why? the WebPage object could simply go through all of the components, produce a nice HTML object automatically.
The HTML written above is reduntant.
> > The solution you suggest (abstract the HTML away > completely) has indeed been done, see Google Web Toolkit > (GWT) and also in Echo and (for AJAX) Echo2. However, I > suspect these have less flexibility than Wicket when it > comes to customizing the look-and-feel of the pages.
No, it has not been done.
The Google Web Toolkit translates Java code to html/javascript. It is not the Java code that produces the html/javascript.
The Echo2 toolkit (I have worked with it for a project) makes the browser a display server, ala X-Windows, using AJAX techniques. It's slow and complex.
My idea is to preserve the web page concept, complete with navigation, but not to have to write html.
> > Beyond that, it depends on whether you prefer using HTML > to customize your look-and-feel versus doing that via API > method invocations (as when building fat clients in > Swing). Most people building web applications have > already made a significant investment in HTML/CSS skills, > and high-power tools for that are readily available -- so > you're not locked into using a particular Java IDE to ease > the painting of GUIs. Furthermore, you may have some > pre-written HTML portions that you really want to > incoroprate (e.g. standard page headers, or static pages > written in HTML by others), and this is probably much > easier to do in Wicket than in GWT or Echo.
Any html coming from artists or web creators should be converted to Java code that produces the html at run-time. The workflow should be:
raw html -> java code -> compilation -> html with data.
The HTML should be treated like an Qt .ui file, i.e. as a description of the gui.
|
|