简体   繁体   English

PropertyModel Expression的异常:org.apache.wicket.WicketRuntimeException:没有为类定义get方法:

[英]PropertyModel Expression's Exception : org.apache.wicket.WicketRuntimeException: No get method defined for class:

I used PropertyModel as the part of my DropDownChoice as following: 我使用PropertyModel作为DropDownChoice的一部分,如下所示:

    List<String> choices = Arrays.asList(new String[] { "Library", "School Office", "Science Dept" });
    String selected = "Library";

    DropDownChoice<String> serviceDDC = 
            new DropDownChoice<String>("service",  new PropertyModel(this, "choices.0"), choices); 

Somehow I've got this exception thown: 不知怎的,我得到了这个例外:

caused by: org.apache.wicket.WicketRuntimeException: No get method defined for class: class com.samoo.tool.pages.CreatePrintingJob expression: choices
    at org.apache.wicket.util.lang.PropertyResolver.getGetAndSetter(PropertyResolver.java:481)
    at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:332)
    at org.apache.wicket.util.lang.PropertyResolver.getObjectAndGetSetter(PropertyResolver.java:242)
    at org.apache.wicket.util.lang.PropertyResolver.getValue(PropertyResolver.java:95)
    at org.apache.wicket.model.AbstractPropertyModel.getObject(AbstractPropertyModel.java:130)
    at org.apache.wicket.Component.getDefaultModelObject(Component.java:1724)

....

I know that there's something wrong with the expression. 我知道表达式有问题。 I've been trying different parameter inputs but it still doesn't work. 我一直在尝试不同的参数输入,但它仍然无法正常工作。 Could anyone help? 有人可以帮忙吗?

Since you're using PropertyModel(this, "choices.0") , Wicket is trying to find a property named choices via reflection through a method getChoices() of the class declaring the PropertyModel. 由于你正在使用PropertyModel(this, "choices.0") ,Wicket试图通过声明PropertyModel的类的方法getChoices()通过反射找到一个名为choices的属性。 This method doesn't seem to exist in com.samoo.tool.pages.CreatePrintingJob , as the exception is stating. com.samoo.tool.pages.CreatePrintingJob似乎不存在此方法,因为异常是在说明。

Also, if that 0 is an index, you should be accessing it with the [index] expression, as this JIRA issue suggests: PropertyModel does not support index only property ("[0]") 此外,如果0是索引,则应使用[index]表达式访问它,因为此JIRA问题表明: PropertyModel不支持仅索引属性(“[0]”)

However, it seems you want to initialize the DropDownChoice to the first element of choices . 但是,您似乎希望将DropDownChoice初始化为choices的第一个元素。 But What Wicket will do if you set the DropDownChoice's Model to PropertyModel(this, "choices.[0"]) will be mapping the selection of this DropDownChoice in the following way: 但是如果你将DropDownChoice的模型设置为PropertyModel(this, "choices.[0"]) Wicket会做什么,将以下列方式映射DropDownChoice的选择:

  • At form rendering time to present the (pre)selected choice, it will use the first element in the choices list. 在表单呈现时呈现(预)选择的选项,它将使用choices列表中的第一个元素。
  • At form submission time to store the user selected value, it will store the selection in the first position of the choices list. 在表单提交时间存储用户选择的值时,它会将选择存储在choices列表的第一个位置。

Summarising, the backing object representing the DropDownChoice 's selection would be the first element in the choices list. 总而言之,表示DropDownChoice选择的后备对象将是choices列表中的第一个元素。

So, you'll probably want to use a whole different Model, independent from the choices list, for the backing object representing the DDC's selection. 因此,对于代表DDC选择的后备对象,您可能希望使用与选项列表无关的完全不同的模型。

List<String> choices = Arrays.asList(new String[] { "Library", "School Office", 
       "Science Dept" });
String selected = "Library";
IModel dropdownModel = new Model<String>(choices[0]);
DropDownChoice<String> serviceDDC = 
        new DropDownChoice<String>("service",  dropdownModel, choices);

You might find the following links useful: 您可能会发现以下链接很有用:

you are declaring choices inside the method, in order to get the PropertyModel to work you need to declare it on a class level not on a method level. 你在方法中声明了选择,为了使PropertyModel工作,你需要在类级别而不是在方法级别上声明它。 As @Xavi López pointed out the espression is not corret you nedd to use choices.[0] 正如@XaviLópez所指出的那样,表达方式并不正确,你需要使用选择。[0]

It is good idea to use IModel instead of PropertyMOdel . 最好使用IModel而不是PropertyMOdel PropertyModel has big problems in refactoring. PropertyModel在重构方面存在很大问题。 In my cases I did it and the problems solved properly.Also I have override the toString() of my Topic object. 在我的情况下,我做了它并且问题正确解决。我也覆盖了我的Topic对象的toString()

topicDropDown = new DropDownChoice<Topic>("topicOptions", new IModel<Topic>() {
        @Override
        public Topic getObject() {
            return top;
        }

        @Override
        public void setObject(Topic t) {
            top = t;
        }

        @Override
        public void detach() {
        }
    }, new LoadableDetachableModel<List<Topic>>() {
        @Override
        protected List<Topic> load() {

            List<Topic> topics = top.getAllTopics();
            return topics;

        }
    });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.wicket.WicketRuntimeException当我尝试从sessionFactory打开休眠获取会话时 - org.apache.wicket.WicketRuntimeException when I try to open hibernate get session from sessionFactory Apache Wicket:如何将PropertyModel添加到复选框对象 - Apache Wicket : How to add PropertyModel to checkbox object Wicket:如何将DropDownChoice与PropertyModel一起使用? - Wicket: How to use a DropDownChoice with a PropertyModel? Wicket:org.apache.wicket.markup.MarkupNotFoundException - Wicket : org.apache.wicket.markup.MarkupNotFoundException java.lang.NoSuchMethodError: org.apache.wicket.request.cycle.RequestCycle.find(Ljava/lang/Class;)Lorg/apache/wicket/request/IRequestHandler; - java.lang.NoSuchMethodError: org.apache.wicket.request.cycle.RequestCycle.find(Ljava/lang/Class;)Lorg/apache/wicket/request/IRequestHandler; 错误 | 发生异常:org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException:行为被拒绝接口调用 - ERROR | Exception occured: org.apache.wicket.core.request.handler.ListenerInvocationNotAllowedException: Behavior rejected interface invocation 无法创建类org.apache.wicket.spring.SpringWebApplicationFactory的应用程序工厂 - Unable to create application factory of class org.apache.wicket.spring.SpringWebApplicationFactory 创建类org.apache.struts.validator.DynaValidatorForm的异常 - Exception creating bean of class org.apache.struts.validator.DynaValidatorForm 找不到类异常-org.apache.http.client.methods.HttpRequestBase - No Class found Exception - org.apache.http.client.methods.HttpRequestBase Wicket-更新PropertyModel时表单组件丢失参考 - Wicket - form components losing reference when PropertyModel is updated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM