为什么给AttributeAppender错误无法使用构造函数实例化页面?

时间:2016-04-11 18:39:03

标签: java wicket

我有一个MylistPage3类可以正常工作。

public class MyListPage3 extends WebPage {

    private static final long serialVersionUID = 1L;
    Model<String> infostringMdl = Model.of("Info: -");
    Model<String> classModelOfMsg = Model.of("btn btn-success btn-lg btn-block");
    Label infolabel = new Label("info", infostringMdl);

    public MyListPage3(final PageParameters parameters) {
        infolabel.setOutputMarkupId(true);
        infostringMdl.setObject("Hello World");
        classModelOfMsg.setObject("btn btn-success btn-lg btn-block");
        //infolabel.add(new AttributeAppender("class", classModelOfMsg, " "));
        add(infolabel);
    }
}

HTML:

...
<table>
    <tr>
        <td width:="50%"><span wicket:id="info"
            class="btn btn-default btn-lg btn-block">info here</span></td>
    </tr>
</table>
...

我想用Java设置span的类,但是用行...

infolabel.add(new AttributeAppender("class", classModelOfMsg, " "));

...我收到错误:

WicketMessage: Can't instantiate page using constructor public Pages.MyListPage3(org.apache.wicket.PageParameters) and argument 

Root cause:

java.lang.ClassNotFoundException: org.apache.wicket.behavior.Behavior
 at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
 at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
...
...

我运行mvn依赖:tree 结果是:

[INFO] ------------------------------------------------------------------------
[INFO] Building WicketExamples 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ WicketExamples ---
[INFO] com.mkyong.core:WicketExamples:war:1.0-SNAPSHOT
[INFO] +- org.apache.wicket:wicket-core:jar:6.21.0:compile
[INFO] |  +- org.apache.wicket:wicket-util:jar:6.21.0:compile
[INFO] |  \- org.apache.wicket:wicket-request:jar:6.21.0:compile
[INFO] +- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.5:compile
[INFO] |  \- org.codehaus.jackson:jackson-core-asl:jar:1.8.5:compile
[INFO] +- org.apache.wicket:wicket:jar:1.4.17:compile
[INFO] +- de.agilecoders.wicket:wicket-bootstrap-core:jar:0.8.3:compile
[INFO] |  +- de.agilecoders.wicket.webjars:wicket-webjars:jar:0.2.0:compile
[INFO] |  |  \- org.webjars:webjars-locator:jar:0.1:compile
[INFO] |  |     +- org.reflections:reflections:jar:0.9.8:compile
[INFO] |  |     |  +- javassist:javassist:jar:3.12.1.GA:compile
[INFO] |  |     |  \- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |     |     \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  |     \- commons-lang:commons-lang:jar:2.6:compile
[INFO] |  +- org.webjars:bootstrap:jar:2.3.1-1:compile
[INFO] |  |  \- org.webjars:jquery:jar:1.9.0:compile
[INFO] |  +- org.webjars:modernizr:jar:2.6.2-1:compile
[INFO] |  +- joda-time:joda-time:jar:2.0:compile
[INFO] |  +- com.google.guava:guava:jar:14.0.1:compile
[INFO] |  \- org.apache.wicket:wicket-extensions:jar:6.21.0:compile
[INFO] +- de.agilecoders.wicket:wicket-bootstrap-extensions:jar:0.8.3:compile
[INFO] |  +- com.google.javascript:closure-compiler:jar:v20130411:compile
[INFO] |  |  +- args4j:args4j:jar:2.0.16:compile
[INFO] |  |  +- com.google.protobuf:protobuf-java:jar:2.4.1:compile
[INFO] |  |  +- org.json:json:jar:20090211:compile
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] |  \- org.webjars:jquerypp:jar:1.0b2:compile
[INFO] +- de.agilecoders.wicket:wicket-bootstrap-themes:jar:0.8.3:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.5.6:compile
[INFO] |  \- log4j:log4j:jar:1.2.16:compile
[INFO] +- junit:junit:jar:4.10:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- org.slf4j:slf4j-api:jar:1.6.4:compile
[INFO] \- org.slf4j:jcl-over-slf4j:jar:1.6.4:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.473 s
[INFO] Finished at: 2016-04-12T20:10:30+02:00
[INFO] Final Memory: 18M/226M
[INFO] ------------------------------------------------------------------------

这里出了什么问题?

是org.apache.wicket:wicket:jar:1.4.17这里是错误的来源吗?

1 个答案:

答案 0 :(得分:1)

检查您的应用程序类路径。它看起来好像有几个版本的Wicket。