2010-08-05 99 views
2

我遇到了在页面上显示按钮的问题。有两个按钮叫做“上传”和“保存”。开始时“上传”按钮是可见的,而保存按钮具有.setVisible(false)。Wicket:在Ajax响应中显示按钮

… 
<tr> 
<td width="35%" align="right"> 
      <input type="submit" wicket:id="createUploadButton" value="Upload" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"/> 
     </td> 
     <td width="30%" align="right"> 

     </td> 
     <td width="35%" align="left"> 
      <input type="submit" wicket:id="createCancelButton" value="Cancel" class="ui-button ui-button-text-only ui-widget ui-state-default ui-corner-all"/> 
     </td> 
</tr> 

在上传AjaxRequest按钮期间,需要显示“保存”按钮并隐藏上传按钮,但出现错误。代码片段如下所示:

AjaxButton createSaveButton=new IndicatingAjaxButton("createSaveButton"){ 

    private static final long serialVersionUID = 1L; 

    @Override 
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) { 
       // TODO Auto-generated method stub 
      } 
    }; 
    createSaveButton.setVisible(uploaded); 
    createSaveButton.setOutputMarkupId(true); 
    form.add(createSaveButton); 

AjaxButton createUploadButton=new IndicatingAjaxButton("createUploadButton"){ 

    private static final long serialVersionUID = 1L; 

    @Override 
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) { 

     … 
     createUploadButton.setVisible(false); 
     createSaveButton.setVisible(true); 
     target.addComponent(createUploadButton); 
     target.addComponent(createSaveButton); 
} 
createUploadButton.setOutputMarkupId(true); 
form.add(createUploadButton); 

有人知道问题在哪里吗?

谢谢! Sonja

+0

你能正确格式化你的代码吗? – ireddick 2010-08-05 12:57:09

回答

4

您需要使用 setOutputMarkupPlacholderTag setOutputMarkupPlaceholderTag。请参阅:

createSaveButton.setVisible(uploaded); 
createSaveButton.setOutputMarkupId(true); 

// Add This line 
createSaveButton.setOutputMarkupPlaceholderTag(true); 
form.add(createSaveButton); 

在HTML中放置一个可以用真正按钮替换的隐藏元素。

+0

当我把它的工作: createSaveButton.setOutputMarkupPlacholderTag(true); 而不是: createUploadButton.setOutputMarkupPlacholderTag(true); 非常感谢! – sonjafon 2010-08-05 23:05:33

+0

你的权利,修复了答案.. – stevemac 2010-08-06 04:03:29

+0

而且,如果你调用.setOutputMarkupPlacholderTag(true);没有必要调用.setOutputMarkupId(true);,因为第一个意味着第二个。 – tpdi 2010-08-06 07:00:59