externalcontext

Difference between @ManagedProperty and FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(“bean”)

混江龙づ霸主 提交于 2020-01-06 20:10:00
问题 What's the difference between: public class GameController implements Serializable{ @ManagedProperty(value="#{Gamebean}") private Game game; and public class GameController implements Serializable{ private Game game; public GameController(){ game =(Game)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("Gamebean"); } and if there's no difference what method is better ? Cheers. 回答1: The @ManagedProperty way will autocreate bean if it doesn't exist yet. The

ExternalContext#getResourceAsStream() returns null, where to place the resource file?

孤人 提交于 2019-12-06 10:41:27
问题 I'm trying to obtain a PNG file as InputStream in my managed bean as below: ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext(); InputStream input = externalContext.getResourceAsStream("/myFile.png"); // input is null. However, the InputStream is always null. How is this caused and how can I solve it? 回答1: Apparently you placed the resource in physically the wrong location. The ExternalContext#getResourceAsStream(), which delegates in case of servlet

What is the difference between FacesContext and ExternalContext

只愿长相守 提交于 2019-11-28 17:09:02
问题 What is the difference between FacesContext and ExternalContext ? When can I use one or other? What has the one and what has the other? The following sample is from the book JavaServer Faces 3rd edition: <h:commandButton ... actionListener="#{rushmore.handleMouseClick}" /> Backing bean: public void handleMouseClick(ActionEvent e) { FacesContext context = FacesContext.getCurrentInstance(); String clientId = e.getComponent().getClientId(context); Map<String, String> requestParams = context