使用wicket禁用/启用文本框

时间:2015-06-10 11:17:39

标签: java wicket

我的要求是基于复选框检查组,将禁用或启用送货地址字段。

明确我的要求:Wicket id:" nonDigital"有6个复选框。如果选中任何一个复选框,则只启用送货地址部分,然后只有用户才能输入值。

这是我的代码

我的HTML代码:

 <fieldset class="deliveryFormats">
          <h2 class="sectionHeading">Delivery Formats</h2>
          <span class="required">* Required Field</span>
         <br/>
            <div class="leftDiv">
          <label>Non-digital</label>
          <div class="radioLabel" wicket:id="nonDigital" >
            <label>
             <input class="checkbox" type="checkbox" name="formatType" />Beta SP NTSC
            </label>
           </div><!--  /.radioLabel non digital -->
</fieldset>
<fieldset class="shippingAddress" style="border-bottom: 0px;" >
           <h2 class="sectionHeading">Shipping Address</h2>
          <table class="form">
            <tbody>
              <tr>
                <th class="fieldName" scope="row">Company</th>
                <td class="fieldEdit">
                  <input class="organization" type="text" wicket:id="address.organization"/>
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">Address 1</th>
                <td class="fieldEdit">
                  <input class="long" type="text" wicket:id="address.line1">
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">Address 2</th>
                <td class="fieldEdit">
                  <input class=" long" type="text" wicket:id="address.line2">
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">Address 3</th>
                <td class="fieldEdit">
                  <input class="long" type="text" wicket:id="address.line3">
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">City</th>
                <td class="fieldEdit">
                  <input class="long" type="text" wicket:id="address.city"/>
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">State</th>
                <td class="fieldEdit">
                  <input class="long" type="text" wicket:id="address.state"/>
                </td>
              </tr>
              <tr>
                <th class="fieldName" scope="row">Postal Code</th>
                <td class="fieldEdit">
                  <input class="postalcode" type="text" wicket:id="address.postalCode"/>
                </td>
              </tr>
            </tbody>
          </table>

Java代码:

List<DeliveryFormat> formatChoices = lookupProcessor.getLookupValues(DeliveryFormat.class);
List<DeliveryFormat> nonDigital = new ArrayList<DeliveryFormat>();
List<DeliveryFormat> digital = new ArrayList<DeliveryFormat>();

            Iterator<DeliveryFormat> nondigitalIterator = formatChoices.iterator();
            while(nondigitalIterator.hasNext()){
                DeliveryFormat df = nondigitalIterator.next();
                if(df.getLabel().equals("Audio Bundle") || df.getLabel().equals("XDCAM file")|| df.getLabel().equals("FTP")){
                    digital.add(df);
                }
                else
                {
                    nonDigital.add(df);
                }
            }

         //Add the check boxes for Delivery format for digital List

          // add(new CheckBoxMultipleChoice<DeliveryFormat>("nonDigital", nonDigital, new ChoiceRenderer<DeliveryFormat>("label")));
         ChoiceRenderer<DeliveryFormat> deliveryFormatShippment = new ChoiceRenderer<DeliveryFormat>("label", "id");
            CheckBoxMultipleChoice<DeliveryFormat> nonDigitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
                    "nonDigital", nonDigital, deliveryFormatShippment);

            CheckBoxMultipleChoice<DeliveryFormat> digitalDelivery = new CheckBoxMultipleChoice<DeliveryFormat>(
                    "digital", digital, deliveryFormatShippment);
            add(nonDigitalDelivery);
 /*final CheckBox test = new CheckBox("nonDigital");
            test.setOutputMarkupId(true);

            nonDigitalDelivery.add(new AjaxEventBehavior("onKeyUp")
            {

                *//**
                 * 
                 *//*
                private static final long serialVersionUID = 1L;

                @Override
                protected void onEvent(AjaxRequestTarget target) {
                    // TODO Auto-generated method stub

                    test.setEnabled(false);
                    target.addComponent(test);
                }

            });*/

1 个答案:

答案 0 :(得分:0)

您应该尝试启用markupid:

textArea.setOutputMarkupId(true);

然后将此组件添加到目标:

textArea.setEnabled(false):
target.add(textArea);