2010-08-06 29 views
0

我創建了一個簡單的wicket web應用程序來描述這個問題,當我設置要求在TextField中爲true並且在Textfield中使用null值提交時。我有一個反饋面板消息(這聽起來不錯),但我的用例我想從模態窗口獲取我的數據併發送回這個表單,但它不能AjaxRequestTarget更新TextField數據,並且不能輸入任何其他textfield.i不能解決有這個問題。請幫助我。但是當我再次運行Web應用程序並使用模態窗口時,我可以在文本字段上設置我的數據。Wicket 1.4.9反饋錯誤後無法使用模態的AjaxRequestTarget!

這是我的示例代碼

用戶實體:

public class User implements Serializable { 

private String username; 
private String password; 

public User(String username, String password){ 
    this.username = username; 
    this.password = password; 
} 

public User() { 
    // TODO Auto-generated constructor stub 
} 

public String getUsername() { 
    return username; 
} 

public void setUsername(String username) { 
    this.username = username; 
} 

public String getPassword() { 
    return password; 
} 

public void setPassword(String password) { 
    this.password = password; 
} 
} 

我的頁面

public class FormPage extends WebPage{ 

private User user; 
private ModalWindow modal; 
private TestForm form; 

public FormPage() { 
    user = new User(); 

    modal = new ModalWindow("modal"); 
    modal.setOutputMarkupId(true); 
    modal.setInitialHeight(300); 
    modal.setInitialWidth(300); 
    add(modal); 

    form = new TestForm("form"); 
    add(form); 
} 

private class TestForm extends Form { 

    private FeedbackPanel feedback; 
    private TextField<String> username; 
    private AjaxLink popupButton; 
    private AjaxButton submitButton; 
    private TextField<String> password; 

    public TestForm(String id) { 
     super(id); 

     feedback = new FeedbackPanel("feedback"); 
     feedback.setOutputMarkupId(true); 
     add(feedback); 

     username = new TextField<String>("username", new PropertyModel<String>(FormPage.this, "user.username")); 
     username.setOutputMarkupId(true); 
     username.setRequired(true); 
     add(username); 

     password = new TextField<String>("password", new PropertyModel<String>(FormPage.this, "user.password")); 
     password.setOutputMarkupId(true); 
     password.setRequired(true); 
     add(password); 

     popupButton = new AjaxLink("popupButton") { 

      @Override 
      public void onClick(AjaxRequestTarget target) { 
       UserPopup popup = new UserPopup(modal.getContentId()) { 

        @Override 
        public void onSuccess(AjaxRequestTarget target, User user) { 
         FormPage.this.user = user; 
         target.addComponent(username); 
         target.addComponent(password); 
         modal.close(target); 
        } 
       }; 
       modal.setContent(popup); 
       modal.show(target); 
      } 
     }; 
     add(popupButton); 

     submitButton = new AjaxButton("submitButton", this) { 

      @Override 
      protected void onSubmit(AjaxRequestTarget target, Form<?> form) { 
       // TODO Auto-generated method stub 

      } 

      @Override 
      protected void onError(AjaxRequestTarget target, Form<?> form) { 
       target.addComponent(feedback); 
      } 
     }; 
     add(submitButton); 

    } 

} 

}

我彈出:

public abstract class UserPopup extends Panel{ 

private User user; 

public UserPopup(String id) { 
    super(id); 

    user = new User("name","pass"); 

    add(new AjaxLink("userLink"){ 

     @Override 
     public void onClick(AjaxRequestTarget target) { 
      onSuccess(target, user); 
     } 


    }); 
} 

public abstract void onSuccess(AjaxRequestTarget target,User user); 

}

回答

0

試試這個。 onSuccess方法,設置您的用戶名和密碼字段的模型對象。

@Override 
       public void onSuccess(AjaxRequestTarget target, User user) { 
        FormPage.this.user = user; 
        username.setModelObject(user.getUsername()); 
        password.setModelObject(user.getPassword()); 
        target.addComponent(username); 
        target.addComponent(password); 
        modal.close(target); 
       } 

我有一個類似的用例,它的工作。你似乎正在努力與你的英語,所以我可能沒有很好地理解你的問題。

下面是我在類似問題上的代碼。

public class ReleaseDetailPanel extends Panel { 

    /** 
    * 
    */ 
    private static final long serialVersionUID = 1L; 

    private Form<Release> frmRelease ; 

    private TextField<String> txtName ; 

    private TextArea<String> txtDescription; 

    private TextField<Project> txtProject; 

    private AjaxLink<String> lnkLookupProject ; 

    private ModalWindow mdProjectLookup ; 

    @Inject 
    private Dao dao ; 


    public ReleaseDetailPanel(String id, Release release) { 
     super(id); 

     frmRelease = new Form<Release>("frmRelease", new Model<Release>(release)){ 
      /** 
      * 
      */ 
      private static final long serialVersionUID = 8075962334880413343L; 

      protected void onSubmit() { 
       Release r = this.getModelObject(); 
       dao.save(r); 
      }; 
     }; 

     txtName = new TextField<String>("txtName", new PropertyModel<String>(release, "name")); 
     frmRelease.add(txtName); 

     txtDescription = new TextArea<String>("txtDescription", new PropertyModel<String>(release, "description")); 
     frmRelease.add(txtDescription); 

     txtProject = new TextField<Project>("lstProject", new PropertyModel<Project>(release, "project")); 
     frmRelease.add(txtProject); 
     txtProject.setEnabled(false); 
     txtProject.setOutputMarkupId(true); 

     lnkLookupProject = new AjaxLink<String>("lnkLookupProject"){ 
      /** 
      * 
      */ 
      private static final long serialVersionUID = -1014715631761886636L; 

      @Override 
      public void onClick(AjaxRequestTarget target) { 
       mdProjectLookup.show(target); 
      } 


     }; 
     frmRelease.add(lnkLookupProject); 
     add(frmRelease); 

     mdProjectLookup = new ModalWindow("mdProjectLookup"); 
     mdProjectLookup.setContent(new ProjectListPanel(mdProjectLookup.getContentId()){ 

      @Override 
      public Component getGridMenu(String id) { 

       return new Label(id); 
      } 

      @Override 
      public Component getGridItemMenu(String componentId, final Project project) { 
       return new LabeledAjaxFallbackLink(componentId, "Select"){ 

        /** 
        * 
        */ 
        private static final long serialVersionUID = 1L; 

        @Override 
        public void doClick(AjaxRequestTarget target) { 
         txtProject.setModelObject(project); 
         target.addComponent(txtProject); 
         mdProjectLookup.close(target); 
        } 


       }; 

      } 

     }); 

     add(mdProjectLookup); 
    }