Thursday, October 8, 2015

ZK: multi-select listboxes with dynamic right click menu

http://learntechnology.net/2015/10/07/listbox-rightclick.html

ZK: setting menuitem style programmtically

ZK's menuitem inherits setStyle but I couldn't get it work eg...
Menuitem menuItem = new Menuitem("Foo"));
menuItem.setStyle("font-weight:bold");

However, on the forums someone pointed out setting sclass works and then defining that class style in your zul.

eg..
Menuitem menuItem = new Menuitem("Foo"));
menuItem.setSclass("itembold");

in your zul:

<style>
.itembold .z-menuitem-text {font-weight: bold}
</style>

Wednesday, June 10, 2015

https://github.com/rickcr/mybatis-generic-crud

Many times your application consists of doing common CRUD type operations (Create, Read, Update, Delete.)

I'm a big fan of MyBatis and a few solutions have been proposed to handle some of the basic CRUD in a generic fashion. This is just one 'partially generic' way to handle these common things. I say 'partially' since I've seen other approaches, such as having a single mapper and you pass in the table name and a list of columns etc. That approach is decent as well, but I've found that many times you start out generic but you'll often have to tweak a few things such that your CRUD becomes a bit more complicated. Following the approach below you have the flexibility to override whatever you want. The drawback (minor) is that, yes, you still need to create a place-holder mapper interface and you still need to create your mapper xml file and the corresponding CRUD sql in it.

The benefit is that if you follow the convention of naming the mapper methods to match the GenericCrudMapper, you typically are only writing the SQL, and the Java side becomes simple.

Note, I also created a GenericCrudService class. If you follow any of my other tutorials you'll realize that I do prefer to have my Mappers used within a service class. This is just my preference and not required. I've found in the 'real world' that I often need to do more stuff around my basic CRUD operations so that using the Mapper within a Service class gives me an extra layer to shield the client - typically the UI - from having to handle the other needed business logic around the CRUD operations.

Friday, April 10, 2015

MyBatis-Spring-ZK Maven Multimodule Project

I know have a sample project that uses MyBatis, Spring, and ZK, broken out into separate Maven modules. It's a more realistic setup for how you'd typically organize your 'real life' projects, especially in a corporate environment.   Domain module (pojos), Services module (MyBatis), Web project (ZK)

Monday, February 23, 2015

MyBatis CDI Zk Sample App (BETA)

Had the worst time trying to figure out how to get this set up working. (The Spring Mybatis setup was much easier.) The examples out there are few and far between and absolutely nothing using the above combination.

https://github.com/rickcr/mybatis-cdi-zk

I'm calling it a BETA though because I have a few questions as you can see in the README Reposting here, in case anyone can help

1) You're supposed to be able to add a weld:scan section in beans.xml but when I do, I get start up errors? It works without it, but I'd like it to only scan what it needs so I'd prefer to add the weld:scan section if I could.

2) I don't understand why/how to upgrade to weld-servlet 2.9? (see note in my pom.xml) I posted about it here posted about it here on stackoverflow

3) Why do some examples also have a beans.xml in resources/META-INF/ along with WEB-INF/ ?

4) Can not get an Integration test (DepartmentIntegrationIT) working with Arquillian. Any help much appreciated. Posted for some help here https://developer.jboss.org/message/919605

Tuesday, February 17, 2015

Ran into an interesting JAXB issue. We have several classes that all extends a Base class. At one point I introduced an object property into the base class, that also happened to be a property defined in just ONE of the subclasses. This caused any setter of this property from ANY subclasses (outside the one with that property overridden) to have this property completely ignored in the XML output. Example
@XmlRootElement(name = "animal")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlSeeAlso({Dog.class, Fish.class})
public class Animal {
    protected String movement;
     ....
}

@XmlRootElement(name = "dog")
@XmlSeeAlso({Animal.class})
@XmlAccessorType(XmlAccessType.FIELD)
public class Dog extends Animal {
   private String breed;
   protected String movement;
   ....
}

@XmlRootElement(name = "fish")
@XmlSeeAlso({Animal.class})
@XmlAccessorType(XmlAccessType.FIELD)
public class Fish extends Animal {
    private String scaleType;
    ....
}

public static void main(String[] args) {
    Dog dog = new Dog();
    dog.setBreed("lab");
    dog.setMovement("walks"); 
    String xml = AnimalJaxb.toXml(dog);
    System.out.println("dog = "+xml);

    Fish fish = new Fish();
    fish.setMovement("swims"); //WILL NOT SHOW UP IN XML!
    fish.setScaleType("normal"); 
    String xml = AnimalJaxb.toXml(fish);
    System.out.println("fish = "+xml); 
When the above runs. The "movement" property on Fish will NOT be in the XML. To fix this, I needed to remove the overridden movement property in the Dog class. What's frustrating is JAXB doesn't throw any errors or complain. The only way it will complain is if I make the base class (Animal) abstract and mark it @XmlTransient, afterwhich JAXB will complain about having "two properties with the same name."

Blogger Syntax Highliter