Compare commits
No commits in common. "7bbd9df62447debef52e21fee47bfa98ab98528a" and "e7f373f6630862208422642ea06f5ed91f6e83a8" have entirely different histories.
7bbd9df624
...
e7f373f663
2
pom.xml
2
pom.xml
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<groupId>com.mousetech.gourmet</groupId>
|
<groupId>com.mousetech.gourmet</groupId>
|
||||||
<artifactId>gourmetj</artifactId>
|
<artifactId>gourmetj</artifactId>
|
||||||
<version>0.2.8</version>
|
<version>0.2.7</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>GourmetJ</name>
|
<name>GourmetJ</name>
|
||||||
|
|
|
@ -68,8 +68,7 @@ public class AdminMainBean implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param cookieBean the cookieBean to set.
|
* @param cookieBean the cookieBean to set
|
||||||
* @deprecated Not invoked by @Inject
|
|
||||||
*/
|
*/
|
||||||
public void setCookieBean(CookieBean cookieBean) {
|
public void setCookieBean(CookieBean cookieBean) {
|
||||||
this.cookieBean = cookieBean;
|
this.cookieBean = cookieBean;
|
||||||
|
@ -211,6 +210,13 @@ public class AdminMainBean implements Serializable {
|
||||||
}
|
}
|
||||||
searchText = searchText.trim();
|
searchText = searchText.trim();
|
||||||
|
|
||||||
|
// Persist current settings
|
||||||
|
try {
|
||||||
|
cookieBean.saveCookies();
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
// Something is really wrong if we can't create UTF-8!
|
||||||
|
log.error("Unable to save cookies!", e);
|
||||||
|
}
|
||||||
RecipeSearchType st = searchtypeEnum();
|
RecipeSearchType st = searchtypeEnum();
|
||||||
switch (st) {
|
switch (st) {
|
||||||
case rst_BY_NAME:
|
case rst_BY_NAME:
|
||||||
|
|
|
@ -17,7 +17,7 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import jakarta.annotation.PostConstruct;
|
import jakarta.annotation.PostConstruct;
|
||||||
import jakarta.faces.view.ViewScoped;
|
import jakarta.enterprise.context.RequestScoped;
|
||||||
import jakarta.inject.Named;
|
import jakarta.inject.Named;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,7 +28,7 @@ import jakarta.inject.Named;
|
||||||
* @since Jan 31, 2024
|
* @since Jan 31, 2024
|
||||||
*/
|
*/
|
||||||
@Named
|
@Named
|
||||||
@ViewScoped
|
@RequestScoped
|
||||||
public class CookieBean {
|
public class CookieBean {
|
||||||
|
|
||||||
private static final String KEY_DISPLAY_ROWS = "displayRows";
|
private static final String KEY_DISPLAY_ROWS = "displayRows";
|
||||||
|
@ -44,15 +44,10 @@ public class CookieBean {
|
||||||
|
|
||||||
private Map<String, String> cookieMap;
|
private Map<String, String> cookieMap;
|
||||||
|
|
||||||
final Map<String, Object> properties = new HashMap<>();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public CookieBean() {
|
public CookieBean() {
|
||||||
properties.put("maxAge", 31536000);
|
|
||||||
properties.put("path", "/");
|
|
||||||
properties.put("SameSite", "Strict");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
|
@ -68,6 +63,11 @@ public class CookieBean {
|
||||||
*/
|
*/
|
||||||
public void saveCookies()
|
public void saveCookies()
|
||||||
throws UnsupportedEncodingException {
|
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()) {
|
for (Entry<String, String> e : cookieMap.entrySet()) {
|
||||||
JSFUtils.outputCookie(e.getKey(), e.getValue(),
|
JSFUtils.outputCookie(e.getKey(), e.getValue(),
|
||||||
properties);
|
properties);
|
||||||
|
@ -86,13 +86,6 @@ public class CookieBean {
|
||||||
|
|
||||||
public void setCookieValue(String name, String value) {
|
public void setCookieValue(String name, String value) {
|
||||||
cookieMap.put(name, value);
|
cookieMap.put(name, value);
|
||||||
try {
|
|
||||||
JSFUtils.outputCookie(name, value, properties);
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// Should never happen. But...
|
|
||||||
log.error("Unable to encode cookie", e);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ************************
|
// ************************
|
||||||
|
@ -104,7 +97,7 @@ public class CookieBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchText(String value) {
|
public void setSearchText(String value) {
|
||||||
setCookieValue(KEY_SEARCH_FOR, value);
|
cookieMap.put(KEY_SEARCH_FOR, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// **
|
// **
|
||||||
|
@ -117,8 +110,7 @@ public class CookieBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSearchType(Integer value) {
|
public void setSearchType(Integer value) {
|
||||||
String st = String.valueOf(value);
|
cookieMap.put(KEY_SEARCH_TYPE, String.valueOf(value));
|
||||||
setCookieValue(KEY_SEARCH_TYPE, st);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// **
|
// **
|
||||||
|
@ -131,13 +123,11 @@ public class CookieBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDisplayListSize(Integer value) {
|
public void setDisplayListSize(Integer value) {
|
||||||
setCookieValue(KEY_DISPLAY_ROWS, String.valueOf(value));
|
cookieMap.put(KEY_DISPLAY_ROWS, String.valueOf(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IdleMonitor backing methods (session/View timeout)
|
* IdleMonitor backing methods (session/View timeout)
|
||||||
* Todo: move to a more general location. Currently
|
|
||||||
* only used by view editor, not Main!
|
|
||||||
*/
|
*/
|
||||||
public void sessionIdleListener() {
|
public void sessionIdleListener() {
|
||||||
log.info("Session Idle Listener fired.");
|
log.info("Session Idle Listener fired.");
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.net.http.HttpResponse;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -13,7 +12,6 @@ import jakarta.faces.context.ExternalContext;
|
||||||
import jakarta.faces.context.FacesContext;
|
import jakarta.faces.context.FacesContext;
|
||||||
import jakarta.faces.context.Flash;
|
import jakarta.faces.context.Flash;
|
||||||
import jakarta.servlet.http.Cookie;
|
import jakarta.servlet.http.Cookie;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
|
||||||
import jakarta.servlet.http.HttpSession;
|
import jakarta.servlet.http.HttpSession;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -128,52 +126,29 @@ public class JSFUtils {
|
||||||
/**
|
/**
|
||||||
* Get cookie values.
|
* Get cookie values.
|
||||||
*/
|
*/
|
||||||
public static Map<String, String> getCookies() {
|
public static Map<String, String> getCookies(){
|
||||||
Map<String, Object> m0 =
|
Map<String, Object> m0 = getExternalContext().getRequestCookieMap();
|
||||||
getExternalContext().getRequestCookieMap();
|
Map<String, String>m1 = new HashMap<String, String>();
|
||||||
Map<String, String> m1 = new HashMap<String, String>();
|
m1 = m0.entrySet()
|
||||||
m1 = m0.entrySet().stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(e -> e.getKey(),
|
.collect(Collectors.toMap(
|
||||||
e -> ((Cookie) e.getValue()).getValue()));
|
e -> e.getKey(),
|
||||||
|
e -> ((Cookie)e.getValue()).getValue()));
|
||||||
return m1;
|
return m1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCookie(String cookieName) {
|
|
||||||
Map<String, Object> map =
|
|
||||||
getExternalContext().getRequestCookieMap();
|
|
||||||
if (map == null) {
|
|
||||||
return null; // no cookies at all
|
|
||||||
}
|
|
||||||
Cookie cookie = (Cookie) map.get(cookieName);
|
|
||||||
if (cookie == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return cookie.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a cookie value in Response.
|
* Set a cookie value in Response.
|
||||||
*
|
|
||||||
* @param name Cookie name
|
* @param name Cookie name
|
||||||
* @param value Cookie value
|
* @param value Cookie value
|
||||||
* @param properties Cookie property Map (timeout,
|
* @param properties Cookie property Map (timeout, <i>etc.</i>)
|
||||||
* <i>etc.</i>)
|
|
||||||
* @throws UnsupportedEncodingException
|
* @throws UnsupportedEncodingException
|
||||||
*/
|
*/
|
||||||
public static void outputCookie(String name, String value,
|
public static void outputCookie(String name,
|
||||||
Map<String, Object> properties)
|
String value, Map<String, Object> properties) throws UnsupportedEncodingException {
|
||||||
throws UnsupportedEncodingException {
|
getExternalContext().addResponseCookie(name,
|
||||||
// getExternalContext().addResponseCookie(name,
|
URLEncoder.encode(value, "UTF-8"),
|
||||||
// URLEncoder.encode(value, "UTF-8"),
|
properties);
|
||||||
// properties);
|
|
||||||
|
|
||||||
Cookie cookie = new Cookie(name, value);
|
|
||||||
cookie.setMaxAge(31536000);
|
|
||||||
cookie.setPath("/");
|
|
||||||
jakarta.servlet.http.HttpServletResponse resp =
|
|
||||||
(HttpServletResponse) getExternalContext()
|
|
||||||
.getResponse();
|
|
||||||
resp.addCookie(cookie);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -720,6 +720,7 @@ public class RecipeDetailBean implements Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recipeService.save(this.getRecipe())) {
|
if (recipeService.save(this.getRecipe())) {
|
||||||
|
////////////userSession.setRecipe(null);
|
||||||
return "recipeDetails?faces-redirect=true";
|
return "recipeDetails?faces-redirect=true";
|
||||||
} else {
|
} else {
|
||||||
JSFUtils.addErrorMessage("Save recipe failed");
|
JSFUtils.addErrorMessage("Save recipe failed");
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE html >
|
|
||||||
<ui:composition template="/WEB-INF/layout/layout.xhtml"
|
<ui:composition template="/WEB-INF/layout/layout.xhtml"
|
||||||
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
xmlns:h="http://xmlns.jcp.org/jsf/html"
|
||||||
xmlns:f="http://xmlns.jcp.org/jsf/core"
|
xmlns:f="http://xmlns.jcp.org/jsf/core"
|
||||||
|
@ -11,12 +10,10 @@
|
||||||
<h:messages />
|
<h:messages />
|
||||||
<h:form id="form1">
|
<h:form id="form1">
|
||||||
<div>
|
<div>
|
||||||
<p:focus />
|
|
||||||
<p:autoComplete id="searchFor" size="45"
|
<p:autoComplete id="searchFor" size="45"
|
||||||
placeholder="Recipe title/cuisine/category, etc.)"
|
placeholder="Recipe title/cuisine/category, etc.)"
|
||||||
value="#{adminMainBean.searchText}"
|
value="#{adminMainBean.searchText}"
|
||||||
completeMethod="#{adminMainBean.searchSuggestionList}"
|
completeMethod="#{adminMainBean.searchSuggestionList}"
|
||||||
onfocus="jQuery('#form1\\:searchFor_input').select();"
|
|
||||||
>
|
>
|
||||||
<f:ajax event="change" execute="@this"
|
<f:ajax event="change" execute="@this"
|
||||||
render="form2:table1"
|
render="form2:table1"
|
||||||
|
@ -26,7 +23,6 @@
|
||||||
<p:outputLabel for="@next" value=" In " />
|
<p:outputLabel for="@next" value=" In " />
|
||||||
<p:selectOneMenu id="ctlSearchType"
|
<p:selectOneMenu id="ctlSearchType"
|
||||||
value="#{cookieBean.searchType}"
|
value="#{cookieBean.searchType}"
|
||||||
onchange="jQuery('#form1\\:searchFor_input').trigger('focus');"
|
|
||||||
>
|
>
|
||||||
<f:selectItems
|
<f:selectItems
|
||||||
value="#{appBean.searchTypeList}"
|
value="#{appBean.searchTypeList}"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user