Example usage for org.apache.wicket.markup.html.form Radio getMarkupId

List of usage examples for org.apache.wicket.markup.html.form Radio getMarkupId

Introduction

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

Prototype

public String getMarkupId(boolean createIfDoesNotExist) 

Source Link

Document

Retrieves id by which this component is represented within the markup.

Usage

From source file:org.efaps.ui.wicket.components.values.BooleanField.java

License:Apache License

/**
 * @param _wicketId wicket id for this component
 * @param _value value of this component
 * @param _choices choices/* www.  ja v  a2s  . c  o  m*/
 * @param _fieldConfiguration configuration for this field
 * @param _label label for this field
 */
public BooleanField(final String _wicketId, final Object _value, final IModel<Map<Object, Object>> _choices,
        final FieldConfiguration _fieldConfiguration, final String _label, final boolean _uniqueName) {
    super(_wicketId, new Model<Boolean>());
    setOutputMarkupId(true);
    setRequired(_fieldConfiguration.getField().isRequired());
    this.fieldConfiguration = _fieldConfiguration;
    this.label = _label;
    // make a unique name if in a fieldset
    this.inputName = _fieldConfiguration.getName()
            + (_uniqueName ? "_" + RandomStringUtils.randomAlphabetic(4) : "");
    final RadioGroup<Boolean> radioGroup = new RadioGroup<Boolean>("radioGroup") {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        public String getInputName() {
            return BooleanField.this.inputName;
        }
    };

    if (_value == null) {
        radioGroup.setDefaultModel(new Model<Boolean>());
    } else {
        radioGroup.setDefaultModel(Model.of((Boolean) _value));
    }
    add(radioGroup);
    final Iterator<Entry<Object, Object>> iter = _choices.getObject().entrySet().iterator();

    final Entry<Object, Object> first = iter.next();
    final Boolean firstVal = (Boolean) first.getValue();
    final Radio<Boolean> radio1 = new Radio<Boolean>("choice1", Model.of(firstVal), radioGroup) {

        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        public String getValue() {
            return firstVal.toString();
        }
    };
    radio1.setLabel(Model.of((String) first.getKey()));
    radioGroup.add(radio1);
    final String markupId1 = radio1.getMarkupId(true);
    radioGroup.add(new Label("label1", Model.of((String) first.getKey())) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(final ComponentTag _tag) {
            super.onComponentTag(_tag);
            _tag.put("for", markupId1);
        }
    });

    final Entry<Object, Object> second = iter.next();
    final Boolean secondVal = (Boolean) second.getValue();
    final Radio<Boolean> radio2 = new Radio<Boolean>("choice2", Model.of(secondVal), radioGroup) {
        /** The Constant serialVersionUID. */
        private static final long serialVersionUID = 1L;

        @Override
        public String getValue() {
            return secondVal.toString();
        }
    };
    radio2.setLabel(Model.of((String) second.getKey()));
    radioGroup.add(radio2);
    final String markupId2 = radio2.getMarkupId(true);
    radioGroup.add(new Label("label2", Model.of((String) second.getKey())) {

        private static final long serialVersionUID = 1L;

        @Override
        protected void onComponentTag(final ComponentTag _tag) {
            super.onComponentTag(_tag);
            _tag.put("for", markupId2);
        }
    });
}

From source file:org.wicketstuff.datatable_autocomplete.table.button.ButtonListView.java

License:Apache License

private IModel<String> createRadioRequireSelectedRowModel(final List<Radio<?>> radioList) {

    return new LoadableDetachableModel<String>() {

        /**/*w  w w.jav a2s.  c  om*/
         * 
         */
        private static final long serialVersionUID = 8113932643386163719L;

        /*
         * (non-Javadoc)
         * 
         * @see org.apache.wicket.model.LoadableDetachableModel#load()
         */
        @Override
        protected String load() {

            StringBuffer template = new StringBuffer();

            template.append("if (");

            for (int i = 0; i < radioList.size(); i++) {

                Radio<?> radio = radioList.get(i);

                template.append("(Wicket.$('" + radio.getMarkupId(true) + "').checked == false)");

                if (i > 0 && i < radioList.size() - 1) {
                    template.append(" and ");
                }
                radio.setOutputMarkupId(true);
            }

            template.append("{" + "\nalert ('A selected row is required.');" + "\nreturn false;" + "\n}");

            return template.toString();

        }

    };

}