Exception of Java – propertymodel expression: org apache. wicket. Wicketruntimeexception: no get method defined for class:

I use propertymodel as part of dropdownchoice, as follows:

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 got this exception:

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 there is something wrong with the expression I've been trying different parameter inputs, but it still doesn't work Can I help you?

Solution

Because you are using propertymodel (this, "choices. 0"), wicket attempts to find a property named choices through reflection through the method getchoices () of the class declaring propertymodel com. samoo. tool. pages. This method does not appear to exist in createprintingjob because the exception is in the description

In addition, if 0 is an index, it should be accessed using the [index] expression because of this JIRA problem. Suggestion: propertymodel does not support index only property ('[0]')

However, you seem to want to initialize dropdownchoice as the first element of the selection However, if you set the dropdownchoice model to propertymodel (this, "option. [0")), the dropdownchoice selection will be mapped in the following ways. What will wicket do

>When the form is rendered, the (pre) selected option is rendered, which will use the first element in the option list. > When a user's selection is stored at the form submission time, it stores the selection in the first position in the option list

In summary, the support object representing the dropdownchoice selection will be the first element in the selection list

Therefore, for fallback objects selected on behalf of DDC, you may want to use a completely different model independent of the option list

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

You may find the following links useful:

> Using the DropDownChoice component > Working with Wicket Models

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>