Compare commits
16 Commits
9dd7da73c2
...
cbef0da7e2
Author | SHA1 | Date |
---|---|---|
tim holloway | cbef0da7e2 | 3 months ago |
tim holloway | 398ecc8bf4 | 3 months ago |
tim holloway | b9d6aea3ea | 3 months ago |
tim holloway | 95ceb82eed | 3 months ago |
tim holloway | d1930a1a66 | 3 months ago |
tim holloway | a792f5d2b7 | 3 months ago |
tim holloway | fa16c0bf9a | 3 months ago |
tim holloway | fe9598194b | 3 months ago |
tim holloway | a7702e27f3 | 3 months ago |
tim holloway | 205835bb5f | 3 months ago |
tim holloway | 2600500344 | 3 months ago |
tim holloway | 5083086ff4 | 3 months ago |
tim holloway | 68462514db | 3 months ago |
tim holloway | 61942f547a | 3 months ago |
tim holloway | 9cf0f89e76 | 3 months ago |
tim holloway | 8bcd8cb9a1 | 3 months ago |
45 changed files with 860 additions and 638 deletions
@ -0,0 +1,51 @@ |
|||||||
|
package com.mousetech.gourmetj; |
||||||
|
|
||||||
|
import java.util.ArrayList; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
import jakarta.enterprise.context.ApplicationScoped; |
||||||
|
import jakarta.faces.model.SelectItem; |
||||||
|
import jakarta.inject.Named; |
||||||
|
|
||||||
|
/** |
||||||
|
* Appplication-scope data (mostly constants) |
||||||
|
* |
||||||
|
* @author timh |
||||||
|
* @since Feb 1, 2024 |
||||||
|
*/ |
||||||
|
@Named |
||||||
|
@ApplicationScoped |
||||||
|
public class AppBean { |
||||||
|
|
||||||
|
public AppBean() { |
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
} |
||||||
|
|
||||||
|
private List<SelectItem> searchTypeList; |
||||||
|
|
||||||
|
/** |
||||||
|
* @return the searchTypeList |
||||||
|
* @see RecipeSearchType |
||||||
|
* Used by main.xhtml |
||||||
|
*/ |
||||||
|
public List<SelectItem> getSearchTypeList() { |
||||||
|
if (searchTypeList == null) { |
||||||
|
searchTypeList = loadSearchTypeList(); |
||||||
|
} |
||||||
|
return searchTypeList; |
||||||
|
} |
||||||
|
|
||||||
|
private List<SelectItem> loadSearchTypeList() { |
||||||
|
List<SelectItem> list = new ArrayList<SelectItem>(5); |
||||||
|
list.add(new SelectItem(RecipeSearchType.rst_BY_NAME.ordinal(), |
||||||
|
"Title")); |
||||||
|
list.add(new SelectItem(RecipeSearchType.rst_BY_CATEGORY.ordinal(), |
||||||
|
"Category")); |
||||||
|
list.add(new SelectItem(RecipeSearchType.rst_BY_CUISINE.ordinal(), |
||||||
|
"Cuisine")); |
||||||
|
list.add( |
||||||
|
new SelectItem(RecipeSearchType.rst_BY_INGREDIENT.ordinal(), |
||||||
|
"Ingredient")); |
||||||
|
return list; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,142 @@ |
|||||||
|
/** |
||||||
|
* Copyright (C) 2024, Tim Holloway |
||||||
|
* |
||||||
|
* Manages app data persisted client-side in cookies. |
||||||
|
* |
||||||
|
* Date written: Jan 31, 2024 |
||||||
|
* Author: Tim Holloway <timh@mousetech.com> |
||||||
|
*/ |
||||||
|
package com.mousetech.gourmetj; |
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException; |
||||||
|
import java.util.HashMap; |
||||||
|
import java.util.Map; |
||||||
|
import java.util.Map.Entry; |
||||||
|
|
||||||
|
import org.slf4j.Logger; |
||||||
|
import org.slf4j.LoggerFactory; |
||||||
|
|
||||||
|
import jakarta.annotation.PostConstruct; |
||||||
|
import jakarta.enterprise.context.RequestScoped; |
||||||
|
import jakarta.inject.Named; |
||||||
|
|
||||||
|
/** |
||||||
|
* Request caching object for cookie data persistence. |
||||||
|
* Does double-duty serving View Session timeouts. |
||||||
|
* |
||||||
|
* @author timh |
||||||
|
* @since Jan 31, 2024 |
||||||
|
*/ |
||||||
|
@Named |
||||||
|
@RequestScoped |
||||||
|
public class CookieBean { |
||||||
|
|
||||||
|
private static final String KEY_DISPLAY_ROWS = "displayRows"; |
||||||
|
|
||||||
|
private static final String KEY_SEARCH_TYPE = "searchType"; |
||||||
|
|
||||||
|
private static final String KEY_SEARCH_FOR = "searchFor"; |
||||||
|
|
||||||
|
/* Logger */ |
||||||
|
|
||||||
|
private static final Logger log = |
||||||
|
LoggerFactory.getLogger(CookieBean.class); |
||||||
|
|
||||||
|
private Map<String, String> cookieMap; |
||||||
|
|
||||||
|
/** |
||||||
|
* Constructor. |
||||||
|
*/ |
||||||
|
public CookieBean() { |
||||||
|
} |
||||||
|
|
||||||
|
@PostConstruct |
||||||
|
public void init() { |
||||||
|
this.cookieMap = JSFUtils.getCookies(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Persist us to client cookie storage |
||||||
|
* |
||||||
|
* @throws UnsupportedEncodingException (which should never |
||||||
|
* happen) |
||||||
|
*/ |
||||||
|
public void saveCookies() |
||||||
|
throws UnsupportedEncodingException { |
||||||
|
final Map<String, Object> properties = new HashMap<>(); |
||||||
|
properties.put("maxAge", 31536000); |
||||||
|
properties.put("path", "/"); |
||||||
|
properties.put("SameSite", "Strict"); |
||||||
|
|
||||||
|
for (Entry<String, String> e : cookieMap.entrySet()) { |
||||||
|
JSFUtils.outputCookie(e.getKey(), e.getValue(), |
||||||
|
properties); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* Get Cookie value by name |
||||||
|
* |
||||||
|
* @param name Name of the cookie |
||||||
|
* @return Value stored in the cookie |
||||||
|
*/ |
||||||
|
public String getCookieValue(String name) { |
||||||
|
return cookieMap.get(name); |
||||||
|
} |
||||||
|
|
||||||
|
public void setCookieValue(String name, String value) { |
||||||
|
cookieMap.put(name, value); |
||||||
|
} |
||||||
|
|
||||||
|
// ************************
|
||||||
|
// App-specific properties
|
||||||
|
// ************************
|
||||||
|
|
||||||
|
public String getSearchText() { |
||||||
|
return cookieMap.get(KEY_SEARCH_FOR); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSearchText(String value) { |
||||||
|
cookieMap.put(KEY_SEARCH_FOR, value); |
||||||
|
} |
||||||
|
|
||||||
|
// **
|
||||||
|
public Integer getSearchType() { |
||||||
|
if (!cookieMap.containsKey(KEY_SEARCH_TYPE)) { |
||||||
|
cookieMap.put(KEY_SEARCH_TYPE, "0"); |
||||||
|
} |
||||||
|
String st = cookieMap.get(KEY_SEARCH_TYPE); |
||||||
|
return Integer.valueOf(String.valueOf(st)); |
||||||
|
} |
||||||
|
|
||||||
|
public void setSearchType(Integer value) { |
||||||
|
cookieMap.put(KEY_SEARCH_TYPE, String.valueOf(value)); |
||||||
|
} |
||||||
|
|
||||||
|
// **
|
||||||
|
public Integer getDisplayListSize() { |
||||||
|
if (!cookieMap.containsKey(KEY_DISPLAY_ROWS)) { |
||||||
|
cookieMap.put(KEY_DISPLAY_ROWS, "30"); |
||||||
|
} |
||||||
|
String st = cookieMap.get(KEY_DISPLAY_ROWS); |
||||||
|
return Integer.valueOf(String.valueOf(st)); |
||||||
|
} |
||||||
|
|
||||||
|
public void setDisplayListSize(Integer value) { |
||||||
|
cookieMap.put(KEY_DISPLAY_ROWS, String.valueOf(value)); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* IdleMonitor backing methods (session/View timeout) |
||||||
|
*/ |
||||||
|
public void sessionIdleListener() { |
||||||
|
log.info("Session Idle Listener fired."); |
||||||
|
JSFUtils.addWarningMessage("Timeout approaching. Save your work!"); |
||||||
|
} |
||||||
|
|
||||||
|
public void sessionTimeout() { |
||||||
|
log.info("Session Timeout Listener fired."); |
||||||
|
JSFUtils.logout(); |
||||||
|
} |
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue