Friday, August 10, 2007

Eclipse 3.3 configuration for Wicket with Aptana

It turns out that using Aptana as the HTML editor in Eclipse marks all the wicket tags as errors. To get around this, do this:

Go to Window->Preferences
Select Aptana->Editors->HTML Editor
Add a new filter: .*wicket:.*
Click OK

Configuring Eclipse 3.3 for wicket web development

Install software updates and plugins
------------------------------

Go to: Help->Software Updates->Find and Install
Select: Search for updates of currently installed features
Automatically select mirrors (or manually do it if you prefer)
I can't remember what I updated, but there is a minor Eclipse update available
Install this update -- I think it is needed for WicketBench to work.
When asked to restart Eclipse, say NO (not yet).
Next, go again to: Help->Software Updates->Find and Install
Select: Search for new features to install
Check Web Tools Platform (WTP) Updates
Click Finish
Select Web Tools Platform (WTP) -> Web Standard Tools (WST)
(only select the one checkbox, not the others such as SDK)
Go through install process
When asked to restart Eclipse, say NO (not yet).
Next, go again to: Help->Software Updates->Find and Install
Select: Search for new features to install
Click New Remote Site button
Name: Wicket Bench
URL: http://www.laughingpanda.org/svn/wicket-bench/trunk/wicket-bench-site
The new Wicket Bench site should be checked.
Click Finish
Go through install process
Now, when asked to restart Eclipse, say YES.

Configure workspace preferences
------------------------------------------------
Go to: Window->Preferences
Select: Java->Compiler
Make sure compiler compliance level is 5.0
Select: Java->Compiler->Errors/Warnings
Under Potential programming problems
Set Serializable class withous serialVersionUID to Ignore
Select: General->Editors->Text Editors
Set the displayed tab width to 4 (or whatever you prefer)
Uncheck insert spaces for tabs (unless you want spaces, but they bug me)
Check show line numbers
Select: General->Workspace->Local History
Set Days to keep files to 14 (or whatever you want...)
Click OK to save everything

Now, to open a Java class, right click onto the class and select Open with -> Wicket Editor. You only need to do this one time. After that, it will automatically use the wicketbench editor when you open that class. In the editor, there will be tabs at the bottom of the editor window for java, properties, css, and html. You can quickly switch between these files within one editor (for instance, HomePage.java, HomePage.properties, HomePage.html, and HomePage.css). It makes it easy for working with Wicket.

WST needs to be installed or you won't be able to edit HTML files with HTML tag highlighting. Whenever you open an HTML file, it will render it in a web browser, but it won't be editable unless you install WST. With WST, you can edit it using the "HTML editor" instead of doing a right click->open with->Text Editor. Another alternative is Aptana. I'm experimenting with it -- it does a lot more than WST, but it seems a bit too heavy and overkill for my needs. If I end up using it, I'll post here with more about it.

Also, WicketBench provides an HTML tab that automatically use WST HTML editor (I think it uses that editor). I don' t know if there is a way to get it to use the Aptana HTML editor. WicketBench also provides a Preview tab that renders the page, but it isn't the same as opening with the Web Browser.

Note that I originally I also did this, but I recommend against doing it:
Go to: Window->Preferences
Select: General->Editors->File Associations
Highlight *.java in list of File Types
Select associated editor: Wicket Editor
Click onto the Default button

When you do that, it causes a wicketbench/eclipse debugger bug to happen. I've found that the debugger in eclipse doesn't show the current line of execution in the code if wicket bench is installed and configured as the default Java editor. The debugger works, and the thread view shows the current line number, but the line isn't highlighted in the code.

At this time, Wicket Bench hasn't been officially tested with Eclipse 3.3 yet, but I understand that this same issue existed prior to Eclipse 3.3. See this FAQ:
http://www.laughingpanda.org/mediawiki/index.php/Wb-FAQ

To avoid the problem, just do not set WicketBench as the default editor for java files. Instead, use right-click, "Open With" Wicket Editor as I described above to open java classes. The next time you open them, you can just double click and it will remember to use WicketBench. And, by doing this, the debugger will open a regular Java Editor and will show the current line highlighted. Even if you have a WicketBench editor open for the same file, the debugger will open a new window with a regular Java Editor during debugging. You will have to close the extra files manually, however.

Once this is done, eclipse provides a decent environment for developing wicket apps. You might also want to add the subversive plugin to eclipse, as described in my previous post.

Next, I may look into adding a maven plugin, but no time for that right now.

Eclipse 3.3 with subversion support

Just installed Subversive plugin into eclipse 3.3. Using update feature, added new site:
http://www.polarion.org/projects/subversive/download/1.1/update-site/

In order to install, I had to remove the following feature:
Subversive Integration for the CSC Project Set

Thursday, August 09, 2007

Radio controls with ajax in wicket 1.2

I needed to have two radio controls on a form. If one was selected, one panel would show. If the other was selected, the other panel would show. This is possible in Wicket 1.3, but not using Wicket 1.2.6. Here is how I got it to work in Wicket 1.2.6.

public static final int WITH_CONFIG = 0;
public static static int WITHOUT_CONFIG = 1;

private class FileUploadForm extends Form {

private WebMarkupContainer xmlContainer;
private WebMarkupContainer enginesContainer;

/**
* Construct.
*
* @param name
* Component name
*/
public FileUploadForm(String id, IModel model) {
super(id, model);

EdiInformation ediInfo = ((EdiInformation)getModelObject());

// set this form to multi-part mode (always needed for uploads!)
setMultiPart(true);

// Set maximum size to 10M
setMaxSize(Bytes.megabytes(10));

Button saveButton = new Button("saveButton", new ResourceModel("form.saveButton"));
add(saveButton);
add(new Button("cancelButton", new ResourceModel("form.cancelButton")) {
protected void onSubmit() {
setResponsePage(new ManagerMainPage(ManagerMainPage.TAB_EDI));
}
}.setDefaultFormProcessing(false));
add(new FeedbackPanel("feedback"));

enginesContainer = new WebMarkupContainer("enginesContainer");
enginesContainer.setOutputMarkupId(true);
enginesContainer.add(new EdiImportEnginesDropDownChoice("importEngine"));
enginesContainer.setVisible(false);

xmlContainer = new WebMarkupContainer("xmlContainer");
xmlContainer.setOutputMarkupId(true);
FileUploadField xmlInput = new FileUploadField("xmlInput");
ediInfo.setXmlInput(xmlInput);
xmlContainer.add(xmlInput);

RadioGroup option = new RadioGroup("option");
setupAjaxRadio(this, option, new Radio("withConfig", new Model(WITH_CONFIG)),
xmlContainer,enginesContainer);
setupAjaxRadio(this, option, new Radio("withoutConfig", new Model(WITHOUT_CONFIG)),
enginesContainer,xmlContainer);

add(enginesContainer);
add(xmlContainer);
add(option);

FileUploadField dataInput = new FileUploadField("dataInput");
ediInfo.setDataInput(dataInput);
add(dataInput);

add(new UploadProgressBar("progress", this));

}

private void setupAjaxRadio(final Form form, final RadioGroup radioGroup,
final Radio radio, final WebMarkupContainer visibleContainer,
final WebMarkupContainer hiddenContainer) {
radioGroup.add(radio.add(new AjaxEventBehavior("onchange") {
protected void onEvent(AjaxRequestTarget target) {
radioGroup.processInput();
hiddenContainer.setVisible(false);
visibleContainer.setVisible(true);
target.addComponent(form);
}
protected CharSequence getEventHandler() {
return getCallbackScript(new AppendingStringBuffer(
"wicketAjaxPost('").append(getCallbackUrl()).append(
"', wicketSerialize(document.getElementById('"
+ radio.getMarkupId() + "'))"), null, null);
}
}));
}

 

Labels

Labels