0

ZK8 form proxy object

asked 2015-10-13 10:45:56 +0800

mikrobe gravatar image mikrobe
100 1 5

Hello, I have to manage generic form with a list of object properties that can be of any datatype (String, int, Date and so on) and with ZK 7 everything works great. Unfortunately when I switched to ZK8 eval, I got errors because one of the datatype I must handle is com.sun.org.apache.xerces.internal.jaxp.datatype.DurationImpl that has no empty constructor. Isn't the new zk form implementation too much restrictive and less flexible about that? Do you have any workaround to suggest to make my code work with ZK8?

Thanks in advance!

delete flag offensive retag edit

6 Answers

Sort by ยป oldest newest most voted
0

answered 2015-10-14 04:06:41 +0800

jumperchen gravatar image jumperchen
3909 2 8
http://jumperchen.blogspo... ZK Team

You can use the annotation of Immutable into that getter method, please refer to this document

link publish delete flag offensive edit
0

answered 2015-10-14 16:01:57 +0800

mikrobe gravatar image mikrobe
100 1 5

updated 2015-10-14 16:14:17 +0800

Thank you jumperchen but I think I cannot do that. My form dialog is built iterating over a List< Property > returned by the ResourceForm class method where Property is the following class

public class Property implements Serializable,Comparable<Property> {

    private String id;
    private String name;
    private String description;
    private String type;
    private String language;
    private Object value;
    ....
    // getters and setters
}

And the value can be of any type (String, int, long, Date, Duration). Furthermore, Property class is contained in an external library that does not import ZK libraries so that I cannot use the Immutable annotation.

link publish delete flag offensive edit

Comments

How about using the annotation ImmutableElements - http://books.zkoss.org/zk-mvvm-book/8.0/syntax/immutableelements.html

jumperchen ( 2015-10-15 03:46:30 +0800 )edit

I'm a little confused @jumperchen. If I use Immutable or ImmutableElements, is it true that there will be no proxy object for those elements ? Hence, there will be no form dirty status and no meaning to use form at all, is it right?

mikrobe ( 2015-10-15 08:17:30 +0800 )edit

Did you ever get an answer about that?

WilliamB ( 2015-11-02 09:09:34 +0800 )edit

@WilliamB: No, I didn't. I don't know whether jumperchen wasn't notified about my comment or he chose not to reply

mikrobe ( 2015-11-02 13:54:21 +0800 )edit

Immutable or ImmutableElements on method is used not to proxy the inner method or inner class of the returned value recursively, not related to itself.

For example,

@Immutable public BigDecimal getPrice() { return price; }

jumperchen ( 2015-11-18 09:38:55 +0800 )edit
0

answered 2015-11-05 10:34:31 +0800

mikrobe gravatar image mikrobe
100 1 5

I really need to sort out this issue because I cannot get through with ZK 8. Besides uncommon datatypes such as Duration (but not for me though), even a BigDecimal has no empty constructor. What is the use of a Form if I cannot even set a proxy object on a BigDecimal property?

Thanks

link publish delete flag offensive edit

Comments

What they need is an exemple page with all the common datetype ... That would help a lot.

WilliamB ( 2015-11-09 08:27:34 +0800 )edit

java.time.Duration is final so this should not cause a problem (i.e. handled like @Immutable automatically), if it does please be more precise which "Duration" class you were using

cor3000 ( 2016-01-05 02:06:22 +0800 )edit
0

answered 2016-01-04 11:32:49 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2016-01-04 11:37:38 +0800

You can define the classes you don't want to proxy using this method:

you can initialize the classes you consider Immutable globally for all forms: ProxyHelper.addIgnoredProxyClass(Class type)

E.g. during an WebappInit listener

That's where you add e.g. BigDecimal, or your Duration class.

Unfortunately Java doesn't provide a better way to determine Immutable classes

link publish delete flag offensive edit
0

answered 2016-12-02 10:35:40 +0800

mikrobe gravatar image mikrobe
100 1 5

Since my domain model consists of hundreds of generated classes, use of ProxyHelper.addIgnoreProxyClass(Class type) is quite cumbersome and I cannot either configure zk.xml. So I found a trick that could, if ZKoss developers like it, be added to the distributed ProxyHelper. I replaced ProxyHelper class with my own one that extends it with a method that allows to specify a Superclass to ignore. The method checkImmutable will additionally compare the parameter type's superclasses against that Superclass. Here it is the change:

public class ProxyHelper {
...    
private static Map<Class<?>, Boolean> _ignoredSuperClasses = new ConcurrentHashMap<Class<?>, Boolean>();
...
    public static void addIgnoredProxySuperClass(Class<?> type) {
        _ignoredSuperClasses.put(type, Boolean.TRUE);
    }
...
    private static boolean checkImmutable(Class<?> type) {
        if (_ignoredClasses.containsKey(type))
            return true;
        if (Modifier.isFinal(type.getModifiers())) {
            _ignoredClasses.put(type, Boolean.TRUE);
            return true;
        }
        Class c = type;
        while (c != null) {
            if(_ignoredSuperClasses.containsKey(c))
                return true;
            c = c.getSuperclass();
        }
        return false;
    }
...
}

Now I can use it in my WepappInit listener adding my domain model's superclass

ProxyHelper.addIgnoredProxySuperClass(AbstractDomainFacade.class);
link publish delete flag offensive edit

Comments

I posted a FR http://tracker.zkoss.org/browse/ZK-3540, feel free to comment in JIRA

cor3000 ( 2016-12-06 09:33:03 +0800 )edit

Thank you cor3000. I will add a comment to the issue with another solution I came up with. My problem is that I have domain model classes that cannot have an empty constructor. Infact they are facades and they are created thru a Factory that injects a delegate entity object.

mikrobe ( 2016-12-06 10:17:59 +0800 )edit

My solution would be to extend ProxyHelper to inject a Factory that takes care of instance creation instead of the default newInstance().

mikrobe ( 2016-12-06 10:21:04 +0800 )edit

if you have any suggestions about the feature please comment directly in JIRA

cor3000 ( 2016-12-06 10:51:42 +0800 )edit
-1

answered 2016-04-04 10:20:31 +0800

WilliamB gravatar image WilliamB
1609 1 6

I'm using @ImmutableFields annotation : http://books.zkoss.org/zk-mvvm-book/8.0/syntax/immutablefields.html

allows me to add the annotation for bean created by submodule (that do not have access to ZK dependency).

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
2 followers

RSS

Stats

Asked: 2015-10-13 10:45:56 +0800

Seen: 142 times

Last updated: Dec 02 '16

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More