Commit 77257bf0 by Tuukka Kivilahti

Merge branch 'facesContextFix' into 'master'

Faces context fix

Remove injecting FacesContext to managed beans (Views) and instead use FacesContext.getInstance()

May fix IllegalStateExceptions

kattonu: @tkfftk
2 parents 4833901d 9689613c
...@@ -9,7 +9,6 @@ import java.util.zip.CRC32; ...@@ -9,7 +9,6 @@ import java.util.zip.CRC32;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext; import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
...@@ -29,8 +28,8 @@ public class ErrorPageView implements Serializable { ...@@ -29,8 +28,8 @@ public class ErrorPageView implements Serializable {
// private static final long serialVersionUID = -2179309061036632342L; // private static final long serialVersionUID = -2179309061036632342L;
String trace; String trace;
@Inject // @Inject
private transient FacesContext context; // private transient FacesContext context;
@SuppressWarnings("unused") @SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class); private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class);
...@@ -70,16 +69,11 @@ public class ErrorPageView implements Serializable { ...@@ -70,16 +69,11 @@ public class ErrorPageView implements Serializable {
} }
public String getTrail() { public String getTrail() {
HttpServletRequest req = (HttpServletRequest) getContext().getExternalContext().getRequest(); FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest req = (HttpServletRequest) context.getExternalContext().getRequest();
Object trail = req.getSession().getAttribute(HostnameFilter.HTTP_TRAIL_NAME); Object trail = req.getSession().getAttribute(HostnameFilter.HTTP_TRAIL_NAME);
return trail != null ? trail.toString() : ""; return trail != null ? trail.toString() : "";
} }
public FacesContext getContext() {
return context;
}
public void setContext(FacesContext context) {
this.context = context;
}
} }
\ No newline at end of file
...@@ -9,7 +9,6 @@ import java.util.Map; ...@@ -9,7 +9,6 @@ import java.util.Map;
import javax.ejb.EJB; import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped; import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent; import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject; import javax.inject.Inject;
import javax.inject.Named; import javax.inject.Named;
...@@ -41,9 +40,6 @@ public class MenuView { ...@@ -41,9 +40,6 @@ public class MenuView {
@Inject @Inject
private transient SessionStore sessionstore; private transient SessionStore sessionstore;
@Inject
private transient FacesContext context;
@EJB @EJB
private transient MenuBeanLocal menubean; private transient MenuBeanLocal menubean;
...@@ -63,8 +59,8 @@ public class MenuView { ...@@ -63,8 +59,8 @@ public class MenuView {
public List<PageContent> getPagecontent(String pagekey) public List<PageContent> getPagecontent(String pagekey)
{ {
String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString(); String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString();
// Removed by tkfftk, enought is enought // Removed by tkfftk, enought is enought
// logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key)); // logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key));
if (!contents.containsKey(key)) { if (!contents.containsKey(key)) {
contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale())); contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale()));
...@@ -234,10 +230,6 @@ public class MenuView { ...@@ -234,10 +230,6 @@ public class MenuView {
return ret; return ret;
} }
public void setContext(FacesContext context) {
this.context = context;
}
public LayoutView getLayoutview() { public LayoutView getLayoutview() {
return layoutview; return layoutview;
} }
......
...@@ -38,8 +38,6 @@ public class LayoutView implements Serializable { ...@@ -38,8 +38,6 @@ public class LayoutView implements Serializable {
* *
*/ */
private static final long serialVersionUID = 4468645109141859301L; private static final long serialVersionUID = 4468645109141859301L;
@Inject
private FacesContext context;
private ResourceBundle rb; private ResourceBundle rb;
private String pagename; private String pagename;
@EJB @EJB
...@@ -106,6 +104,7 @@ public class LayoutView implements Serializable { ...@@ -106,6 +104,7 @@ public class LayoutView implements Serializable {
} }
public String getPagepath() { public String getPagepath() {
FacesContext context = FacesContext.getCurrentInstance();
if (pagename == null && if (pagename == null &&
context != null && context != null &&
context.getExternalContext() != null && context.getExternalContext() != null &&
...@@ -140,6 +139,8 @@ public class LayoutView implements Serializable { ...@@ -140,6 +139,8 @@ public class LayoutView implements Serializable {
} }
private ResourceBundle getResourcebundle() { private ResourceBundle getResourcebundle() {
FacesContext context = FacesContext.getCurrentInstance();
if (rb == null) { if (rb == null) {
rb = context.getApplication().getResourceBundle(context, "i18n"); rb = context.getApplication().getResourceBundle(context, "i18n");
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!