managed-bean

JSF 1.2: How to keep request scoped managed bean alive across postbacks on same view?

…衆ロ難τιáo~ 提交于 2019-11-26 11:22:06
问题 Is it possible to keep a request scoped bean alive across postbacks on the same page? The general problem is, as the bean gets trashed on end of request and recreated on every form submit, for example the booleans behind dynamically manipulated disabled , readonly and rendered get reset to their default values and cause the forms to not work as intented anymore. 回答1: I'll assume that the session scope is not an option, otherwise this question makes little sense. You can do it using Tomahawk

Calling a JavaScript function from managed bean

做~自己de王妃 提交于 2019-11-26 11:21:49
Is there a way to call (execute) a JavaScript function from managed bean in JSF? If that's relevant, I'm also using PrimeFaces. BalusC 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 can get is to set the desired script as a bean property and conditionally render a <h:outputScript>

How to set -Dorg.apache.el.parser.COERCE_TO_ZERO=false programmatically

ⅰ亾dé卋堺 提交于 2019-11-26 10:35:48
问题 This question is similar to: jsf: integer property binded to a inputtext in UI is set to zero on submit but I am not completely satisfied with the solution. The contexts is the same: I have a web form requiring an Integer value. If the textbox is left empty, I want my Integer field to be \'null\' but instead the EL Parser automatically sets my id field to \'0\'. I can fix the problem by setting a JVM Parameter in my local Tomcat VM: -Dorg.apache.el.parser.COERCE_TO_ZERO=false However, this

Why are there different bean management annotations

岁酱吖の 提交于 2019-11-26 10:23:15
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; ? 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 EE space. It's an alternative to JSF managed beans and it's set to even supersede the JSF bean management

Field.get(obj) returns all nulls on injected CDI managed beans, while manually invoking getters return correct values

青春壹個敷衍的年華 提交于 2019-11-26 10:03:43
问题 I am trying to access the values of some fields from the backing bean of a JSF page via reflection. The problem is that when I use the getter I get the correct value but when I use the get(obj) method of the necessary fields I always get a null value returned. Getting the beanObject: ELContext elcontext = FacesContext.getCurrentInstance().getELContext(); Object beanObject = FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elcontext, null, beanName); To get the

NullPointerException while trying to access @Inject bean in constructor

狂风中的少年 提交于 2019-11-26 09:43:57
问题 I\'ve a session scoped bean: @Named @SessionScoped public class SessionBean implements Serializable { private String someProperty; public String getSomeProperty() { return someProperty; } } I\'d like to inject this in a request scoped bean and initialize with it: @Named @RequestScoped public class RequestBean { @Inject private SessionBean sessionBean; public RequestBean() { System.out.println(sessionBean.getProperty()); } } However, it throws the following exception: java.lang

How do I force an application-scoped bean to instantiate at application startup?

北城余情 提交于 2019-11-26 09:18:04
问题 I can\'t seem to find a way to force an application-scoped managed bean to be instantiated/initialized when the web app is started. It seems that application-scoped beans get lazy-instantiated the first time the bean is accessed, not when the web app is started up. For my web app this happens when the first user opens a page in the web app for the first time. The reason I want to avoid this is because a number of time-consuming database operations happen during the initialization of my

Read resource bundle properties in a managed bean

ⅰ亾dé卋堺 提交于 2019-11-26 08:19:26
问题 Using <resource-bundle> files I\'m able to have i18n text in my JSF pages. But is it possible to access these same properties in my managed bean so I can set faces messages with i18n values? 回答1: Assuming that you've configured it as follows: <resource-bundle> <base-name>com.example.i18n.text</base-name> <var>text</var> </resource-bundle> If your bean is request scoped, you can just inject the <resource-bundle> as @ManagedProperty by its <var> : @ManagedProperty("#{text}") private

ManagedProperty in CDI @Named bean returns null

爱⌒轻易说出口 提交于 2019-11-26 07:32:46
问题 I\'m trying to deal with @ManagedProperty but without success ! I\'ve been following this guide, and it not seems that hard. But my code simply won\'t work! Here\'s a little snippet @ManagedBean @SessionScoped public class LoginBean { @EJB private LoginUserLocal loginUser; private boolean loggedIn = false; private User user; private StreamedContent image; . . . //-- @Named(value = \"messagesBean\") @RequestScoped public class MessagesBean { @ManagedProperty(value = \"#{loginBean}\") private

JSF managed-bean EJB injection

百般思念 提交于 2019-11-26 07:22:27
问题 I have an EJB (PersonManager) in the Enterprise Application modul, which injects another EJB (Person): @Stateful public class PersonManager implements PersonManagerLocal { @EJB private PersonLocal person; @Override public void setPersonName(String name) { person.setName(name); } @Override public String getPersonName() { return person.getName(); } } I want to use the PersonManager EJB in a JSF web app. I define it in the faces-config.xml: <managed-bean> <managed-bean-name>personManager<