繁体   English   中英

如何将Wicket FormComponentPanel的标记放在wicket:fragment中?

[英]How can I put the markup for a Wicket FormComponentPanel inside of a wicket:fragment?

我将一个TextField和一个DropDownChoice放在FormComponentPanel中,该组件应该将setConvertedInput用作与DropDownChoice的值连接的TextField的值。 但是,我想将FormComponentPanel的标记放在包含包含表单的标记文件的wicket:fragment中。

这是到目前为止我尝试过的简化版本:

OptionsPanel.java

... some stuff not shown here ...
DurationFormComponentPanel durationFormComponentPanel = new DurationFormComponentPanel("estimated_duration");
add(new Fragment("estimatedDuration", "duration_fragment", OptionsPanel.this));

OptionsPanel.html

<span wicket:id='estimatedDuration'></span>
<wicket:fragment wicket:id='duration_fragment'>
<input wicket:id='estimated_duration' value='3' />
<select wicket:id='needed_time_unit'>
    <option>weeks</option>
    <option>days</option>
</select>
</wicket:fragment>

此atm的最终结果是FormComponentPanel的标记为空。

我不确定做为片段会多么容易。 我经常扩展FormComponentPanel并通过像这样重写onComponentTagBody来将其像WebmarkupContainer一样对待:

public class CustomFormComponentPanel extends FormComponentPanel {

    public CustomFormComponentPanel(String id) {
        super(id);
        // Various Form Items
    }

    @Override
    protected void onComponentTagBody(final MarkupStream markupStream, final ComponentTag openTag) {
        // Render as a WebMarkupContainer, not a panel
        super.renderComponentTagBody(markupStream, openTag);
    }
}

然后,我可以像这样添加FormComponentPanel:

add(new CustomFormComponentPanel("custom"));

这个标记

<span wicket:id="custom">
    <!-- Various form Items -->
</span>

Fragment的onComponentTagBody()在Fragment类中调用了许多私有方法,我认为您必须重复这些方法。 一次性使用上面的我的方法。 如果您真的需要重复使用它,我将按照原先的意图使用一个面板。

您必须以这种方式将内部输入组件添加到片段中:

Fragment f = new Fragment("estimatedDuration", "duration_fragment", OptionsPanel.this);
f.add(new TextField("estimated_duration", new Model<String>("3"));
f.add(...);    
[form.]add(f);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM