Wicket:在Ajax响应期间显示按钮

时间:2010-08-05 02:00:20

标签: java wicket

我遇到与显示页面上的按钮有关的问题。有两个按钮叫做“上传”和“保存”。在开头“上传”按钮可见,而“保存”按钮有.setVisible(false)。

…
<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);

有人知道问题在哪里吗?

谢谢! 宋佳

1 个答案:

答案 0 :(得分:4)

您需要使用 setOutputMarkupPlacholderTag setOutputMarkupPlaceholderTag。参见:

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

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

将隐藏元素放在HTML中,可以用真实按钮替换。