use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class BaseWorkspaceController method getOrcidHash.
@ModelAttribute("orcidIdHash")
String getOrcidHash(HttpServletRequest request) throws Exception {
HttpSession session = request.getSession(false);
String hash = session != null ? (String) session.getAttribute(ORCID_ID_HASH) : null;
if (!PojoUtil.isEmpty(hash)) {
return hash;
}
hash = profileEntityManager.getOrcidHash(getEffectiveUserOrcid());
if (session != null) {
request.getSession().setAttribute(ORCID_ID_HASH, hash);
}
return hash;
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class WorkspaceController method retrieveCurrencyCodesTypesAsMap.
@ModelAttribute("currencyCodeTypes")
public Map<String, String> retrieveCurrencyCodesTypesAsMap() {
Map<String, String> currencyCodeTypes = new LinkedHashMap<String, String>();
//Add an empty one
currencyCodeTypes.put("", "");
for (Currency currency : Currency.getAvailableCurrencies()) {
currencyCodeTypes.put(currency.getCurrencyCode(), currency.getCurrencyCode());
}
return FunctionsOverCollections.sortMapsByValues(currencyCodeTypes);
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class ResultContainer method retrieveGroupTypes.
@ModelAttribute("groupTypes")
public Map<String, String> retrieveGroupTypes() {
MemberType[] groupTypes = MemberType.values();
Map<String, String> groupTypesMap = new TreeMap<String, String>();
for (MemberType groupType : groupTypes) {
String key = groupType.value();
String value = key.replace('-', ' ');
groupTypesMap.put(key, value);
}
return groupTypesMap;
}
use of org.springframework.web.bind.annotation.ModelAttribute in project ORCID-Source by ORCID.
the class ManageConsortiumController method retrieveContactRoleTypesAsMap.
@ModelAttribute("contactRoleTypes")
public Map<String, String> retrieveContactRoleTypesAsMap() {
Map<String, String> map = new LinkedHashMap<>();
for (ContactRoleType type : ContactRoleType.values()) {
map.put(type.name(), getMessage(buildInternationalizationKey(ContactRoleType.class, type.name())));
}
Map<String, String> sorted = new LinkedHashMap<>();
// @formatter:off
map.entrySet().stream().sorted(Map.Entry.<String, String>comparingByValue()).forEachOrdered(x -> sorted.put(x.getKey(), x.getValue()));
// @formatter:on
return sorted;
}
use of org.springframework.web.bind.annotation.ModelAttribute in project spring-framework by spring-projects.
the class ErrorsMethodArgumentResolver method getModelAttributeName.
private String getModelAttributeName(MethodParameter parameter) {
Assert.isTrue(parameter.getParameterIndex() > 0, "Errors argument must be immediately after a model attribute argument.");
int index = parameter.getParameterIndex() - 1;
MethodParameter attributeParam = new MethodParameter(parameter.getMethod(), index);
Class<?> attributeType = attributeParam.getParameterType();
ResolvableType type = ResolvableType.forMethodParameter(attributeParam);
ReactiveAdapter adapter = getAdapterRegistry().getAdapter(type.resolve());
Assert.isNull(adapter, "Errors/BindingResult cannot be used with an async model attribute. " + "Either declare the model attribute without the async wrapper type " + "or handle WebExchangeBindException through the async type.");
ModelAttribute annot = parameter.getParameterAnnotation(ModelAttribute.class);
if (annot != null && StringUtils.hasText(annot.value())) {
return annot.value();
}
// TODO: Conventions does not deal with async wrappers
return ClassUtils.getShortNameAsProperty(attributeType);
}
Aggregations