managed-bean

How to send form input values and invoke a method in JSF bean

跟風遠走 提交于 2019-11-25 22:58:35
问题 I am building a JSF application. I defined the GUI and did the select statements query the database using select. Now I must do the insert statements, but I don\'t know how to read the value of a JSF input component like <h:inputText> and send it to my bean which performs the insert. Should <h:inputText> value be mapped through faces-config.xml , so I can have it in my Java code? 回答1: You need to put all <h:inputXxx> / <h:selectXxx> components in a <h:form> and bind their value attribute to a

Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable

喜你入骨 提交于 2019-11-25 22:11:40
问题 When trying to reference a managed bean in EL like so #{bean.entity.property} , sometimes a javax.el.PropertyNotFoundException: Target Unreachable exception is being thrown, usually when a bean property is to be set, or when a bean action is to be invoked. There seem to be five different kinds of messages: Target Unreachable, identifier \'bean\' resolved to null Target Unreachable, \'entity\' returned null Target Unreachable, \'null\' returned null Target Unreachable, \'\'0\'\' returned null

Get JSF managed bean by name in any Servlet related class

你离开我真会死。 提交于 2019-11-25 22:00:59
问题 I\'m trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I\'m hoping to map: http://host/app/myBean/myProperty to: @ManagedBean(name=\"myBean\") public class MyBean { public String getMyProperty(); } Is it possible to load a bean by name from a regular servlet? Is there a JSF servlet or helper I could use for it? I seem to be spoilt by Spring in which all this is too obvious. 回答1: In a Servlet, you can get request scoped beans by: Bean

ViewParam vs @ManagedProperty(value = “#{param.id}”)

℡╲_俬逩灬. 提交于 2019-11-25 21:53:09
问题 What is the difference between defining View Params like this: <f:metadata> <f:viewParam name=\"id\" value=\"#{someBean.id}\"/> </f:metadata> And defining the property in the ManagedBean like this: @ManagedProperty(value = \"#{param.id}\") private Integer id; 回答1: <f:viewParam>: Sets the value during update model values phase only (since it extends UIInput). The set value is not available during @PostConstruct, so you need an additional <f:event type="preRenderView" listener="#{bean.init}" />

Spring JSF integration: how to inject a Spring component/service in JSF managed bean?

做~自己de王妃 提交于 2019-11-25 21:49:26
问题 I understand that a managed bean works like a controller, because your only task is \"link\" the View Layer with Model. To use a bean as a managed bean I must declare @ManagedBean annotation, doing that I can communicate JSF with bean directly. If I want to inject some component (from Spring) in this managedBean I have two possibles ways: Choose the property in ManagedBean (like \"BasicDAO dao\") and declare @ManagedProperty(#{\"basicDAO\"}) above the property. Doing it, i\'m injecting the

How to choose the right bean scope?

和自甴很熟 提交于 2019-11-25 21:33:21
问题 I noticed that there are different bean scopes like: @RequestScoped @ViewScoped @FlowScoped @SessionScoped @ApplicationScoped What is the purpose of each? How do I choose a proper scope for my bean? 回答1: Introduction It represents the scope (the lifetime) of the bean. This is easier to understand if you are familiar with "under the covers" working of a basic servlet web application: How do servlets work? Instantiation, sessions, shared variables and multithreading. @Request/View/Flow/Session