Custom Component - Auto Submit on Change

Hello,

I am working on a custom component for Sun Java Studio Creator. I have the component mostly working and ready, except now I need an "Auto Submit on Change" functionality in my component.

I want to be able to right-click on the component and select "Auto Submit on Change" from the pop-up menu. What is required for me to do this?

Is there some special parameter I need to add in the XML files somewhere? Something in the BeanInfo class?

Any help would be greatly appreciated.

Many Thanks,

Kevin

[547 byte] By [kewiga] at [2007-11-26 15:30:41]
# 1

> Hello,

>

> I am working on a custom component for Sun Java

> Studio Creator. I have the component mostly working

> and ready, except now I need an "Auto Submit on

> Change" functionality in my component.

>

> I want to be able to right-click on the component and

> select "Auto Submit on Change" from the pop-up menu.

> What is required for me to do this?

>

> Is there some special parameter I need to add in the

> XML files somewhere? Something in the BeanInfo class?

>

There is a Creator/VWP design-time API that you can do this with. This is in addition to a property in the property sheet.

-Edwin

http://blogs.sun.com/edwingo/

edwingoa at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...
# 2

Hello Edwin,

Do you mean there has to be a property value in the getPropertyDescriptors() method in the BeanInfoBase class?

Could you please be a little more specific? What property in the property sheet do I have to add? Could you post some code? I would really appreciate it.

Thank you,

Kevin

kewiga at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...
# 3

> Hello Edwin,

>

> Do you mean there has to be a property value in the

> getPropertyDescriptors() method in the BeanInfoBase

> class?

>

> Could you please be a little more specific? What

> property in the property sheet do I have to add?

> Could you post some code? I would really appreciate

> it.

I wasn't specific because I had a meeting to go to. It's also not currently well documented. You can find a link to info here: http://wiki.java.net/bin/view/Javatools/CreatorDesignTimeApi. I believe there are parts of the API that allow one to add context menu items into the IDE. The latest codebase is NetBeans VWP 5.5 with Sun AppServer 9 UR1. The design-time API works in that tool as well. See some of my recent blog entries for more info on installation.

-Edwin

http://blogs.sun.com/edwingo/

edwingoa at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...
# 4

Hello Edwin,

I'm going to try to see if I can use getContextItems(DesignBean designBean) in the DesignInfo interface when I get back to work on Monday. Am I getting warmer?

I'll assign duke points if it works. If you could give us some code that would be nice too. Thanks for the link and for the hints pointing the way...

Regards,

Kevin

kewiga at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...
# 5

> Hello Edwin,

>

> I'm going to try to see if I can use

> getContextItems(DesignBean designBean) in the

> DesignInfo interface when I get back to work on

> Monday. Am I getting warmer?

Yes, I believe you need to implement com.sun.rave.designtime.DesignInfo.getContextItems(DesignBean). A DesignInfo is similar to a standard BeanInfo, but it provides for dynamic design-time behavior of a JavaBean.

>

> I'll assign duke points if it works. If you could

> give us some code that would be nice too. Thanks for

> the link and for the hints pointing the way...

As I understand it, eventually this code will be open sourced.

/*

* {START_JAVA_COPYRIGHT_NOTICE

* Copyright 2006 Sun Microsystems, Inc. All rights reserved.

* Use is subject to license terms.

* END_COPYRIGHT_NOTICE}

*/

/**

*

Return <code>null</code>, indicating that no context menu items

* will be provided.

*

* @param bean The DesignBean that a user has right-clicked on

*/

public DisplayAction[] getContextItems(DesignBean bean) {

DesignProperty property = getDefaultBindingProperty(bean);

if (property == null) {

return new DisplayAction[0];

}

ArrayList displayActions = new ArrayList();

if (EditableValueHolder.class.isAssignableFrom(beanClass))

displayActions.add(new AutoSubmitOnChangeAction(bean));

Class beanClass = bean.getInstance().getClass();

Class bindingPanelClass = null;

if (Selector.class.isAssignableFrom(beanClass)) {

if (RbCbSelector.class.isAssignableFrom(beanClass))

bindingPanelClass = DataBindingHelper.BIND_VALUE_TO_DATAPROVIDER;

else

bindingPanelClass = DataBindingHelper.BIND_OPTIONS_TO_DATAPROVIDER;

} else {

bindingPanelClass = DataBindingHelper.BIND_VALUE_TO_DATAPROVIDER;

}

displayActions.add(

DataBindingHelper.getDataBindingAction(bean,

property.getPropertyDescriptor().getName(),

new Class[] {bindingPanelClass, DataBindingHelper.BIND_VALUE_TO_OBJECT}));

if (Selector.class.isAssignableFrom(beanClass)) {

DesignProperty itemsProperty = bean.getProperty("items");

if (itemsProperty instanceof FacesDesignProperty && ((FacesDesignProperty) itemsProperty).isBound()) {

String expression = ((FacesDesignProperty) itemsProperty).getValueBinding().getExpressionString();

ResolveResult resolveResult =

((FacesDesignContext)bean.getDesignContext()).resolveBindingExprToBean(expression);

if (resolveResult != null && resolveResult.getDesignBean() != null &&

resolveResult.getDesignBean().getInstance() instanceof DefaultOptionsList)

displayActions.add(new OptionsListCustomizerAction(bean));

}

}

return (DisplayAction[]) displayActions.toArray(new DisplayAction[displayActions.size()]);

}

-Edwin

blogs.sun.com/edwingo/

edwingoa at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...
# 6

This is for future reference -- in case anyone is looking on how to implement an "Auto-Submit on Change" functionality to their custom components. Please correct me if there are any mistakes.

The first thing you will need is an onChange property in your component. Just add this to the XML:

<property>

<description>

Scripting code executed when the element

value of this component is changed.

</description>

<property-name>onChange</property-name>

<property-class>java.lang.String</property-class>

<property-extension>

<category>JAVASCRIPT</category>

<is-bindable>true</is-bindable>

</property-extension>

</property>

Then add the following code below to your DesignBean or any superclass that your DesignBean might extend from. This will tell Studio Creator to add an AutoSubmitOnChangeAction to your component if your component is an EditableValueHolder -- which it should be if it is a text field or a drop down. The AutoSubmitOnChangeAction action simply sets Javascript code directly into the onChange property of your component. This Javascript code will submit the form when your component is changed.

public DisplayAction[] getContextItems( DesignBean bean ) {

Class beanClass = bean.getInstance().getClass();

ArrayList displayActions = new ArrayList();

if((javax.faces.component.EditableValueHolder.class).isAssignableFrom(this.beanClass)) {

displayActions.add(new AutoSubmitOnChangeAction(bean));

}

return (DisplayAction[])displayActions.toArray(new DisplayAction[displayActions.size()]);

}

Then, make sure that the onchange property is rendered by your renderer.

// Render on change javascript.

if( onChange != null ) {

aWriter.writeAttribute("onchange", onChange, "onchange");

}

Finally, you need to make sure that the following jar files are in your class-path. These jar files are located in rave2.0/modules directory in Studio Creator:

webui-dt.jar, com-sun-rave-designtime.jar

I hope this helps.

Regards,

Kevin

kewiga at 2007-7-8 21:47:24 > top of Java-index,Development Tools,Java Tools...