managed-bean

Accessing injected dependency in managed bean constructor causes NullPointerException

痴心易碎 提交于 2019-11-26 06:03:31
问题 I\'m trying to inject a DAO as a managed property. public class UserInfoBean { private User user; @ManagedProperty(\"#{userDAO}\") private UserDAO dao; public UserInfoBean() { this.user = dao.getUserByEmail(\"test@gmail.com\"); } // Getters and setters. } The DAO object is injected after the bean is created, but it is null in the constructor and therefore causing NullPointerException . How can I initialize the managed bean using the injected managed property? 回答1: Injection can only take

How to pass JavaScript variables as parameters to JSF action method?

佐手、 提交于 2019-11-26 04:46:03
问题 I\'m preparing some variables in JavaScript (in my specific case, I\'d like to get GPS location): function getVars() { // ... var x = locationInfo.lng; var y = locationInfo.lat; } I\'d like to send them to my managed bean via the below command button: <h:commandButton value=\"submit\" onclick=\"getVars()\" action=\"#{bean.submit(x,y)}\" /> public void submit(int x, int y) { // ... } How can I send x and y variables from JavaScript to JSF managed bean action method? 回答1: Let JS set them as

Calling a JavaScript function from managed bean

馋奶兔 提交于 2019-11-26 02:21:04
问题 Is there a way to call (execute) a JavaScript function from managed bean in JSF? If that\'s relevant, I\'m also using PrimeFaces. 回答1: In PrimeFaces pre 6.2, you can use RequestContext#execute() for this. public void submit() { // ... RequestContext.getCurrentInstance().execute("alert('peek-a-boo');"); } In PrimeFaces 6.2 and up: public void submit() { // ... PrimeFaces.current().executeScript("alert('peek-a-boo');"); } In standard JSF, there is no direct public API for that. Best what you

Why are there different bean management annotations

[亡魂溺海] 提交于 2019-11-26 02:08:19
问题 What is the difference between import javax.annotation.ManagedBean; import javax.enterprise.context.SessionScoped; and import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; ? 回答1: javax.enterprise.context.SessionScoped (JSR 346) and all other annotations under the javax.enterprise.context.* package maintain the context of CDI. CDI provides an alternative, versatile and more powerful mechanism for dependency injection, bean and general resource management within the Java

How to invalidate session in JSF 2.0?

安稳与你 提交于 2019-11-26 01:06:56
问题 What is the best possible way to invalidate session within a JSF 2.0 application? I know JSF itself does not handle session. So far I could find private void reset() { HttpSession session = (HttpSession) FacesContext.getCurrentInstance() .getExternalContext().getSession(false); session.invalidate(); } Is this method correct? Is there a way without touching the ServletAPI? Consider a scenario wherein a @SessionScoped UserBean handles the login-logout of a user. I have this method in the same

BeanFactory vs ApplicationContext

泄露秘密 提交于 2019-11-26 01:04:02
问题 I\'m pretty new to the Spring Framework, I\'ve been playing around with it and putting a few samples apps together for the purposes of evaluating Spring MVC for use in an upcoming company project. So far I really like what I see in Spring MVC, seems very easy to use and encourages you to write classes that are very unit test-friendly. Just as an exercise, I\'m writing a main method for one of my sample/test projects. One thing I\'m unclear about is the exact differences between BeanFactory

How to invalidate session in JSF 2.0?

那年仲夏 提交于 2019-11-26 00:58:50
What is the best possible way to invalidate session within a JSF 2.0 application? I know JSF itself does not handle session. So far I could find private void reset() { HttpSession session = (HttpSession) FacesContext.getCurrentInstance() .getExternalContext().getSession(false); session.invalidate(); } Is this method correct? Is there a way without touching the ServletAPI? Consider a scenario wherein a @SessionScoped UserBean handles the login-logout of a user. I have this method in the same bean. Now when I call the reset() method after I'm done with necessary DB updates, what will happen to

How do I process GET query string URL parameters in backing bean on page load?

寵の児 提交于 2019-11-25 23:41:07
问题 I\'ve read how to send parameters using JSF but what if the user types their companyId in the URL when accessing their login page? For example, http://my.company.url/productName/login.faces?companyId=acme. The way we do it now, there is a bit of scriptlet code that grabs the value from the request and then set it in the session. That parameter changes their look and feel starting from the login page forward so each customer could have a different login page view. We are using extjs until I

Invoke JSF managed bean action on page load

 ̄綄美尐妖づ 提交于 2019-11-25 23:34:58
问题 Is there a way to execute a JSF managed bean action when a page is loaded? If that\'s relevant, I\'m currently using JSF 1.2. 回答1: JSF 1.0 / 1.1 Just put the desired logic in the constructor of the request scoped bean associated with the JSF page. public Bean() { // Do your stuff here. } JSF 1.2 / 2.x Use @PostConstruct annotated method on a request or view scoped bean. It will be executed after construction and initialization/setting of all managed properties and injected dependencies.

BeanFactory vs ApplicationContext

烈酒焚心 提交于 2019-11-25 23:12:08
I'm pretty new to the Spring Framework, I've been playing around with it and putting a few samples apps together for the purposes of evaluating Spring MVC for use in an upcoming company project. So far I really like what I see in Spring MVC, seems very easy to use and encourages you to write classes that are very unit test-friendly. Just as an exercise, I'm writing a main method for one of my sample/test projects. One thing I'm unclear about is the exact differences between BeanFactory and ApplicationContext - which is appropriate to use in which conditions? I understand that