javabeans

Injecting Beans in JSF 2.0

馋奶兔 提交于 2019-11-29 02:33:46
I have a Session scoped bean import javax.faces.bean.SessionScoped; import javax.inject.Named; @Named @SessionScoped public class SessionBean implements Serializable{ I inyect the object in one Filter... public class FiltroSeguridad implements Filter{ @Inject private SessionBean sessionBean; @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest httpRequest = (HttpServletRequest) request; sessionBean.setRutaRedirect(httpRequest.getRequestURI()); } } But, I inyect SessionBean in the next

BeanUtils converting java.util.Map to nested bean

被刻印的时光 ゝ 提交于 2019-11-29 02:24:25
I have a Java bean which has a field which in turn is another bean public class BeanOne { private String fieldOne; private BeanTwo fieldTwo; public String getFieldOne() {return this.fieldOne;} public void setFieldOne(String fieldOne){this.fieldOne = fieldOne} public BeanTwo getFieldTwo() {return this.fieldTwo;} public void setFieldTwo(BeanTwo fieldTwo){this.fieldTwo = fieldTwo} } public class BeanTwo { private String fieldOne; public String getFieldOne() {return this.fieldOne;} public void setFieldOne(String fieldOne){this.fieldOne = fieldOne} } I am trying to pass a map to BeanUtils to try

Why Java Beans have to be serializable?

我们两清 提交于 2019-11-29 01:35:19
Is it necessary that a Java Bean implements the Serializable interface? It's one of the "typical" features as described in the Javabeans specification . Here's an extract of chapter 2.1 What is a bean? Individual Java Beans will vary in the functionality they support, but the typical unifying features that distinguish a Java Bean are: Support for “introspection” so that a builder tool can analyze how a bean works Support for “customization” so that when using an application builder a user can customize the appearance and behaviour of a bean. Support for “events” as a simple communication

boolean properties starting with “is” does not work

笑着哭i 提交于 2019-11-28 23:53:15
I have a project that use JSF 2.1 and PrimeFaces. I tried to use a simple <h:outputText> referencing #{myBean.matriz} and I got this error: SEVERE: javax.el.PropertyNotFoundException: ... value="#{myBean.matriz}": Missing Resource in EL implementation: ???propertyNotReadable??? The getter is: isMatriz() . Should it be getMatriz() ? BalusC The is prefix works only for boolean , not Boolean . You've there apparently actually a Boolean property. You've 2 options to fix it: Rename the getter with get prefix. Replace Boolean by boolean . Note that it will default to false instead of null . See also

List<Map<String,Object>> to org.json.JSONObject?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 23:31:39
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>(); Map<String, Object> map = new HashMap<String, Object>(); map.put("abc", "123456"); map.put("def", "hmm"); list.add(map); JSONObject json = new JSONObject(list); try { System.err.println(json.toString(2)); } catch (JSONException e) { e.printStackTrace(); } What's wrong with this code? The output is: {"empty": false} public String listmap_to_json_string(List<Map<String, Object>> list) { JSONArray json_arr=new JSONArray(); for (Map<String, Object> map : list) { JSONObject json_obj=new JSONObject(); for (Map.Entry<String,

Java 8 interface default method doesn't seem to declare property

匆匆过客 提交于 2019-11-28 21:36:45
In my application I run into a problem that when a getter in a class is defaulted in an interface only (Java 8 feature), there is no Java Beans property as a result. I.e. for normal method invocation it works just as a standard method, but for access through "properties" it suddenly behaves differently... Here is a test case: import java.beans.Introspector; import java.util.Arrays; import java.util.stream.Collectors; import org.apache.commons.beanutils.PropertyUtils; public class test { public static void main (String[] arguments) throws Exception { // Normal language-level invocation, works

Common algorithm for generating a diff of the fields in two beans?

£可爱£侵袭症+ 提交于 2019-11-28 20:52:10
Let's say you have two instances of the same bean type, and you'd like to display a summary of what has changed between the two instances - for example, you have a bean representing a user's settings in your application, and you'd like to be able to display a list of what has changed in the new settings the user is submitting (instance #1) versus what is stored already for the user (instance #2). Is there a commonly used algorithm or design pattern for a task such as this, perhaps something that can be abstracted and re-used for different types of beans? (I'm having a hard time thinking of a

Defining the same Spring bean twice with same name

假装没事ソ 提交于 2019-11-28 20:30:21
Is having two definition for a bean (with same name and class) valid in Spring IOC ? I am having two bean definition files included in web.xml. See the sample below. applicationContext-beans1.xml <bean name="myWao" class="com.beans.myBean"> </bean> applicationContext-beans2.xml <bean name="myWao" class="com.beans.myBean"> </bean> I am not facing any issue till now. But, will this possibly impact in the real environment which will be multi threaded and clustered ? Note: Both the XMLs are loaded as I am able to use the other beans defined(only once) in both the XMLs Brian Agnew It's valid, but

What is the advantage of using Java Beans?

廉价感情. 提交于 2019-11-28 20:04:25
问题 I believe I understand what Java Beans are: Java class(es) which contain a no-arg constructor, are serializable, and expose their fields with getters and setters. Does a Java Bean have to expose all of its fields in order to qualify as a bean? If no, does it even have to expose any ? May Java Beans include constructors with arguments as well as a no-arg constructor? What is the purpose of Java Beans, other than to conform to a certain coding style? It seems there is a lot of talk about 'beans

Spring - set a property only if the value is not null

柔情痞子 提交于 2019-11-28 19:17:14
When using Spring, is it possible to set a property only if the value passed is not null? Example: <bean name="myBean" class="some.Type"> <property name="abc" value="${some.param}"/> </bean> The behavior I'm looking for is: some.Type myBean = new some.Type(); if (${some.param} != null) myBean.setAbc(${some.param}); The reason I need this is since abc has a default value which I don't want to override with a null . And the Bean I am creating is not under my source control - so I cannot change its behavior. (Also, abc for this purpose might be a primitive, so I can't set it with a null anyway.