【问题标题】:How i can add new attribute for the input submit in "form" wicket我如何为“表单”检票口中的输入提交添加新属性
【发布时间】:2020-11-24 12:23:11
【问题描述】:

大家好,我对 wicket 有一个小问题,我是 wicket 世界的新手,所以请帮助我:

标记需要在输入标签中添加标题,该标签是表单的子标签

html 是这样的:

<div class="arena-record-button">
   <form wicket:id="showEditReservationPanelForm">
    <input class="arena-input-submit"  type="submit" wicket:id="editReservationButton" wicket:message="value:LabelEdit"/>
    </form>
</div>

但是当我们点击按钮时,我在输入标签中的 html 中所做的任何更改都不会出现,否则我可以在按钮构造中添加此代码,并且在我按下按钮之前将起作用:

this.add(new AttributeModifier("title", true, new Model("hello12")));

所以问题出在我按下按钮之后。


private void addEditReservationComponents(final ReservationDetailsPanel detailsPanel) { Form> showEditReservationPanelForm = new Form("showEditReservationPanelForm"); showEditReservationPanelForm.setOutputMarkupId(true); 添加(showEditReservationPanelForm);

    Button editReservationButton;
    boolean editReservation = isVisible(CONFIG_SHOW_EDIT_BUTTON) && reservation.isEditable();

    if (editReservation) {
        ApplicationBase app = (ApplicationBase) getApplication();
        DecorationParameters decorationParameters =
                new DecorationParameters(getSession().getLocale(), app.getPortalSite().getId(), Sets.newHashSet(decorations));
        EditReservationPanel editReservationPanel = new EditReservationPanel(EDIT_RESERVATION_PANEL_ID, decorationParameters, reservation,
                detailsPanel);
        editReservationPanel.setVisible(false);
        add(editReservationPanel);
        editReservationButton = new EditReservationButton(this, editReservationPanel, detailsPanel);
    } else {
        EmptyPanel editReservationPanel = new EmptyPanel(EDIT_RESERVATION_PANEL_ID);
        add(editReservationPanel);
        editReservationButton = new Button(EDIT_RESERVATION_BUTTON_ID);
        editReservationButton.setVisible(false);
    }

    showEditReservationPanelForm.add(editReservationButton);
}

/**
 * Indicates whether a component with the given portlet configuration key should be visible.
 *
 * @param key the portlet configuration key
 * @return <code>true</code> if and only if the portlet configuration for the given key returns <code>true</code>,
 * <code>false</code> otherwise
 */
private boolean isVisible(String key) {
    SessionBase session = (SessionBase) getSession();
    return session.getPortletConfigurationAsBoolean(key);
}

/**
 * Returns the configuration parameters for the indexed record panel.
 *
 * @param entityType the entity type to get the configuration for
 * @return the configuration parameters for the indexed record panel
 */
private IndexedRecordPanelConfigParams getIndexedRecordPanelConfigParams(EntityType entityType) {
    SessionBase session = (SessionBase) getSession();
    IndexedRecordPanelConfigParams configParams = new IndexedRecordPanelConfigParams(session, entityType);
    configParams.setDecorations(decorations);
    return configParams;
}

/**
 * This button provides the possibility to make the {@link EditReservationPanel} visible.
 */
private static class EditReservationButton extends IndicatingAjaxButton {
    private static final long serialVersionUID = -8740143889760682177L;
    private final ReservationListItemPanel listItemPanel;
    private final EditReservationPanel editReservationPanel;
    private final ReservationDetailsPanel reservationDetailsPanel;

    /**
     * Constructs a new {@link EditReservationButton}.
     *
     * @param listItemPanel           the {@link ReservationListItemPanel} to update on submit
     * @param editReservationPanel    the {@link EditReservationPanel} to make visible on submit
     * @param reservationDetailsPanel
     */
    private EditReservationButton(ReservationListItemPanel listItemPanel, EditReservationPanel editReservationPanel,
                                  ReservationDetailsPanel reservationDetailsPanel) {
        super(EDIT_RESERVATION_BUTTON_ID);
        this.listItemPanel = listItemPanel;
        this.editReservationPanel = editReservationPanel;
        this.reservationDetailsPanel = reservationDetailsPanel;
        setOutputMarkupId(true);
        setOutputMarkupPlaceholderTag(true);
    }

    /**
     * @see org.apache.wicket.ajax.markup.html.form.AjaxButton#onSubmit(org.apache.wicket.ajax.AjaxRequestTarget,
     * org.apache.wicket.markup.html.form.Form)
     */
    @Override
    protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
        setVisible(false);
        this.add(new AttributeModifier("title", true, new Model("hello12")));
        editReservationPanel.setVisible(true);
        editReservationPanel.setComponentsToMakeVisibleOnSave(this, reservationDetailsPanel);
        editReservationPanel.setComponentsToMakeVisibleOnCancel(this, reservationDetailsPanel);
        editReservationPanel.setOutputMarkupPlaceholderTag(true);
        editReservationPanel.setOutputMarkupId(true);
        if (target != null) {
            target.addComponent(editReservationPanel);
            target.addComponent(listItemPanel);
            target.addComponent(this);
        }
    }
}

}

【问题讨论】:

    标签: wicket


    【解决方案1】:

    您需要在 Java 代码中将 TextField 添加到表单中。

    private void addEditReservationComponents(final ReservationDetailsPanel detailsPanel) {
      Form<MyObject> showEditReservationPanelForm = new Form<MyObject>("showEditReservationPanelForm");
      showEditReservationPanelForm.setOutputMarkupId(true);
      add(showEditReservationPanelForm);
    
      // new stuff starts here
      TextField input = new TextField("editReservationButton", someModel);
      input.add(AttributeAppender.append("title", Model.of("Some text")));
      showEditReservationPanelForm.add(input);
      // ...
    }
    

    附:我还将Object (java.lang.Object ?!) 更改为MyObject。我怀疑您是否想使用 java.lang.Object 作为支持您的表单的模型对象。

    【讨论】:

    • 谢谢,马丁,您的代码有效,但它改变了表单(父),我想更改表单标签中的输入标签有什么想法吗?
    • 对不起。我错过了那部分。我已经更新了我的答案。
    • 谢谢你还是一样,我会更新我的帖子让你看到全班
    猜你喜欢
    • 1970-01-01
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多