2010-08-05 98 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