简体   繁体   中英

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

I am putting a TextField and a DropDownChoice inside a FormComponentPanel which is supposed to use setConvertedInput to TextField's value concatenated with DropDownChoice's value. However, I would like to put the markup for the FormComponentPanel inside a wicket:fragment in the markup file that contains the containing form.

Here's an abrreviated version of what I tried so far:

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>

The end result of this atm is that the markup for the FormComponentPanel is empty.

I'm not sure how easy it will be to do as a Fragment. I have frequently extended FormComponentPanel and treated it like a WebmarkupContainer by overriding onComponentTagBody like so:

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

I can then just add my FormComponentPanel like so:

add(new CustomFormComponentPanel("custom"));

with this markup

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

Fragment's onComponentTagBody() calls a lot of private methods in the Fragment class that I presume you would have to duplicate. For a one-off, use my method above. If you really need to re-use it, I'd go with a Panel as originally intended.

You have to add the inner inputs components to the fragments, in this fashion:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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