Wicket Component ID Best practive
Just started playing around with, how is everyone linking up their component ids ?
So far the most frequent error I've got are mismatches in component ids. For example,
In the html
...
<span wicket:id="messageID">message will be here</span>
...
and on the Java side
...
add(new Label("messageID", "If you see this message wicket is p开发者_Go百科roperly configured and running"));
...
I'm running on a maven/IntelliJ setup if that helps. Thanks!
every wicket page I have has at least one test
@Test
public void testPageRender() {
WicketTester tester = new WicketTester();
tester.startPage( MyPage.class );
tester.assertNoErrors();
}
Since you are using IntelliJ you could use the WicketForge plugin which highlights IDs that that do not appear in Java code. Apart from that, i would suggest testing the components, missing IDs are easy to detect in tests.
Good question, and I'll be watching for other answers.
The best advice I can give is to use tests to catch the problem early.
Write a unit test using WicketTester for each component you develop at least verifying that your component renders. This will catch such errors in a test rather than in the running app.
You can and of course should also test that your component contains all the right pieces, that navigation works properly, etc... But the basic render test will catch id mismatches.
精彩评论