facescontext

Mocking FacesContext

走远了吗. 提交于 2020-01-22 17:13:26
问题 I am trying to add some unit tests to a JSF application. This application didnt rely heavily on any best practices, so many service methods use the FacesContext to pull data from managed session beans like so: (this is inside a util class) public static Object getPageBean(String beanReference) { FacesContext fc = FacesContext.getCurrentInstance(); VariableResolver vr = fc.getApplication().getVariableResolver(); return vr.resolveVariable(fc, beanReference); } What would be the best way to mock

How to use FacesContext.getCurrentInstance(), it returns null

為{幸葍}努か 提交于 2020-01-12 14:08:47
问题 I've been struggling for the last couple of days with the login part of my web app. I've gotten to the point where I can succesfully authenticate a user using the JDBCRealm on tomcat(by reading users from a sql server database). Now I want to send some kind of feedback when the user's account has been blocked, or when the credentials are incorrect, this is where I'm stuck now. I wanted to use this: try { request.login(request.getParameter("user"), request.getParameter("pass")); } catch

How to use FacesContext.getCurrentInstance(), it returns null

心不动则不痛 提交于 2020-01-12 14:08:35
问题 I've been struggling for the last couple of days with the login part of my web app. I've gotten to the point where I can succesfully authenticate a user using the JDBCRealm on tomcat(by reading users from a sql server database). Now I want to send some kind of feedback when the user's account has been blocked, or when the credentials are incorrect, this is where I'm stuck now. I wanted to use this: try { request.login(request.getParameter("user"), request.getParameter("pass")); } catch

Serialize FacesContext or How to get properties-values after Server Restart

怎甘沉沦 提交于 2020-01-03 04:32:38
问题 The problem is the following: I need to serialize the user session, so, it will still be present after a server restarts. Using JavaEE and Tomcat 7 works fine with implements Serializable , but the problem is the FacesContext . Indeed, after restarting the server, FacesContext.getCurrentInstance() returns null , and therefore I cannot access the message bundle (and therefore my message.properties cannot be found anymore). So, how do I keep the FacesContext when restarting Tomcat? 回答1: Your

Access JSF and Primefaces version numbers programmatically

你离开我真会死。 提交于 2019-12-30 05:00:34
问题 I use PrimeFaces 3.5.x and Mojarra JSF 2.1.x I would like to access and show the versions of both libraries programmatically. I use the versions as maven2 properties, but I hope there is an easier way to get the versions. I hope to find something like: Primeface.getVersion(); FacesContext.getCurrentInstance(); A JavaScript based solution would be fine too, since I only want to display the version on a status page. 回答1: For JSF: //returns the major version (2.1) FacesContext.class.getPackage()

Failed to retrieve Session from FacesContext inside a Servlet Filter

↘锁芯ラ 提交于 2019-12-21 05:30:48
问题 After autheticating my user, I want to put a reference in the session to current logged in user. Here how I do it in the setCurrentUser method : FacesContext facesContext = FacesContext.getCurrentInstance(); HttpSession session = (HttpSession) facesContext.getExternalContext().getSession(true); session.setAttribute("CURRENT_USER", currentUser); Unfortunately, the session reference is always null ! Alternatively, I tried with the sessionMap FacesContext facesContext = FacesContext

Faces in ADF can't get the request parameters

寵の児 提交于 2019-12-13 03:34:29
问题 I have an ADF web application with Faces 1.2 In my managed bean I am trying to access the parameters of the post request, but always getting null. This is my post form that I am posting to the Faces: <form name="input" action="http://127.0.01:7072/myapplication/faces/login.jspx" method="post"> <input type="hidden" name="user" id="user" value="myUserName"/> <input type="submit" value="Submit"/> </form> FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("user");

How to inject FacesContext with JSF 2.3 and TomEE?

余生长醉 提交于 2019-12-11 07:33:08
问题 I've been trying to use JSF 2.3 with TomEE server and I'm having problems using the @Inject annotation with the FacesContext object. When I use it, i get the following exception while starting my TomEE server: SEVERE: CDI Beans module deployment failed org.apache.webbeans.exception.WebBeansDeploymentException: javax.enterprise.inject.UnsatisfiedResolutionException: Api type [javax.faces.context.FacesContext] is not found with the qualifiers Qualifiers: [@javax.enterprise.inject.Default()] Am

Why does my FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal() code runs to NullPointer?

大憨熊 提交于 2019-12-11 03:33:39
问题 I have a stateless bean which has a method, where I want to get the current/logged user. My code to get it: Principal p1 = FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal(); But I am getting nullpointer exception on this. Why is that? Or is there any other way to get the logged user? I am using weblogic. 回答1: You're not supposed to grab the FacesContext in an EJB. Even more, your EJBs should be completely free from any JSF dependencies. In other words, you should not

Custom Validator, should I use FacesContext#addMessage() or throw ValidatorException?

别说谁变了你拦得住时间么 提交于 2019-12-10 23:07:25
问题 I was wondering what is the correct way of implementing the custom Validator in JSF 1.2. In my Validator class' public void validate(FacesContext context, UIComponent component,Object value) throws ValidatorException {} method, I am doing the validation check and just adding the FacesMessage instance to the context by context.addMessage(new FacesMessage(xxx...); in case of invalid condition. This seems to be working fine in my application. However, I am not sure if I also need to explicitely