Re: Re: Action listener issue

Frank Meissner <[email protected]>
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Hello Tristan,

I see nothing wrong in your code.

I looked into the code of the Parser of swixml and found nothing wrong 
there either. The field (in your case: cancelAction) is fetched through 
reflection by using the getField(String) method (coming from 
java.lang.Class). The docu says there:
    1. If C declares a public field with the name specified, that is
       the field to be reflected.
    2. If no field was found in step 1 above, this algorithm is applied
       recursively to each direct superinterface of C. The direct
       superinterfaces are searched in the order they were declared.
    3. If no field was found in steps 1 and 2 above, and C has a
       superclass S, then this algorithm is invoked recursively upon S.
       If C has no superclass, then a NoSuchFieldException is thrown.
So, to declare your cancelAction in the super class is absolutly fine.
You may slightly modify the SwingEngine-Class to assign true to its 
DEBUG_MODE. You may see an exception coming then.

The reasons I suspect are:
- using the wrong class-file altogether (e.g. your compilation outside 
eclipse does not work very well -- try erasing *all* class files before 
compiling your project outside eclipse. You may as well output something 
to System.err to ensure the use of the correct code)
- a security manager interfering

If there are no great secrets about your classes, I appreciate getting 
the complete code of it (xml, java-files).

Yours,

Frank

Tristan Richard wrote:
> Here is the class that call the render method :
> 
> /**
>  * JPEG option dialog
>  *
>  * @author Tristan RICHARD
>  */
> public class JpegOptions extends SwiXMLDialog {
> 
>     /**
>      * Validates user settings. Has to be <code>public</code> because of 
> SwiXML use
>      */
>     public JButton okButton;
> 
>     /**
>      * Build Swing dialog with XUL
>      */
>     public JpegOptions() {
>         try {
>             swix = new SwingEngine(this);
> swix.render("com/soft/iseult/iseult/gui/dialogs/JpegOptions.xml");
>             dialog = (JDialog) swix.getRootComponent();
>             initUI(); //Method to add more complex UI elements to the 
> already created XUL one
>             dialog.pack();
>         } catch (Exception e) {
>             e.printStackTrace();
>         }
>     }
> 
> The okButton works very well, and in initUI(), you have a classic Action 
> Listener :
>         okButton.addActionListener(new ActionListener() {
>             public void actionPerformed(ActionEvent e) {
>                 exit();
>             }
>         });
> 
> But for the cancel action, everything is defined in SwiXMLDialog 
> abstract class. It is public, so there shall not be any trouble using it 
> from XUL.
> 
> ABout the jre, I have the same issue on Windows and Linux, and also with 
> j2re 1.4.2_03, so I guess it comes not from there. But I don't 
> understand why it works from Eclipse and not outside of it ?
> 
> Regards,
> Tristan
> 
> Frank Meissner a écrit :
> 
>> Tristan Richard wrote:
>>
>>> Hi,
>>>
>>> I have created an abstract dialog class for dialogs based on Swixml, 
>>> with a public cancelAction. (see below)
>>>
>>> So that I can call it from my XUL code like that :
>>> <button text="dialog.cancel" action="cancelAction"/>
>>>
>>> /**
>>>  * This class merely defines what we need to create
>>>  * a dialog box with SwiXML
>>>  *
>>>  * @author Tristan RICHARD
>>>  */
>>> public abstract class SwiXMLDialog {
>>>
>>>     /**
>>>      * Rendering engine from XUL to Swing
>>>      */
>>>     SwingEngine swix;
>>>
>>>     public Action cancelAction = new AbstractAction() {
>>>         public void actionPerformed(ActionEvent e) {
>>>             dialog.dispose();
>>>         }
>>>     };
>>>
>>>     /**
>>>      * The top UI <code>Container</code> to represent this class
>>>      */
>>>     JDialog dialog;
>>> ...
>>>
>>> There's something strange out there:
>>> When I'm using Eclipse, and jre 1.4.2_04 from Sun, I have no pb.
>>> But when my app is launched directly with the same jre, outside 
>>> Eclipse, the button doesn't execute the action code...
>>>
>>> I assume there is a problem in action listener registration  by Swix?
>>
>>
>>
>> Hm, this sounds rather strange. I do not know of any 1.4.2_04 specific 
>> issues there. I'm using eclipse to develop swixml applications quite 
>> seriously and did not have any problems there either...
>>
>> Please post the swix.render(...) call. I suspect a problem there.
>>
>> Frank
>>
>>> The problem doesn't happen if I set explicitely the action listener 
>>> in the Java code, which I'd like to avoid.
>>>
>>> Can anyone help ?
>>>
>>> Thx,
>>> Tristan Richard
>>>
>>>
>>> _______________________________________________
>>> Forum mailing list
>>> [email protected]
>>> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
>>>
> 
> 
> _______________________________________________
> Forum mailing list
> [email protected]
> http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.