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;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.inject.Inject;
import javax.inject.Named;
import javax.servlet.http.HttpServletRequest;
......@@ -29,8 +28,8 @@ public class ErrorPageView implements Serializable {
// private static final long serialVersionUID = -2179309061036632342L;
String trace;
@Inject
private transient FacesContext context;
// @Inject
// private transient FacesContext context;
@SuppressWarnings("unused")
private static final Logger logger = LoggerFactory.getLogger(ErrorPageView.class);
......@@ -70,16 +69,11 @@ public class ErrorPageView implements Serializable {
}
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);
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;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.faces.context.FacesContext;
import javax.faces.event.ValueChangeEvent;
import javax.inject.Inject;
import javax.inject.Named;
......@@ -41,9 +40,6 @@ public class MenuView {
@Inject
private transient SessionStore sessionstore;
@Inject
private transient FacesContext context;
@EJB
private transient MenuBeanLocal menubean;
......@@ -63,8 +59,8 @@ public class MenuView {
public List<PageContent> getPagecontent(String pagekey)
{
String key = new StringBuilder(layoutview.getPagepath()).append(":").append(pagekey).toString();
// Removed by tkfftk, enought is enought
// logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key));
// Removed by tkfftk, enought is enought
// logger.debug("Getting pagecontent for key {}. Matches: {}", key, contents.containsKey(key));
if (!contents.containsKey(key)) {
contents.put(key, pagebean.findContentsForUser(key, sessionstore.getLocale()));
......@@ -234,10 +230,6 @@ public class MenuView {
return ret;
}
public void setContext(FacesContext context) {
this.context = context;
}
public LayoutView getLayoutview() {
return layoutview;
}
......
......@@ -38,8 +38,6 @@ public class LayoutView implements Serializable {
*
*/
private static final long serialVersionUID = 4468645109141859301L;
@Inject
private FacesContext context;
private ResourceBundle rb;
private String pagename;
@EJB
......@@ -106,6 +104,7 @@ public class LayoutView implements Serializable {
}
public String getPagepath() {
FacesContext context = FacesContext.getCurrentInstance();
if (pagename == null &&
context != null &&
context.getExternalContext() != null &&
......@@ -140,6 +139,8 @@ public class LayoutView implements Serializable {
}
private ResourceBundle getResourcebundle() {
FacesContext context = FacesContext.getCurrentInstance();
if (rb == null) {
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!