Example usage for org.apache.wicket.markup.html.form RadioChoice setPrefix

List of usage examples for org.apache.wicket.markup.html.form RadioChoice setPrefix

Introduction

In this page you can find the example usage for org.apache.wicket.markup.html.form RadioChoice setPrefix.

Prototype

public final RadioChoice<T> setPrefix(String prefix) 

Source Link

Usage

From source file:org.opensingular.form.wicket.mapper.selection.RadioMapper.java

License:Apache License

@Override
public Component appendInput(WicketBuildContext ctx, BSControls formGroup, IModel<String> labelModel) {
    final IModel<? extends SInstance> model = ctx.getModel();
    final SViewSelectionByRadio radioView = (SViewSelectionByRadio) ctx.getView();
    final String id = model.getObject().getName();

    RadioChoice<Serializable> rc = new RadioChoice<Serializable>(id, new SelectSInstanceAwareModel(model),
            new DefaultOptionsProviderLoadableDetachableModel(model), new SingularChoiceRenderer(model)) {

        @Override/*www. j  a  va2 s. co  m*/
        protected IValueMap getAdditionalAttributesForLabel(int index, Serializable choice) {
            IValueMap map = new ValueMap();
            if (radioView.getLayout() == SViewSelectionByRadio.Layout.HORIZONTAL) {
                map.put("class", "radio-inline");
                map.put("style", "position:relative;top:-1px;padding-left:3px;padding-right:10px;");
            } else if (radioView.getLayout() == SViewSelectionByRadio.Layout.VERTICAL) {
                map.put("style",
                        "position:relative;top:-1px;padding-left:3px;padding-right:10px;display:table-cell;");
            }
            return map;
        }

        @Override
        protected IValueMap getAdditionalAttributes(int index, Serializable choice) {
            IValueMap map = new ValueMap();
            map.put("style", "left:20px;");
            return map;
        }

        @Override
        protected void onConfigure() {
            setVisible(!model.getObject().isEmptyOfData());
        }
    };

    if (radioView.getLayout() == SViewSelectionByRadio.Layout.HORIZONTAL) {
        rc.setPrefix("<span style=\"display: inline-block;white-space: nowrap;\">");
        rc.setSuffix("</span>");
    } else if (radioView.getLayout() == SViewSelectionByRadio.Layout.VERTICAL) {
        rc.setPrefix("<span style='display: table;padding: 4px 0;'>");
        rc.setSuffix("</span>");
    }
    formGroup.appendRadioChoice(rc);

    return rc;
}