只需要readonly文本字段

时间:2014-05-19 13:27:55

标签: java

我遇到一个问题,我有一个文本字段,如果该字段是可编辑的,我必须要求它。但是如果该字段是只读的(因为有时字段是基于某些条件的只读字段),那么该字段也是必需的。所以我无法克服它。

虽然如果我在浏览器中检查代码它工作正常,为该字段提供可选项。我使用以下代码:

//defining the values

Boolean isReadonlyWhenHostnameBlank = Boolean.FALSE;
Boolean isNotRequiredWhenHostNameBlank = Boolean.TRUE;

//changing the variable based on some condition i.e. if a particular field having null value.
if (value == null || Arrays.toString(value).equals("[]")) {
  isReadonlyWhenHostnameBlank = Boolean.TRUE;

  isNotRequiredWhenHostNameBlank = Boolean.FALSE;
}

//making it readonly and required based on the condition
if (controlId != null &&
    (controlId.contains("circuit_servers_portassignment") ||
      controlId.contains("circuit_servers_globalip")||
      controlId.contains("circuit_wf_servers_portassignment")||
      controlId.contains("circuit_wf_servers_globalip")||
      controlId.contains("circuit_staticnat_globalIP"))) {

  control.setReadOnly(isReadonlyWhenHostnameBlank);

  control.setRequired(isNotRequiredWhenHostNameBlank);

  System.out.println("isNotRequiredWhenHostNameBlank "+isNotRequiredWhenHostNameBlank);

  System.out.println("isReadonlyWhenHostnameBlank "+isReadonlyWhenHostnameBlank);
}

0 个答案:

没有答案