java - Listener within @Autowired class called twice -
this autowired class :
@component public class alfrescologinframe extends javax.swing.jframe { private static final long serialversionuid = 6302651813469103752l; @autowired private maincontroller controller; public alfrescologinframe() { initcomponents(); initactions(); } private void initcomponents() { try { uimanager.setlookandfeel("com.jgoodies.looks.windows.windowslookandfeel"); //uimanager.setlookandfeel ( "com.alee.laf.weblookandfeel" ); } catch (classnotfoundexception e) { e.printstacktrace(); } catch (instantiationexception e) { e.printstacktrace(); } catch (illegalaccessexception e) { e.printstacktrace(); } catch (unsupportedlookandfeelexception e) { e.printstacktrace(); } lbl_user_name = new javax.swing.jlabel(); lbl_password = new javax.swing.jlabel(); txt_user_name = new javax.swing.jtextfield(); txt_password = new javax.swing.jtextfield(); bt_connexion = new javax.swing.jbutton(); bt_annuler = new javax.swing.jbutton(); lbl_alfreco_logo = new javax.swing.jlabel(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); settitle("se connecter"); lbl_user_name.settext("nom d'utilisateur"); lbl_password.settext("mot de passe"); bt_connexion.seticon(new imageicon(login_icon)); bt_connexion.settext("connexion"); bt_annuler.seticon(new imageicon(logout_icon)); bt_annuler.settext("annuler"); initactions(); lbl_alfreco_logo.seticon(new imageicon(alfresco_logo)); javax.swing.grouplayout layout = new javax.swing.grouplayout(getcontentpane()); getcontentpane().setlayout(layout); layout.sethorizontalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(79, 79, 79) .addcomponent(bt_connexion) .addgap(18, 18, 18) .addcomponent(bt_annuler, javax.swing.grouplayout.preferred_size, 105, javax.swing.grouplayout.preferred_size)) .addgroup(layout.createsequentialgroup() .addgap(89, 89, 89) .addcomponent(lbl_alfreco_logo)) .addgroup(layout.createsequentialgroup() .addgap(47, 47, 47) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(lbl_password, javax.swing.grouplayout.preferred_size, 79, javax.swing.grouplayout.preferred_size) .addcomponent(lbl_user_name)) .addgap(32, 32, 32) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addcomponent(txt_user_name, javax.swing.grouplayout.preferred_size, 107, javax.swing.grouplayout.preferred_size) .addcomponent(txt_password, javax.swing.grouplayout.preferred_size, 107, javax.swing.grouplayout.preferred_size)))) .addcontainergap(91, short.max_value)) ); layout.setverticalgroup( layout.createparallelgroup(javax.swing.grouplayout.alignment.leading) .addgroup(layout.createsequentialgroup() .addgap(28, 28, 28) .addcomponent(lbl_alfreco_logo, javax.swing.grouplayout.preferred_size, 57, javax.swing.grouplayout.preferred_size) .addpreferredgap(javax.swing.layoutstyle.componentplacement.related, 53, short.max_value) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(lbl_user_name) .addcomponent(txt_user_name, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addgap(23, 23, 23) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(lbl_password) .addcomponent(txt_password, javax.swing.grouplayout.preferred_size, javax.swing.grouplayout.default_size, javax.swing.grouplayout.preferred_size)) .addgap(49, 49, 49) .addgroup(layout.createparallelgroup(javax.swing.grouplayout.alignment.baseline) .addcomponent(bt_connexion) .addcomponent(bt_annuler)) .addgap(25, 25, 25)) ); pack(); } public void initactions(){ bt_connexion.addactionlistener(new loginactionlistener()); } private class loginactionlistener implements actionlistener { @override public void actionperformed(actionevent e) { //system.out.println("***"+e.getactioncommand()); // displays same event controller.checklogincreditsredirect(txt_user_name.gettext(),txt_password.gettext()); } } // declaration des variables private javax.swing.jbutton bt_annuler; private javax.swing.jbutton bt_connexion; private javax.swing.jlabel lbl_alfreco_logo; private javax.swing.jlabel lbl_password; private javax.swing.jlabel lbl_user_name; private javax.swing.jtextfield txt_password; private javax.swing.jtextfield txt_user_name; public static final string login_icon= system.getproperty("user.dir") + "/resource/com/talan/launcher/ui/icon/login_icon.png"; public static final string alfresco_logo = system.getproperty("user.dir") + "/resource/com/talan/launcher/ui/icon/alfresco_logo.jpg"; public static final string logout_icon = system.getproperty("user.dir") + "/resource/com/talan/launcher/ui/icon/logout_icon.png"; }
as u can see listener :
public void initactions(){ bt_connexion.addactionlistener(new loginactionlistener()); } private class loginactionlistener implements actionlistener { @override public void actionperformed(actionevent e) { //system.out.println("***"+e.getactioncommand()); // displays same event controller.checklogincreditsredirect(txt_user_name.gettext(),txt_password.gettext()); } }
and class maincontroller within class alfrescologinframe @autowired :
@component public class maincontroller { @autowired private isessionrepo sessionrepo; @autowired private wrongalfrescocreditsdialog wrongalfrescocredistdiag; public maincontroller() { } public void checklogincreditsredirect(string login, string password){ checklogincredits(login, password); if(sessionrepo.isvalid()){ //this sop executes twice system.out.println("logged in !"); }else{ //also sop executes twice system.out.println("not logged in : wrond credit !"); wrongalfrescocredistdiag.risewrongcreditspanel(alfresco_loginframe); } } }
so checklogincreditsredirect(string login, string password) method called twice. think it's spring issue, appreciated guys?
you call initactions() twice yourself. once constructor , once halfway initcomponents
method
next time have problem this: try debugging adding new exception().printstacktrace();
in method accidentally gets called twice
Comments
Post a Comment