문제

I have a wicket page, say SignUpCustomerPage extends WebPage. It has a default model to be new CompoundPropertyModel<Customer>(customer) where customer is private property of page class.

I add various HTML input fields into a form of page, but when adding HTML5 url input, it requires IModel<String> as second parameter. Example

model = new CompoundPropertyModel<Customer>(customer);

Form f = new Form();
f.add(new UrlTextField("website", model));
add(f);

Any example how to combine compound property model with URL text field?

도움이 되었습니까?

해결책

I don't think it's possible to use the CompoundPropertyModel. You can use PropertyModel instead:

f.add(new UrlTextField("website", new PropertyModel<String>(customer, "website"));

다른 팁

You can access a property inside an object using a compoundpropertymodel using a wicket id like so: "textfieldid.property" so in the following example you can get/set the website inside the Customer object with "customer.website". this id should also be used in the html for the form input wicket:id.

// Customer class
public class Customer {
    private String website;
    // Getter and setter for website
}

// Webpage
public SignUpCustomerPage extends WebPage {

    private Customer customer;

    public SignUpCustomerPage() {

        customer = new Customer();

        CompoundPropertyModel<Customer> cpm = new CompoundPropertyModel<Customer>(customer);   

        Form<Customer> form = new Form("formid", cpm) {
            @Override
            public onSubmit(){ System.out.println(getModelObject().getWebsite())}
        };
        form.add(new UrlTextField("customer.website"));
        add(form);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top