javabeans

Valid JavaBeans names for boolean getter methods

[亡魂溺海] 提交于 2019-12-17 15:32:17
问题 I know most variable names will work with "is", such as isBlue() , but is "has" also a valid prefix, like hasProperty() ? 回答1: According to the JavaBeans specification section 8.3.2: Boolean properties In addition, for boolean properties, we allow a getter method to match the pattern: public boolean is<PropertyName>(); This " isPropertyName " method may be provided instead of a " get<PropertyName> " method, or it may be provided in addition to a " get<PropertyName> " method. In either case,

@PreDestroy never called on @ViewScoped

只愿长相守 提交于 2019-12-17 10:50:11
问题 I have a @ViewScoped bean that has a method with an @PreDestroy annotation that should make sure some remote connections are closed. However, the method is not called when the user navigates away. Is there anything one can do wrong? Do I have to register anything anywhere in order to make it work? It's a simple public method ( void ) that throws no exception. I'm using JSF 2 (MyFaces) with Tomcat 7.0.12. Could it be a problem with Tomcat? UPDATE The @PostConstruct annotation works fine. 回答1:

Why doesn't JavaBeans serialize a property from type List<?>?

痴心易碎 提交于 2019-12-14 02:23:43
问题 I'm trying to do some simple XML serialization with JavaBeans, with an object having five getter/setter properties, and two getters. These two are from type List<...> : public List<MasterDataQueryMDType> getType() { if (type == null) { type = new ArrayList<MasterDataQueryMDType>(); } return this.type; } and public List<MasterDataQueryKey> getKey() { if (key == null) { key = new ArrayList<MasterDataQueryKey>(); } return this.key; } I'm then using the XMLEncoder class (although here JAXB may be

How to use XMLEncoder and XMLDecoder with String?

与世无争的帅哥 提交于 2019-12-13 18:42:31
问题 Sorry this is a very new to Java question! How does one input a String to XMLEncoder and one output a String from XMLDecoder? The String contains information about a JavaBeans object. 回答1: Here is a more direct example using ByteArrayInput/OutputStream than the other question: for class static public class MyClass implements Serializable { private String prop; /** * Get the value of prop * * @return the value of prop */ public String getProp() { return prop; } /** * Set the value of prop * *

Is it possible to access string-indexed getter with Spring XML?

喜夏-厌秋 提交于 2019-12-13 16:01:48
问题 Is there a notion of "string-indexed" getters in spring context setup XML language? Suppose I have Person getter with the following prototype: class Person { Person getRelative(String relativeName); ... } Can I access it with something like <bean id="Bob" class="Person"/> <bean id="Barnyard" class="Company"> <property name="owner" ref="Bob.relative.father"/> </bean> saying that Bob's father is the owner of Barnyard company. The Company prototype is like follows: class Company { Person

What is a good use case of Java Beans?

纵然是瞬间 提交于 2019-12-13 14:46:47
问题 I just saw the Java Beans specification. I felt that using only getters, setters and empty constructor will make code more hectic plus developer needs to manage track to set all the required instances properly. Could somebody point me a good use case for using such design? I am unable to get a feel of it. There is one use I can think of - "When you need to create an Instance of a class such that its data members will be decided later in the code." EDIT: Guys I am not initiating a discussion.

Get NullPointerException in java EE application on Intellij Idea IDE

风格不统一 提交于 2019-12-13 11:23:52
问题 I'm trying to run this simple and small application but I don't understand which is the problem and consequently how to fix it. Here it is the code. It is very simple. One bean invoked by a client application in order to print out in the client terminal the well-known message Hello World. I have created the application by using Intellij Idea 13.0.3 IDE with Server GlassFish 4.0.0, Java JDK 8.0 and Java EE 7. EDIT I think I got those errors because I didn't deployed correctly my application. I

Spring autowire null pointer exception [duplicate]

丶灬走出姿态 提交于 2019-12-13 10:01:26
问题 This question already has answers here : Why is my Spring @Autowired field null? (16 answers) Closed 2 years ago . xml configuration - <bean id="DS" class="org.springframework.jdbc.datasource.DriverManagerDataSource" > <property name="driverClassName" value="${DB.DRIVERCLASS}" /> <property name="url" value="${TABLEMAINT.URL}" /> <property name="username" value="${TABLEMAINT.USER}" /> <property name="password" value="${TABLEMAINT.PASSWORD}" /> </bean> @Component class AbcDAO{ @Autowired

Is it possible to extend a pojo class in Spring?

白昼怎懂夜的黑 提交于 2019-12-13 07:06:34
问题 I have a pojo which contains a set of private variables and their setters and getters. This pojo is used extensively across my application. Now, I have to support a scenario where there are multiple pojos and each pojo is a superset of the initial pojo I have. Is it possible that I can extend my original pojo so that I need not change my existing business logic. I am new to spring and I dont know if this is possible. Pojo B should contain everything in pojo A and few more things. Inside the

Spring Multiple PropertyPlaceholderConfigurer files and database

北城余情 提交于 2019-12-13 05:24:34
问题 I want to load the properties from my java application used the Spring Beans, through the database, however I need to load the properties of the connection to the database from a file. So what I want is the following: Load the file db.Properties Initialize the beans of DataSources Load the remaining properties Base At the end, have access to the loaded properties from both sources. I tried the following way. application-context.xml: <beans xmlns="http://www.springframework.org/schema/beans"