コード例 #1
0
  protected boolean setParameters(
      final CommandRequest request,
      final PanelProviderParameter[] params,
      final PanelInstance instance,
      final boolean specificParameters)
      throws Exception {
    final boolean anyParamWritten[] = new boolean[] {false};

    new HibernateTxFragment() {
      @Override
      protected void txFragment(Session session) throws Throwable {
        super.txFragment(session);
        String language = LocaleManager.lookup().getCurrentLang();

        if (params != null && params.length > 0) {
          for (int i = 0; i < params.length; i++) {
            if (params[i]
                .getProvider()
                .getProperties()
                .containsKey("parameter." + params[i].getId())) {
              continue;
            }
            String value = params[i].readFromRequest(request.getRequestObject());
            log.debug(
                "Panel "
                    + instance.getInstanceId()
                    + " field:"
                    + params[i].getId()
                    + " = "
                    + value);
            if (params[i].isI18n()) {
              String oldValue = instance.getParameterValue(params[i].getId(), language);
              if (!RenderUtils.noNull(oldValue).equals(RenderUtils.noNull(value))
                  && params[i].isValid(value)) {
                instance.setParameterValue(params[i].getId(), value, language);
                anyParamWritten[0] = true;
              }
            } else {
              String oldValue = instance.getParameterValue(params[i].getId());
              if (!RenderUtils.noNull(oldValue).equals(RenderUtils.noNull(value))
                  && params[i].isValid(value)) {
                instance.setParameterValue(params[i].getId(), value);
                anyParamWritten[0] = true;
              }
            }

            if (!params[i].isValid(value)) formStatus.addWrongField(params[i].getId());
          }
        }
      }
    }.execute();

    if (formStatus.getWrongFields().length == 0) {
      if (anyParamWritten[0]) {
        if (specificParameters) instance.saveCustomProperties();
        else instance.saveProperties();
      }
      return true;
    }
    return false;
  }