@GET @Path("/definition/supportedCountries") @Produces({MediaType.APPLICATION_JSON}) @Consumes({MediaType.APPLICATION_JSON}) @PermitAll public Response getCountriesToAbsenceType(@javax.ws.rs.core.Context HttpServletRequest request) { try { AFMetaModelPack data = new AFMetaModelPack(); AFClassInfo classInfo = new AFClassInfo(); classInfo.setName(""); AFFieldInfo fieldInfo = new AFFieldInfo(); fieldInfo.setId("country"); fieldInfo.addRule(new AFValidationRule(SupportedValidations.REQUIRED, "true")); fieldInfo.setWidgetType(SupportedWidgets.DROPDOWNMENU); List<Country> supportedCountries = getCountryManager().findAllCountry(); classInfo.addFieldInfo(fieldInfo); data.setClassInfo(classInfo); HashMap<String, String> options = new HashMap<String, String>(); for (Country country : supportedCountries) { options.put(String.valueOf(country.getId()), country.getName()); } data.setOptionsToFields(options, "country"); return Response.status(Response.Status.OK).entity(data).build(); } catch (NamingException e) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } }
@Override public AFSwinxPanel buildComponent(AFFieldInfo fieldInfo) throws IllegalArgumentException, AFSwinxBuildException { AFSwinxPanel panel = super.buildComponent(fieldInfo); // Add number validator which will provide number validation NumberValidator validator = new NumberValidator(fieldInfo.getWidgetType()); // Use localization based on parent localization validator.setLocalization(localization); panel.addValidator(validator); return panel; }