Json Java serialization that works with GWT [closed]

Take a look at GWT’s Overlay Types. I think this is by far the easiest way to work with JSON in GWT. Here’s a modified code example from the linked article: public class Customer extends JavaScriptObject { public final native String getFirstName() /*-{ return this.first_name; }-*/; public final native void setFirstName(String value) /*-{ this.first_name = … Read more

Valid JavaBeans names for boolean getter methods

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, if the is<PropertyName> method … Read more

Spring – using static final fields (constants) for bean initialization

Something like this (Spring 2.5) <bean id=”foo” class=”Bar”> <property name=”myValue”> <util:constant static-field=”java.lang.Integer.MAX_VALUE”/> </property> </bean> Where util namespace is from xmlns:util=”http://www.springframework.org/schema/util” But for Spring 3, it would be cleaner to use the @Value annotation and the expression language. Which looks like this: public class Bar { @Value(“T(java.lang.Integer).MAX_VALUE”) private Integer myValue; }

Programmatically configure LogBack appender

Here a simple example that works for me (note that I use the FileAppender in this example) import org.slf4j.LoggerFactory; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.encoder.PatternLayoutEncoder; import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.FileAppender; public class Loggerutils { public static void main(String[] args) { Logger foo = createLoggerFor(“foo”, “foo.log”); Logger bar = createLoggerFor(“bar”, “bar.log”); foo.info(“test”); bar.info(“bar”); } private … Read more

Spring cannot find bean xml configuration file when it does exist

Thanks, but that was not the solution. I found it out why it wasn’t working for me. Since I’d done a declaration: ApplicationContext context = new ClassPathXmlApplicationContext(“beans.xml”); I thought I would refer to root directory of the project when beans.xml file was there. Then I put the configuration file to src/main/resources and changed initialization to: … Read more

How to convert a Java object (bean) to key-value pairs (and vice versa)?

Lots of potential solutions, but let’s add just one more. Use Jackson (JSON processing lib) to do “json-less” conversion, like: ObjectMapper m = new ObjectMapper(); Map<String,Object> props = m.convertValue(myBean, Map.class); MyBean anotherBean = m.convertValue(props, MyBean.class); (this blog entry has some more examples) You can basically convert any compatible types: compatible meaning that if you did … Read more

Can I update a JSF component from a JSF backing bean method?

Using standard JSF API, add the client ID to PartialViewContext#getRenderIds(). FacesContext.getCurrentInstance().getPartialViewContext().getRenderIds().add(“foo:bar”); Using PrimeFaces specific API, use PrimeFaces.Ajax#update(). PrimeFaces.current().ajax().update(“foo:bar”); Or if you’re not on PrimeFaces 6.2+ yet, use RequestContext#update(). RequestContext.getCurrentInstance().update(“foo:bar”); If you happen to use JSF utility library OmniFaces, use Ajax#update(). Ajax.update(“foo:bar”); Regardless of the way, note that those client IDs should represent absolute client IDs … Read more

What is java pojo class, java bean, normal class? [duplicate]

Normal Class: A Java class Java Beans: All properties private (use getters/setters) A public no-argument constructor Implements Serializable. Pojo: Plain Old Java Object is a Java object not bound by any restriction other than those forced by the Java Language Specification. I.e., a POJO should not have to Extend prespecified classes Implement prespecified interface Contain … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)