English 中文(简体)
Wicket: Bind Model on Level
原标题:Wicket: Bind Model on Class
  • 时间:2012-01-13 08:50:41
  •  标签:
  • model
  • wicket

《示范法》如何运作?

我有这样的书记官处:

public class RegisterPanel extends Panel{

//empty user
public User user = new User();

protected ServiceClient client = ((WicketApplication) (WicketApplication.get())).getClient();

@SuppressWarnings({ "rawtypes" })
public RegisterPanel(String id) {
    super(id);
    //creates form with an empty user
    Form form = new RegisterForm("registerForm", user); 
    add(form); 
}

@SuppressWarnings({ "rawtypes" })
class RegisterForm extends Form {

    private String userId = "";
    private String email = "";
    private String password1 = "";
    private String password2 = "";

    private FormComponent formEmail;
    private FormComponent formPassword1;
    private FormComponent formPassword2;

  @SuppressWarnings("unchecked")
public RegisterForm(String id, User user) {

    super(id);
    add(new TextField("userId", new PropertyModel(this, "userId")).setRequired(true));
    formEmail = new TextField("email", new PropertyModel(this, "email")).setRequired(true);
    formPassword1 = new PasswordTextField("password1", new PropertyModel(this, "password1")).setRequired(true);
    formPassword2 = new PasswordTextField("password2", new PropertyModel(this, "password2")).setRequired(true);
    add(formEmail);
    add(formPassword1);
    add(formPassword2);
  }

  @Override
  public void onSubmit() {

      Result result = client.register(email, userId, password1);
      if(result.getStatus()) {

                      user.setEail(email);
                          user.setUserId(userId);
                          user.setPassword(password1);
                  client.postUser(user);
      }
  } 
}
 }

但是,我如何利用模式开展工作? 现在,我只把财产模型与我的文本领域联系起来。 我认为,我可以把模型约束给我的空勤者,而采用提交方法,我的工作是仿照我的简单用户。 如何工作? 如何利用模型开展工作?

最佳回答

与模型合作有若干优势:

public class RegisterPanel extends Panel{

protected ServiceClient client = ...

public RegisterPanel(String id) {
    super(id);
    //creates form with an empty user
    Form<Void> form = new RegisterForm<Void>("registerForm", new Model(new User())); 
    add(form); 
}

class RegisterForm extends Form<Void> {

    public RegisterForm(String id, IModel<User> user) {
        super(id);

        add(new TextField("userId", new PropertyModel(user, "userId")).setRequired(true));
        add(new TextField("email", new PropertyModel(user, "email")).setRequired(true);
        add(new PasswordTextField("password", new PropertyModel(user, "password")).setRequired(true);
        add(new PasswordTextField("password2", new Model("").setRequired(true);
}

    @Override
    public void onSubmit() {
        try {
            client.registerAndPost(email, userId, password1);
        } catch (ServiceException ex) {
            ...
        }
    }
}

注:

  • RegisterForm isn t interested where the user is coming from
  • form fields write directly into the user
问题回答

暂无回答




相关问题
What do you have in your Model class?

What do you have in your model classes. Generally if i use any framework or any library (Zend Framework) , my classes only have variable which is table name . I know that in complicated applications ...

Rails Model With Aggregrate Data (not backed by a table)

Id like to create a model in rails that does not correlate to a table in the database. Instead the model should dynamically pull aggregrate data about other models. Example: I have a Restaurant ...

Trouble changing databases for my models in codeigniter

I m making a website with two different databases. Let s say one is DB1, and the other is DB2. I ve set up my database.php in the config folder, so they each have the correct host/password/username/...

EMAIL server FSP model

For my assignment I need to develop FSP model for email server and client. I manage to write simple model which describes one user, server and his mailbox, but I am having problems changing this ...

Rails Custom Model Functions

I m in a databases course and the instructor wants us to develop an e-commerce app. She said we can use any framework we like, and now that we re halfway through the semester she decided that Rails ...

热门标签