本文整理匯總了Java中org.springframework.ui.Model.containsAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java Model.containsAttribute方法的具體用法?Java Model.containsAttribute怎麽用?Java Model.containsAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.ui.Model
的用法示例。
在下文中一共展示了Model.containsAttribute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: settings
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/{ssoId}/settings", method = RequestMethod.GET)
public String settings(@PathVariable("ssoId") String ssoId, Model model, RedirectAttributes attr){
if(!ssoId.equals(userService.getPrincipal())){
attr.addFlashAttribute("error","You are not allowed to visit this page.");
return "redirect:/error";
}
User user = userService.getUserBySsoId(ssoId, false);
if(user == null){
attr.addFlashAttribute("error","User does not exist");
return "redirect:/error";
}
if(!model.containsAttribute("userSettingsDTO")) {
UserSettingsDTO userSettingsDTO = new UserSettingsDTO(user.getSsoId(), user.getEmail(), user.getName(), user.getUserDetail().getUserBio());
model.addAttribute("userSettingsDTO", userSettingsDTO);
}
model.addAttribute("userName", userService.getPrincipal());
model.addAttribute("categories", categoryService.getCategories());
return "settings";
}
示例2: settings
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/{ssoId}/settings", method = RequestMethod.GET)
public String settings(@PathVariable("ssoId") String ssoId, Model model, RedirectAttributes attr){
if(!ssoId.equals(userService.getPrincipal())){
attr.addFlashAttribute("error","You are not allowed to visit this page.");
return "redirect:/oups";
}
User user = userService.getUserBySsoId(ssoId, false);
if(user == null){
attr.addFlashAttribute("error","User does not exist");
return "redirect:/oups";
}
if(!model.containsAttribute("userSettingsDTO")) {
UserSettingsDTO userSettingsDTO = new UserSettingsDTO(user.getSsoId(), user.getEmail(), user.getName(), user.getUserDetail().getUserBio());
model.addAttribute("userSettingsDTO", userSettingsDTO);
}
model.addAttribute("userName", userService.getPrincipal());
model.addAttribute("categories", categoryService.getCategories());
return "settings";
}
示例3: showLists
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Send user to a page showing all his lists
*/
@RequestMapping(value = "/list", method = RequestMethod.GET)
public ModelAndView showLists(Principal principal, Model model) {
LOGGER.debug("home() method of MvcController called for user: {}", principal.getName());
ModelAndView mav = new ModelAndView("showAllLists", model.asMap());
List<ShoppingList> shoppingLists = repositoryService.getShoppingLists(principal.getName());
mav.addObject("shoppingLists", shoppingLists); //current ShoppingLists of the user to display
if(!model.containsAttribute("newList"))
mav.addObject("newList", new ShoppingListDTO()); //backing object for name of the new ShoppingList
mav.addObject("listToDelete", new ShoppingListDTO()); //backing object for ShoppingList to delete
return mav;
}
示例4: showRegistrationForm
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Shows registration form for unlogged users, if user is logged shows message and link to the home page
* @param model
*/
@RequestMapping(value = "/register", method = RequestMethod.GET)
public ModelAndView showRegistrationForm(Model model) {
LOGGER.debug("showRegistrationForm() called");
ModelAndView mav = new ModelAndView("register", model.asMap());
if(!model.containsAttribute("newUser"))
mav.addObject("newUser", new AppUserDTO());
return mav;
}
示例5: displayForm
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(method = RequestMethod.GET)
protected String displayForm(HttpServletRequest request, Model model) throws Exception {
UserSettingsCommand command;
if(!model.containsAttribute("command")) {
command = new UserSettingsCommand();
User user = getUser(request);
if (user != null) {
command.setUser(user);
command.setEmail(user.getEmail());
UserSettings userSettings = settingsService.getUserSettings(user.getUsername());
command.setTranscodeSchemeName(userSettings.getTranscodeScheme().name());
command.setAllowedMusicFolderIds(Util.toIntArray(getAllowedMusicFolderIds(user)));
} else {
command.setNewUser(true);
command.setStreamRole(true);
command.setSettingsRole(true);
}
} else {
command = (UserSettingsCommand) model.asMap().get("command");
}
command.setAdmin(User.USERNAME_ADMIN.equals(command.getUsername()));
command.setUsers(securityService.getAllUsers());
command.setTranscodingSupported(transcodingService.isDownsamplingSupported(null));
command.setTranscodeDirectory(transcodingService.getTranscodeDirectory().getPath());
command.setTranscodeSchemes(TranscodeScheme.values());
command.setLdapEnabled(settingsService.isLdapEnabled());
command.setAllMusicFolders(settingsService.getAllMusicFolders());
model.addAttribute("command", command);
return "userSettings";
}
示例6: index
import org.springframework.ui.Model; //導入方法依賴的package包/類
@GetMapping("/")
public String index(Model model) {
if (model.containsAttribute("name")) {
String name = (String) model.asMap().get("name");
Map<String, String> greeting = helloworldService.greeting(name);
model.addAttribute("greeting", greeting);
}
model.addAttribute("messages", guestbookService.all());
return "index";
}
示例7: index
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping
public String index(HttpServletRequest httpServletRequest, Model uiModel, @RequestParam(value = "type", required = false) String type) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String eppn = auth.getName();
if(uiModel.containsAttribute("type")){
Map<String, ?> flashInputMap = RequestContextUtils.getInputFlashMap(httpServletRequest);
if(flashInputMap.containsKey("type")){
type = (String) flashInputMap.get("type");
}
}
if(type==null){
type="";
}
uiModel.addAttribute("selectedType", type);
ObjectMapper mapper = new ObjectMapper();
String jsonStats = "";
String jsonStatsRm = "";
List<String> prefsStats = new ArrayList<>();
List<String> prefsStatsRm = new ArrayList<>();
try {
if(preferencesService.getPrefs(eppn, KEY)!=null){
prefsStats = Arrays.asList(preferencesService.getPrefs(eppn, KEY).getValue().split("\\s*,\\s*"));
}
jsonStats = mapper.writeValueAsString(prefsStats);
if(preferencesService.getPrefs(eppn, KEYRM)!=null){
prefsStatsRm = Arrays.asList(preferencesService.getPrefs(eppn, KEYRM).getValue().split("\\s*,\\s*"));
}
jsonStatsRm = mapper.writeValueAsString(prefsStatsRm);
} catch (Exception e) {
e.printStackTrace();
}
uiModel.addAttribute("prefs",jsonStats);
uiModel.addAttribute("prefsRm",jsonStatsRm);
uiModel.addAttribute("prefsRmList",prefsStatsRm);
return "manager/stats";
}
示例8: loginPage
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(Model model, HttpServletRequest request){
if(userService.getPrincipal() != null){ return "redirect:/"; }
if(!model.containsAttribute("userDTO")){
model.addAttribute("userDTO", new UserDTO());
}
return "login";
}
示例9: isYadaNotifySaved
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Check if the YadaNotify.yadaSave() has been called in this request
* @param model can be null
* @param redirectAttributes can be null
* @return
*/
@Deprecated
public static boolean isYadaNotifySaved(Model model, RedirectAttributes redirectAttributes) {
boolean result = false;
if (model!=null) {
result = model.containsAttribute(KEY_NOTIFICATION_TITLE);
}
if (redirectAttributes!=null) {
result |= redirectAttributes.getFlashAttributes().containsKey(KEY_NOTIFICATION_TITLE);
}
return result;
}
示例10: admin
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value= {"","/"} , method = RequestMethod.GET)
public String admin(Model model){
model.addAttribute("userName", userService.getPrincipal());
model.addAttribute("categories", categoryService.getCategories());
if(!model.containsAttribute("userDTO")){
model.addAttribute("userDTO", new UserDTO());
}
if(!model.containsAttribute("categoryDTO")){
model.addAttribute("categoryDTO", new CategoryDTO());
}
model.addAttribute("fileUpload", new FileUpload());
model.addAttribute("accountStates", getAccountStates());
return "admin";
}
示例11: createArticleGET
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String createArticleGET(Model model){
if(!model.containsAttribute("articleDTO")){
model.addAttribute("articleDTO", new ArticleDTO());
}
model.addAttribute("categories", categoryService.getCategories());
model.addAttribute("userName", userService.getPrincipal());
return "article_add";
}
示例12: error
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value = "/oups")
public String error(Model model){
if(!model.containsAttribute("error")){
model.addAttribute("error", "You do not have the permission to access this page.");
}
if(userService.getPrincipal() != null){
model.addAttribute("categories", categoryService.getCategories());
model.addAttribute("userName", userService.getPrincipal());
}
return "error";
}
示例13: admin
import org.springframework.ui.Model; //導入方法依賴的package包/類
@RequestMapping(value= {"","/"} , method = RequestMethod.GET)
public String admin(Model model){
model.addAttribute("userName", userService.getPrincipal());
model.addAttribute("categories", categoryService.getCategories());
if(!model.containsAttribute("userDTO")){
model.addAttribute("userDTO", new UserDTO());
}
if(!model.containsAttribute("categoryDTO")){
model.addAttribute("categoryDTO", new CategoryDTO());
}
model.addAttribute("fileUpload", new FileUpload());
model.addAttribute("accountStates", State.getAccountStates());
return "admin";
}
示例14: notifyModal
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Da usare direttamente solo quando si vuole fare un redirect dopo aver mostrato un messaggio.
* Se chiamato tante volte, i messaggi si sommano e vengono mostrati tutti all'utente.
* @param title
* @param message
* @param severity a string like YadaConstants.VAL_NOTIFICATION_SEVERITY_OK
* @param redirectSemiurl e.g. "/user/profile"
* @param model
* @see YadaConstants
* @deprecated Use YadaNotify instead
*/
@Deprecated
public void notifyModal(String title, String message, String severity, String redirectSemiurl, Model model) {
if (severity==VAL_NOTIFICATION_SEVERITY_ERROR) {
// Tutte le notifiche di errore vengono loggate a warn (potrebbero non essere degli errori del programma)
log.warn("notifyModal: {} - {}", title, message);
}
// Mette nel model tre array di stringhe che contengono titolo, messaggio e severity.
if (!model.containsAttribute(KEY_NOTIFICATION_TITLE)) {
List<String> titles = new ArrayList<String>();
List<String> bodies = new ArrayList<String>();
List<String> severities = new ArrayList<String>();
model.addAttribute(KEY_NOTIFICATION_TITLE, titles);
model.addAttribute(KEY_NOTIFICATION_BODY, bodies);
model.addAttribute(KEY_NOTIFICATION_SEVERITY, severities);
}
// Aggiunge i nuovi valori
Map<String, Object> modelMap = model.asMap();
((List<String>)modelMap.get(KEY_NOTIFICATION_TITLE)).add(title);
((List<String>)modelMap.get(KEY_NOTIFICATION_BODY)).add(message);
((List<String>)modelMap.get(KEY_NOTIFICATION_SEVERITY)).add(severity);
// Il redirect è sempre uno solo: prevale l'ultimo
if (redirectSemiurl!=null) {
model.addAttribute(KEY_NOTIFICATION_REDIRECT, redirectSemiurl);
}
String newTotalSeverity = calcTotalSeverity(modelMap, severity);
model.addAttribute(KEY_NOTIFICATION_TOTALSEVERITY, newTotalSeverity);
}
示例15: callScriptOnModal
import org.springframework.ui.Model; //導入方法依賴的package包/類
/**
* Add a script id to call when opening the notification modal
* @param scriptId
* @param model
* @deprecated Use YadaNotify instead
*/
@Deprecated
public void callScriptOnModal(String scriptId, Model model) {
if (!model.containsAttribute(KEY_NOTIFICATION_CALLSCRIPT)) {
List<String> scriptIds = new ArrayList<String>();
model.addAttribute(KEY_NOTIFICATION_CALLSCRIPT, scriptIds);
}
Map<String, Object> modelMap = model.asMap();
((List<String>)modelMap.get(KEY_NOTIFICATION_CALLSCRIPT)).add(scriptId);
}