Trigger is firing multiple times
Hi
we have a table in database , which has multiple triggers defined by Vendor. I have created our own custom trigger on this table also , which fires last. Goal of this custom trigger is to send an email, when ever update happens on table. But somehow
trigger is firing multiple times for same update, so it is sending multiple email for same update also
Any advice?
thanks
Drew
ALTER trigger [dbo].[AB_TABLEXXX_IUD_TR]
on [dbo].[TABLEXXX]
after insert,update,delete
as
begin
set nocount on
declare @sub varchar(1024)
declare @tmpstr nvarchar(max)
DECLARE @action as char(1);
declare @id as int
declare @send as int
SET @action = 'I'; -- Set Action to Insert by default.
declare @insCount int
declare @delCount int
DECLARE @newLineChar AS CHAR(2) = CHAR(13) + CHAR(10)
DECLARE @tab as CHAR(1)=char(9)
declare @vendorId char(30)
declare @detailmsg varchar(500)
declare @ovname varchar(30),@nvname varchar(100)
declare @ovchkname varchar(100),@nvchkname varchar(100)
declare @oaddress1 varchar(100),@naddress1 varchar(100)
declare @oaddress2 varchar(100),@naddress2 varchar(100)
declare @oaddress3 varchar(100),@naddress3 varchar(100)
declare @ouserdef1 varchar(100),@nuserdef1 varchar(100)
declare @ovndclsid varchar(11),@nvndclsid varchar(11)
select @tmpstr=''
select @insCount = count(*) from INSERTED
select @delCount = count(*) from DELETED
if(@insCount > 0 or @delCount > 0)--if something was actually affected, otherwise do nothing
Begin
if(@insCount = @delCount)
set @action = 'U'--is update
else if(@insCount > 0)
set @action = 'I' --is insert
else
set @action = 'D' --is delete
End
else
select @action='X'
if(@action='X') RETURN
select @sub='Not Found'
set @send=0
if (@action='I')
begin
select top 1 @vendorId=rtrim(VENDORID),@nvname=rtrim(VENDNAME),@nvchkname=rtrim(VNDCHKNM), @naddress1=rtrim(ADDRESS1) ,
@naddress2=rtrim(ADDRESS2),@naddress3=rtrim(ADDRESS3),@nuserdef1=rtrim(USERDEF1),@nvndclsid=rtrim(VNDCLSID) from inserted
select @sub=ORIGINAL_LOGIN()+' : '+'Data inserted in table ''TABLEXXX'''
select @send=1
select @sub=ORIGINAL_LOGIN()+' : '+'New Vendor
'''+@nvname+''' is added'
select @tmpstr=@sub
select @tmpstr =@tmpstr+@newLineChar +'Inserted On: '+ Convert(varchar(50),sysdatetime())+@newLineChar
select @tmpstr=@tmpstr+@newLineChar+'Vendor ID:
'+@vendorId
select @tmpstr=@tmpstr+@newLineChar+'Vendor Name:
'+@nvname
select @tmpstr=@tmpstr+@newLineChar+'Check Name:
'+@nvchkname
select @tmpstr=@tmpstr+@newLineChar+'Address1:
'+@naddress1
select @tmpstr=@tmpstr+@newLineChar+'Address2:
'+@naddress2
select @tmpstr=@tmpstr+@newLineChar+'Address3:
'+@naddress3
select @tmpstr=@tmpstr+@newLineChar+'User Def:
'+@nuserdef1
select @tmpstr=@tmpstr+@newLineChar+'Class ID:
'+@nvndclsid
end
if (@action='U')
begin
select @sub=ORIGINAL_LOGIN()+':''Data Updated in table ''TABLEXXX'''
declare @iTotal int
select @iTotal =0
select @detailmsg=''
create table #new_values(
VENDORID varchar(100) NULL,
processed char(1) NULL
insert into #new_values
select distinct VENDORID,NULL from inserted
while ((select count(*) from #new_values where processed is null)>0 and @iTotal<=50)
begin
--PRINT 'UPDATE Entered ' +@action
select @iTotal=@iTotal+1
select top 1 @vendorId=VENDORID from #new_values where processed is null
update #new_values set processed='Y' where
VENDORID=@vendorId and processed is null
select @detailmsg=''
select
top 1
@ovname=o.VENDNAME, @nvname=n.VENDNAME,
@ovchkname=o.VNDCHKNM,@nvchkname=n.VNDCHKNM,
@oaddress1=o.ADDRESS1,@naddress1=n.ADDRESS1,
@oaddress2=o.ADDRESS2,@naddress2=n.ADDRESS2,
@oaddress3=o.ADDRESS3,@naddress3=n.ADDRESS3,
@ouserdef1=o.USERDEF1,@nuserdef1=n.USERDEF1,
@ovndclsid=o.VNDCLSID,@nvndclsid=n.VNDCLSID
from inserted n,deleted o
where n.VENDORID=o.VENDORID and n.VENDORID
=@vendorId
if (update(VENDNAME) and @ovname<>@nvname) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Vendor Name: '+rtrim(@ovname)+' => '+rtrim(@nvname)
if (update(VNDCHKNM) and @ovchkname<>@nvchkname) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Check Name: '+rtrim(@ovchkname)+' => '+rtrim(@nvchkname)
if (update(ADDRESS1) and @oaddress1<>@naddress1) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Address1: '+rtrim(@oaddress1)+' => '+rtrim(@naddress1)
if (update(ADDRESS2) and @oaddress2<>@naddress2) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Address2: '+rtrim(@oaddress2)+' => '+rtrim(@naddress2)
if (update(ADDRESS3) and @oaddress3<>@naddress3) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Address3: '+rtrim(@oaddress3)+' => '+rtrim(@naddress3)
if (update(USERDEF1) and @ouserdef1<>@nuserdef1) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'User Def: '+rtrim(@ouserdef1)+' => '+rtrim(@nuserdef1)
if (update(VNDCLSID) and @ovndclsid<>@nvndclsid) select @detailmsg
=@detailmsg+ @newLineChar
+@tab+'Class ID: '+rtrim(@ovndclsid)+' => '+rtrim(@nvndclsid)
if(len(@detailmsg)>0)
begin
select @send=1
if (len(@tmpstr)<=0)
begin
select @sub=ORIGINAL_LOGIN()+' : '+'Vendor '''+rtrim(@ovname)+''' Updated in table TABLEXXX'
select @tmpstr='Vendor '''+rtrim(@ovname)+''' Updated'
select @tmpstr
=@tmpstr+@newLineChar +@tab+'Updated On: '+ Convert(varchar(50),sysdatetime())+@newLineChar
select @tmpstr
=@tmpstr+@newLineChar +@tab+'Vendor ID: '+rtrim(@vendorId)
end
select @tmpstr=@tmpstr +@detailmsg
end
end
end
if (@action='D')
begin
select top 1 @vendorId=rtrim(VENDORID),@nvname=rtrim(VENDNAME),@nvchkname=rtrim(VNDCHKNM), @naddress1=rtrim(ADDRESS1) ,
@naddress2=rtrim(ADDRESS2),@naddress3=rtrim(ADDRESS3),@nuserdef1=rtrim(USERDEF1),@nvndclsid=rtrim(VNDCLSID) from deleted
select @send=1
select @sub=ORIGINAL_LOGIN()+' : '+'Vendor
'''+@nvname+''' is DELETED'
select @tmpstr=@sub
select @tmpstr =@tmpstr+@newLineChar +'Deleted On: '+ Convert(varchar(50),sysdatetime())+@newLineChar
select @tmpstr=@tmpstr+@newLineChar+'Vendor ID:
'+@vendorId
select @tmpstr=@tmpstr+@newLineChar+'Vendor Name:
'+@nvname
select @tmpstr=@tmpstr+@newLineChar+'Check Name:
'+@nvchkname
select @tmpstr=@tmpstr+@newLineChar+'Address1:
'+@naddress1
select @tmpstr=@tmpstr+@newLineChar+'Address2:
'+@naddress2
select @tmpstr=@tmpstr+@newLineChar+'Address3:
'+@naddress3
select @tmpstr=@tmpstr+@newLineChar+'User Def:
'+@nuserdef1
select @tmpstr=@tmpstr+@newLineChar+'Class ID:
'+@nvndclsid
end
if (@action<>'X' and @send=1)
begin
Exec msdb.dbo.sp_send_dbmail
@profile_name='default',
@recipients='[email protected]',
@subject= @sub,
@body=@tmpstr
end
end
Drew
Similar Messages
-
Issue with When Validate Trigger firing multiple times
Hi guys,
I have Designed a Form Personalization on a Form which Fires a concurrent Program (built in:execute Procedure) when a Record is Saved.
Below are the issues I am facing:
1.Concurrent Program is Firing Multiple Times after Saving the Record.
2.2 input Values to Concurrent Program are passed as NULL though I have Data but they are in Different Block of Form.
Note :I have When Validate trigger on 1 Block but i am trying to pass 2 Values on Another Block as input parameters for Concurrent program.But those values are getting as null when program fires.
Thanks.If EBS then post in {forum:id=475}
-
Problem with ActionListener firing multiple times
I have a GUI class, GUIView, with a no-arg constructor and a static getInstance() method.
The GUI class has a JButton called btnB1 with a method:
void addB1Listener(ActionListener al){
btnB1.addActionListener(al);
}The Controller class has an instance of the GUI and the Model.
The Controller has a constructor which assigns a new ActionListener to the JButton from the GUI.
private GUI m_gui;
FTController(GUIView view){
m_gui = view;
m_gui.addButtonListener(new AddButtonListener());
}The Controller has an inner class:
class AddButtonListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
// do stuff
}The model has a constructor which accepts a GUIView.
My main method setups instances of the objects:
private GUIView view;
private Model model;
private Controller controller;
public static void main(String [] args){
view = GUIView.getInstance();
model = new Model(view);
controller = new Controller(view);
}This action listener for btnB1 is firing multiple times, but I don't understand why.
Edited by: user10199598 on Jan 9, 2012 2:56 PMHere is the actual Controller class
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JOptionPane;
import com.esri.arcgis.carto.FeatureLayer;
import com.esri.arcgis.carto.IActiveView;
import com.esri.arcgis.carto.Map;
import com.esri.arcgis.interop.AutomationException;
public class FTController{
private FTView m_arraView;
private FTModel m_arraModel;
private Map m_map;
FTController(FTView view, FTModel model, Map map){
m_arraView = view;
m_arraModel = model;
m_map = map;
m_arraView.addPointListener(new AddPointListener());
m_arraView.addExitListener(new AddExitListener());
m_arraView.addResetListener(new AddResetListener());
public FTView getM_arraView() {
return m_arraView;
// Inner class used as the ActionListener for the btnAddPoint in FTView
class AddPointListener implements ActionListener {
@Override
public void actionPerformed(ActionEvent e) {
FeatureLayer fl = (FeatureLayer) m_arraModel.getLayerByName("arra_field_teams", m_map);
try {
// Start the process to add a new feature point
m_arraModel.addPoint(fl, (IActiveView) m_map.getActiveView());
// Reset and dispose of the ARRA Field Teams form.
m_arraView.getCboTeam().setSelectedIndex(0);
m_arraView.getCboAgency().setSelectedIndex(0);
m_arraView.getTxtLatitude().setText("");
m_arraView.getTxtLongitude().setText("");
m_arraView.getTxtGridL().setText("");
m_arraView.getTxtGridN().setText("");
m_arraView.getTxtQuadrant().setText("");
m_arraView.getFtf3IC().setText("0.002");
m_arraView.getFtf3FC().setText("0.002");
m_arraView.getFtf3IO().setText("0.002");
m_arraView.getFtf3FO().setText("0.002");
m_arraView.getFtfAgxCartridge().setText("0.000");
m_arraView.getFtfBGCM().setText("50.000");
m_arraView.getFtfBGURHR().setText("0.002");
m_arraView.getTxtTimeOfReading().setText("");
m_arraView.dispose();
// Refresh the map window
m_map.getActiveView().refresh();
} catch (AutomationException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
} // end AddPointListener
// Inner class used as the ActionListener for the btnExit in FTView
class AddExitListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
m_arraView.getCboTeam().setSelectedIndex(0);
m_arraView.getCboAgency().setSelectedIndex(0);
m_arraView.getTxtLatitude().setText("");
m_arraView.getTxtLongitude().setText("");
m_arraView.getTxtGridL().setText("");
m_arraView.getTxtGridN().setText("");
m_arraView.getTxtQuadrant().setText("");
m_arraView.getFtf3IC().setText("0.002");
m_arraView.getFtf3FC().setText("0.002");
m_arraView.getFtf3IO().setText("0.002");
m_arraView.getFtf3FO().setText("0.002");
m_arraView.getFtfAgxCartridge().setText("0.000");
m_arraView.getFtfBGCM().setText("50.000");
m_arraView.getFtfBGURHR().setText("0.002");
m_arraView.getTxtTimeOfReading().setText("");
m_arraView.dispose();
} // end AddExitListener
// Inner class used as the ActionListner for the btnReset in FTView
class AddResetListener implements ActionListener{
@Override
public void actionPerformed(ActionEvent e) {
FeatureLayer fl = (FeatureLayer) m_arraModel.getLayerByName("field_teams", m_map);
try {
// Actually, "Reset" is deleting all features from the shapefile, poor choice of labels.
m_arraModel.resetFeatures(fl, (IActiveView) m_map.getActiveView(), (Map) m_map);
// Refresh the map window
m_map.getActiveView().refresh();
} catch (AutomationException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}Here is where the application starts:
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import com.esri.arcgis.addins.desktop.Tool;
import com.esri.arcgis.arcmap.Application;
import com.esri.arcgis.arcmapui.IMxDocument;
import com.esri.arcgis.arcmapui.MxDocument;
import com.esri.arcgis.carto.IActiveView;
import com.esri.arcgis.carto.IFeatureLayer;
import com.esri.arcgis.carto.Map;
import com.esri.arcgis.framework.IApplication;
import com.esri.arcgis.geodatabase.Feature;
import com.esri.arcgis.geodatabase.IFeatureClass;
import com.esri.arcgis.geometry.Point;
import com.esri.arcgis.interop.AutomationException;
public class FTTool extends Tool {
private IApplication app;
private IActiveView av;
private IMxDocument mxDocument;
private Map map;
private FTView arraView;
private FTModel model;
private FTController controller;
private int left;
private int top;
* Called when the tool is activated by clicking it.
* @exception java.io.IOException if there are interop problems.
* @exception com.esri.arcgis.interop.AutomationException if the component throws an ArcObjects exception.
@Override
public void activate() throws IOException, AutomationException {
@Override
public void init(IApplication app) throws IOException, AutomationException {
this.app = app;
try {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// Initialize our map document, map and active view
mxDocument = (IMxDocument)app.getDocument();
av = mxDocument.getActiveView();
map = (Map)mxDocument.getMaps().getItem(0);
// Get an instance of the ARRAView JFrame, and setup the model and controller for this tool add-in
arraView = FTView.getInstance();
// arraView.addWindowListener(arraView);
// Set up the model and controller objects
model = new FTModel(arraView);
controller = new FTController(arraView, model, map);
} catch (AutomationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
@Override
public void mousePressed(MouseEvent mouseEvent) {
super.mousePressed(mouseEvent);
// Cast IMxDocument into MxDocument so we can get the Parent which returns an Application
MxDocument mxd = (MxDocument)mxDocument;
Application application;
// Create an Application object so we can get the left and top properties of the window
// so we can position the Field Teams GUI.
try {
application = new Application(mxd.getParent());
left = application.getLeft() + 75;
top = application.getTop() + 105;
} catch (IOException e2) {
e2.printStackTrace();
try {
// Call the model to convert the screen coordinates to map coordinates and project the point to WGS_1984
Point p1 = new Point();
p1.putCoords((double)mouseEvent.getX(), (double)mouseEvent.getY());
Point p2 = (Point) model.getMapCoordinatesFromScreenCoordinates(p1, av);
Point point = (Point)model.handleToolMouseEvent(mouseEvent, av);
// Format the decimal degrees to six decimal places
DecimalFormat df = new DecimalFormat("#.######");
// Assign the point2 values to double
double x = point.getX();
double y = point.getY();
// Set the text of the lat/long fields.
arraView.getTxtLatitude().setText(df.format(y));
arraView.getTxtLongitude().setText(df.format(x));
// Set the Time of Reading text field
Date now = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
arraView.getTxtTimeOfReading().setText(sdf.format(now).toString());
// Determine whether the mouse click point intersects the arra_grid_quad.
// If so, iterate over that feature cursor to update the gridl, gridn and quadrant fields...
IFeatureLayer featLayer = (IFeatureLayer) model.getLayerByName("arra_grid_quads", map);
IFeatureClass featClass = featLayer.getFeatureClass();
Feature iFeat = (Feature) model.queryArraGridQuads(featClass, p2);
if(iFeat != null){
// Fill in the grid and quadrant values if there are any.
String gridl = (String) iFeat.getValue(iFeat.getFields().findField("GRID_L"));
String gridn = (String) iFeat.getValue(iFeat.getFields().findField("GRID_N"));
String quadrant = (String) iFeat.getValue(iFeat.getFields().findField("QUADRANT"));
arraView.getTxtGridL().setText(gridl);
arraView.getTxtGridN().setText(gridn);
arraView.getTxtQuadrant().setText(quadrant);
} else {
// Revert values back to empty string after clicking in the grid, then outside of the grid.
arraView.getTxtGridL().setText("");
arraView.getTxtGridN().setText("");
arraView.getTxtQuadrant().setText("");
// Set the Field Team Readings form to visible, or redisplay it if it is already visible
arraView.setBounds(left, top, 325, 675);
arraView.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
@Override
public boolean deactivate() throws IOException, AutomationException {
return super.deactivate();
@Override
public boolean isChecked() throws IOException, AutomationException {
return super.isChecked();
public FTView getArraView() {
return arraView;
public IApplication getApp() {
return app;
public Map getMap() {
return map;
public FTModel getModel() {
return model;
}Is this enough?
Edited by: user10199598 on Jan 9, 2012 3:20 PM -
CFSchedule firing multiple times
Hi Everyone,
i still have not found a solution to this. if anyone has any
other suggestions please let me know.
Also i would like to report this as a bug, what is the proper
procedure for reporting this?
thanks to all
Tim
Original- Hi All,
i have had issues since upgrading from 6 to 7 with
cfschedule. sometimes it runs fine, other times it will run the
same task multiple times in a row, other times it will wait an hour
then run the same task again.
This may not sound like a big deal, but the tasks send out
several thousands of emails. talk about spam!!
I have been screamed at on a weekly basis to make this stop.
Now since the the DST change, the tasks that were scheduled
at 3pm run at 3pm and again at 4pm!!
Please someone help!!!!!!!!!!!!!!!!!!!!!
Thanks in advance.
TimHi BK,
in my task is setup to run every 15 with a start date of a
few days ago and no end date or time.
it calls a file on the same server via its dsn name.
The file it calls is this:
[code]
<cfset testtext = "Testing st #now()#">
<cfset testSTname = "d:\st_test_" &
#DateFormat(now(),"yyyymmdd")#&""&#TimeFormat(now(),"HHmmss")#
&".txt">
<!--- <cffile action="write" file="#testSTname#"
output="#testtext#" nameconflict="makeunique"> --->
<cfmail to="[email protected]" from="[email protected]"
subject="st timer test">
#Dateformat(now(),"mm/dd/yyyy")#
#TimeFormat(now(),"hh:mm:ss:l")#
</cfmail>
[/code]
If you notice i commented out the file write. something was
puzzling about it, it would write fine for an hour then once in
awhile write multiples (by comparing the date created on the file
in windows.
I then found the calls in my IIS log file, every single call
was done twice at exactly the same time.
(edited for security)
[code]
2007-07-30 22:15:06 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
2007-07-30 22:15:06 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
2007-07-30 22:30:06 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
2007-07-30 22:30:06 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
2007-07-30 22:45:08 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
2007-07-30 22:45:08 x.x.x.x GET /tools/test_ts.cfm - 80 -
x.x.x.x CFSCHEDULE 200 0 0
[/code]
So i decieded to make it send an email, this way there is a
queue so to speak for the messages to be written, i think this is
why i saw speratic multiples with cffile.
Email 1 contents: {ts '2007-07-31 01:30:00'} 01:30:00:769
Email 2 contents: {ts '2007-07-31 01:30:00'} 01:30:00:909
So far, i am only getting 2 copies for every fire of the
task, but i have seen in other tasks that email, up to 6 copies.
i can see this in IIS Logs, the test cfm file being called at
least twice per task for long periods, then other tasks will fire
and i only see a single call to the test cfm file. but its next
execution time is duplicated if there is no other tasks running
during the same time period
I have dug through all the logs for each task, so far all of
the task that have no end date fire multiple times.
I can see the results (files written, db records inserted,
emails sent, IIS log files).
all show duplicates during same creation time Except the
scheduler.log it only shows each of those tasks firing once.
I can only assume that the scheduler log is being updated
correctly which leads me to belive that this log entry is done some
time before the scheduler payload execution or the scheduler code
dosnt log multiple triggers on its actions.
So i am going to set the End date for this test task to see
if the duplicates stop.
more to come
Tim -
Alert is Firing multiple Times
Hi,
I designed an alert for one of my requirement, for this i build i a sql statement
and my sql statement is returning 20 records and i check the same in Application, the records are matching and till now every thing works fine for me.
When i start my alert, My alert is firing 20 times and i am receiving 20 mails, but my requirement is i need to consolidated all the records and need to send a mail.
Do i need to do some setup for this, please help me on this.
Thanks for all for your continuous help and guidance.
NazHello,
When you created your alert action to create the notification, what did you set the action level to? Sound like you want it to be Summary but you have it set at Detail. Create another notification at Summary level and see if you get the results you are looking for.
HTH,
--Johnnie -
MouseClicked firing multiple times
Greetings,
I have a GUI Java application with a few buttons that do different things. Sometimes, my mouseClicked event seems to get fired several times instead of the once I've actually clicked it.
Example:
BTN_Launch.setText("Upload File(s)");
BTN_Launch.setPreferredSize(new Dimension(140,40));
BTN_Launch.setMinimumSize(new Dimension(140,40));
BTN_Launch.setToolTipText("Run Upload Process");
BTN_Launch.setFont(Font_Bold);
BTN_Launch.setEnabled(false);
BTN_Launch.addMouseListener(new launchClicked());
class launchClicked extends MouseAdapter {
public synchronized void mousePressed(MouseEvent e) { }
public synchronized void mouseReleased(MouseEvent e) { }
public synchronized void mouseClicked(MouseEvent e) {
String foundErrors = "0";
int errCount = 0;
if( uploadFileDirectory.equals("") ) { foundErrors += ":1"; errCount++; }
if( uploadFiles.length == 0 ) { foundErrors += ":2"; errCount++; }
if( selectedVendor.equals("") ) { foundErrors += ":3"; errCount++; }
if( qdocUsername.getText() != null && qdocUsername.getText().equals("") == false) {
QDoc_UserName = qdocUsername.getText();
} else {
foundErrors += ":4";
errCount++;
if( qdocPassword.getPassword() != null && qdocPassword.getPassword().length > 0) {
QDoc_Password = new String(qdocPassword.getPassword());
} else {
foundErrors += ":5";
errCount++;
if( foundErrors.equals("0") == false ) {
int index = 0;
String[] errString = new String[errCount + 2];
errString[index] = ERR_HEAD;
if( foundErrors.indexOf("1") >= 0 ) { errString[++index] = MSG1; }
if( foundErrors.indexOf("2") >= 0 ) { errString[++index] = MSG2; }
if( foundErrors.indexOf("3") >= 0 ) { errString[++index] = MSG3; }
if( foundErrors.indexOf("4") >= 0 ) { errString[++index] = MSG4; }
if( foundErrors.indexOf("5") >= 0 ) { errString[++index] = MSG5; }
errString[++index] = ERR_FOOT;
JOptionPane.showMessageDialog(Main, errString,
"Validation Error",
JOptionPane.ERROR_MESSAGE);
} else {
if( emailRecipients.contains(QDoc_UserName) == false ) {
emailRecipients.addElement(QDoc_UserName);
for( int x=1; x<VENDORS.length; x++ ) {
emailRecipients.remove(vendorEmails.get(VENDORS[x]));
emailRecipients.addElement(vendorEmails.get(selectedVendor));
System.out.println("Start upload...");
System.out.print("Files: ");
for( int x=0; x<uploadFiles.length; x++ ) {
System.out.print("\"" + uploadFiles[x] + "\" ");
System.out.println();
System.out.println("Dir: \"" + uploadFileDirectory + "\"");
System.out.println("Vendor: \"" + selectedVendor + "\"");
System.out.println("User: \"" + QDoc_UserName + "\"");
System.out.println("Pwd: \"" + QDoc_Password + "\"");
System.out.println("Publish: \"" + publishFiles + "\"");
System.out.println("EMail: \"" + emailRecipients.toString() + "\"");
The code in launchClicked.mouseClicked(e) method is getting executed more than once in many situations. What seems to be wrong here?Greetings,
I have a GUI Java application with a few buttons that do different things. Sometimes, my mouseClicked event seems to get fired several times instead of the once I've actually clicked it.
Example:
BTN_Launch.setText("Upload File(s)");
BTN_Launch.setPreferredSize(new Dimension(140,40));
BTN_Launch.setMinimumSize(new Dimension(140,40));
BTN_Launch.setToolTipText("Run Upload Process");
BTN_Launch.setFont(Font_Bold);
BTN_Launch.setEnabled(false);
BTN_Launch.addMouseListener(new launchClicked());
class launchClicked extends MouseAdapter {
public synchronized void mousePressed(MouseEvent e) { }
public synchronized void mouseReleased(MouseEvent e) { }
public synchronized void mouseClicked(MouseEvent e) {
String foundErrors = "0";
int errCount = 0;
if( uploadFileDirectory.equals("") ) { foundErrors += ":1"; errCount++; }
if( uploadFiles.length == 0 ) { foundErrors += ":2"; errCount++; }
if( selectedVendor.equals("") ) { foundErrors += ":3"; errCount++; }
if( qdocUsername.getText() != null && qdocUsername.getText().equals("") == false) {
QDoc_UserName = qdocUsername.getText();
} else {
foundErrors += ":4";
errCount++;
if( qdocPassword.getPassword() != null && qdocPassword.getPassword().length > 0) {
QDoc_Password = new String(qdocPassword.getPassword());
} else {
foundErrors += ":5";
errCount++;
if( foundErrors.equals("0") == false ) {
int index = 0;
String[] errString = new String[errCount + 2];
errString[index] = ERR_HEAD;
if( foundErrors.indexOf("1") >= 0 ) { errString[++index] = MSG1; }
if( foundErrors.indexOf("2") >= 0 ) { errString[++index] = MSG2; }
if( foundErrors.indexOf("3") >= 0 ) { errString[++index] = MSG3; }
if( foundErrors.indexOf("4") >= 0 ) { errString[++index] = MSG4; }
if( foundErrors.indexOf("5") >= 0 ) { errString[++index] = MSG5; }
errString[++index] = ERR_FOOT;
JOptionPane.showMessageDialog(Main, errString,
"Validation Error",
JOptionPane.ERROR_MESSAGE);
} else {
if( emailRecipients.contains(QDoc_UserName) == false ) {
emailRecipients.addElement(QDoc_UserName);
for( int x=1; x<VENDORS.length; x++ ) {
emailRecipients.remove(vendorEmails.get(VENDORS[x]));
emailRecipients.addElement(vendorEmails.get(selectedVendor));
System.out.println("Start upload...");
System.out.print("Files: ");
for( int x=0; x<uploadFiles.length; x++ ) {
System.out.print("\"" + uploadFiles[x] + "\" ");
System.out.println();
System.out.println("Dir: \"" + uploadFileDirectory + "\"");
System.out.println("Vendor: \"" + selectedVendor + "\"");
System.out.println("User: \"" + QDoc_UserName + "\"");
System.out.println("Pwd: \"" + QDoc_Password + "\"");
System.out.println("Publish: \"" + publishFiles + "\"");
System.out.println("EMail: \"" + emailRecipients.toString() + "\"");
The code in launchClicked.mouseClicked(e) method is getting executed more than once in many situations. What seems to be wrong here? -
Event firing multiple times (et_Got_Focus)
Hi,
I just noticed while debugging my Add On code that the et_Got_Focus event which I have added to my event filters is triggered 64 times when I change a field value and then move to a different field. This not only happens in the matrix when changing field values and tabbing through but also in the header fields.
This has got to be a bug and it is not only slowing down the A/P Invoice form but it is potentially very dangerous to have an event firing 64 times when it should only be fired once.
To test this all one needs to do is add the et_Got_Focus event to the event filter with the A/P Invoice form, then add a debug statement to write out the itemvalue properties and you will see once you edit a value and tab you will get 64 statements that are the et_Got_Focus event, BeforeAction false for the same field or column when it should only occur once.
I have a very digrunted client that is very frustrated due to the amount this slows down data entry in the A/P Invoice. I cannot get rid of this event because there is a particular field I am monitoring for the got focus event so I can stop it under certain circumstances.
If anyone else has experienced this or knows how to resolve this please let me know. I guess if I don't find out why this is happening I will post a CSN to SAP.
Thanks very much,
David Wall
Here is a sample of my debug output messages for one update of a single field and then tabbing out:
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - False
et_GOT_FOCUS - - FalseHi David,
We at Self Informatique France have the same problem of getfocus firing many times at one of our customers in Algeria although wae are not using formated search.Any solution ?
Best Rgds.
Antoine Egeileh
President
Self Informatique
[email protected] -
JPane ancestorResized event fired multiple times
Hi,
I have a JPane which in turn contains some more controls. I'm handling "ancestorResized" event for the JPane. But, when I resize the form once, the "ancestorResized" event for the JPane is called 3 times. where as the "this_componentResized" event is called only once.
I am doing a lot of control relocation and resizing in the "ancestorResized" event handler. Since it is fired 3 times, it is making my application slow.
Can some body tell me how to come over this.
Regards.Hi David,
We at Self Informatique France have the same problem of getfocus firing many times at one of our customers in Algeria although wae are not using formated search.Any solution ?
Best Rgds.
Antoine Egeileh
President
Self Informatique
[email protected] -
[iPhone] - button press even firing multiple times
Hi - first post here, so sorry if it's dumb (doesn't seem to have been answered previously, by searching)...
I have an iPhone app, with a button. In my ViewController code I have an IBAction, which I've linked up with the Touch Up Inside event. The Action function increases an integer score by 50, and then updates a label to display the new score.
When I run this, the score goes up in increments of 200 - implying the button even is being triggered multiple (four) times per click.
Is that normal / is there any obvious reason why this might happen? I can post code if that's useful...
Thanks,
MuzzHi Ace, and wecome to the Dev Forum!
Acemuzzy wrote:
When I run this, the score goes up in increments of 200 - implying the button even is being triggered multiple (four) times per click.
No need to guess. Add a log statement as the first line of your action method like this:
- (IBAction)incrementScore:(id)sender {
NSLog(@"incrementScore: sender=%@", sender);
The above will print one line in your Debugger Console window (Run->Dubugger Console) each time the method runs. It's very unlikely that your button is sending more than one action message for each Touch Up Inside event. The console log should tell us exactly who is calling your action method and how many times.
Is that normal
No.
is there any obvious reason why this might happen?
My three top guesses would be: 1) The code in your action method isn't doing what you think; 2) The action method is being called from more than one object; 3) You hooked up the button so that some of its other events (such as Touch Down or Touch Down Repeat) are also connected to your method.
I can post code if that's useful...
Yes, if none of my comments lead you to a solution please post the relevant code. To format code in this forum, please take a look at the first, yellow alert message on the topics page. You can see how your code will appear by clicking the Preview tab above the Reply editor panel. If and when your question is resolved, here's how to close your thread: [http://discussions.apple.com/help.jspa#answers].
- Ray -
in the game i'm makin i got the bullet to fire and move across the screen but it will only let me fire once, how can i get it to let me fire more than once?? if u need to see my code let me no
i'm going to copy and paste the code that i have now, is still will only fire one shot
sorry if it's a little jumbled and confusing but any help would be great
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TestPanel extends JPanel
private int move=10, x=180, y=730, delay=500, yb=-250, p, by;
private ImageIcon left, stop, right, currentImage, back, bullet;
private Timer timer;
public TestPanel()
addKeyListener (new DirectionListener());
stop = new ImageIcon ("plane1.jpg");
left = new ImageIcon ("planeleft.jpg");
right = new ImageIcon ("planeright.jpg");
back = new ImageIcon ("backb.jpg");
bullet = new ImageIcon ("bullet.jpg");
currentImage = stop;
by=y;
ActionListener movePlane = new MoveListener();
timer = new Timer(delay,movePlane);
timer.setInitialDelay(500);
timer.start();
setPreferredSize (new Dimension(400,800));
setFocusable(true);
public void paintComponent (Graphics page)
super.paintComponent (page);
back.paintIcon (this, page, 0 ,yb);
currentImage.paintIcon (this, page, x, y);
if (p>0)
bullet.paintIcon (this, page, x, by);
Thread fireBullet = new Thread(){
public void run(){
while (true){
by--;
repaint();
try{
Thread.sleep(600); }
catch (InterruptedException e){
e.printStackTrace();
fireBullet.start();
private class DirectionListener implements KeyListener
public void keyPressed (KeyEvent event)
switch (event.getKeyCode())
case KeyEvent.VK_LEFT:
currentImage = left;
x -= move;
break;
case KeyEvent.VK_RIGHT:
currentImage = right;
x += move;
break;
case KeyEvent.VK_UP:
currentImage = stop;
y -= move;
break;
case KeyEvent.VK_DOWN:
currentImage = stop;
y += move;
break;
case KeyEvent.VK_SPACE:
p++;
break;
repaint();
public void keyTyped (KeyEvent event) {}
public void keyReleased (KeyEvent event)
currentImage = stop;
repaint();
private class MoveListener implements ActionListener
public void actionPerformed (ActionEvent event)
yb=yb+10;
repaint();
} -
View events are firing multiple times after navigating views.
I made a basic app that has a Home View and a 2nd View and attached mxml events for activate and deactivate onto each of them. From the home view there is a button that pushes the 2nd view. If I suspend and reopen the app from the Home View, the deactivate and activate events fire once each. Then, if I go to the 2nd view and do the same thing, the activate/deactiate events from the Home View fire alongside the ones from the 2nd view. When I go back to the Home view and repeat the test, 3 sets of activate/deactivate events fire (2 from home, 1 from 2nd) and this keeps going. Why is this happening and how do I prevent it? Am I doing something wrong here?
I've tested this in Air 3.3-3.5 on an android 2.3 device and on the desktop tester.If EBS then post in {forum:id=475}
-
JSF event firing multiple times?
Just upgraded our JSF app from using JBoss4.0.0 to JBoss4.0.5.
Tomcat 5 -> Tomcat5.5
Java1.4.2 -> Java5.0
Of course as a result of all these changes, some things that used to work in the app, either no longer work or work differently.
We have been using the Sun RI implementation of JSF.
Through googling, I found that Jboss installed MyFaces. That has been removed, and resolved some of our issues (mainly to do with nested tables)
The current issue is that there are instances where clicking a button seems to execute the JSF action twice. In this case it is a "process payment", so the payment ends up getting recorded twice in the database.
Potential causes I have looked at
1 - javascript submission form.submit() as well as button click. Pretty sure that this is not happening.
2 - Double clicking the submit() button? Some javascript has been written to prevent this, and it seems to be working.
Can anybody suggest ideas as to why the JSF event would be triggered twice?
Would a JSF event be triggered on a later request if it failed to complete successfully on a first try?I don't want to use immediate=true, because I need the values entered from the screen. Or are you suggesting it for another reason?
Anyway, I'm still working on this, and have been running debug logs.
Something interesting seems to be happening:
I am pretty sure I only pushed the button once.
Note however that two threads seem to be starting up, and two FacesContext objects seem to be present.
I am deducing that from
execute(com.sun.faces.context.FacesContextImpl@1ebfb58)
execute(com.sun.faces.context.FacesContextImpl@1c283b5)
There are two facesContextImpl with different addresses.
Is it normal to have two FacesContext instance objects?
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] execute(com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(APPLY_REQUEST_VALUES 2,com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] execute(com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RESTORE_VIEW 1,com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,092 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(APPLY_REQUEST_VALUES 2,com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,123 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,138 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(UPDATE_MODEL_VALUES 4,com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,154 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(PROCESS_VALIDATIONS 3,com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,154 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(INVOKE_APPLICATION 5,com.sun.faces.context.FacesContextImpl@1ebfb58)
2007-05-10 09:38:00,185 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(UPDATE_MODEL_VALUES 4,com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,185 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(INVOKE_APPLICATION 5,com.sun.faces.context.FacesContextImpl@1c283b5)
2007-05-10 09:38:00,201 DEBUG [com.sun.faces.lifecycle.LifecycleImpl] phase(RENDER_RESPONSE 6,com.sun.faces.context.FacesContextImpl@1c283b5) -
Query executing multiple times
All,
This question has been come up quite often in the OTN forum and i have not managed to get the answer. The issue is when i enable the logs i can see query getting fired multiple times :
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> ----[Exec query for VO=Kpi, RS=<Default>]----
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> ----[Exec COUNT query for VO=Kpi]----
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> VODef =com.xxx.model.uiView.KpiVO
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> SELECT
kpi.kpi,
kpi.kpi_desc,
kpi.target,
kpi_pkg.get_kpi_main (kpi.kpi, kpi.sale_type, :bSelectedSalesExecutiveId, :bSelectedBranchId ,:bOperatingUnitId, :bUserRole, :bPersonId, :bKpiRefresh) achieved,
kpi.percentage,
kpi.sale_type
FROM tableName kpi
WHERE kpi.sale_type = NVL (:bSaleType, kpi.sale_type)
ORDER BY tag
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> BindVars:(bUserRole=SE,bOperatingUnitId=81,bPersonId=31458,bSaleType=RETAIL,bSelectedBranchId=224,bSelectedSalesExecutiveId=31458,bKpiRefresh=Y)
<TracingViewObjectSqlQueryExecution> <getQueryHitCount> ***** Query Hit Count = 6 *****
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> VODef =com.xxx.model.uiView.KpiVO
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> SELECT
kpi.kpi,
kpi.kpi_desc,
kpi.target,
kpi_pkg.get_kpi_main (kpi.kpi, kpi.sale_type, :bSelectedSalesExecutiveId, :bSelectedBranchId ,:bOperatingUnitId, :bUserRole, :bPersonId, :bKpiRefresh) achieved,
kpi.percentage,
kpi.sale_type
FROM tableName kpi
WHERE kpi.sale_type = NVL (:bSaleType, kpi.sale_type)
ORDER BY tag
<TracingViewObjectSqlQueryExecution> <logQueryStatementAndBindParameters> BindVars:(bUserRole=SE,bOperatingUnitId=81,bPersonId=31458,bSaleType=RETAIL,bSelectedBranchId=224,bSelectedSalesExecutiveId=31458,bKpiRefresh=Y)This is one such case. These repetitive nature of the queries getting executed is making my application slow. On the logs i can see the first time query getting executed then waiting for it to finish then the same for the second time. Can any one give some inputs on this ?
thnks
Jdev 11.1.1.5thnks Frank for your reply.
Ideally this query is supposed to run when the page is loaded however it has a complex calculation which takes 28 secs to complete. In order to load the page fast we dragged and dropped the collection as a table and added a button which executes the query. So the query gets executed on page load with a condition set as false so that no data is fetched - to speed the page load. However when we press the Refresh button the query gets re executed but as you can see 2 times. I can see the same effect on a nos of tables. -
How to trigger Condition Access sequence multiple times for one line item?
Hi,
We have a situation that, User will enter a Promo code (custom Field) in Sales order Header Additional data B tab to apply discount for line items.
Logic goes like this:
1. For each Promo code .. there may be multiple sale deals (Max 3 at this point).
2. For each line item (refering to tkomp table) we have to apply the sale deals (found above) the Condition access sequence will pick the right sale deal to apply the line item.
3.we have enhanced the tkomp structure to hold the sale deal.
Challenge:
As we have the standard logic to trigger the condition access sequence once for each line item, how we can apply 3 sale deals for single line item. Is there any logic or way to trigger the condition access sequence multiple times for single line item with diffrent sale deals. ~ There may be one valid sale deal for one line.
Functional team maintained diffrent access tables in the access sequence!!!
Fnds, please help me to get some clue
Thanks,
Sunil YHi Eduardo , Thanks for the response.
I am trying to explain again, this is the requirment given by the functional guys.
we have Promo code in Hearder Addtional data B tab --> Have to retrieve Sale Deals -->
At this point of time we may have at max 3 Sale Deals. we don't know which sale deal is vallied for which item we have in TKOMP. We have enhanced the TKOMP structure to hold one sale deal only (ZZPROMO).
We have enhanced USEREXIT_PRICING_PREPARE_TKOMP in RV60AFZZ to populate the value in TKOMP. Then it will go for diffrent access sequence to find the proper condition.
Our challenge is that, for each line item we have 3 sale deals, we don't know which one is valid for which line. but we have to apply the vallied sale Deal to the line items. Line item 10 may have Sale Deal 2 , item 20 may have Sale Deal3 and 30 may have sale deal 1.
We may have solution, by fixing some thing in the code or through config. But i am confused that is it a valid requirment?
Please help me ...
Thanks,
Sunil Y -
Default button being clicked multiple times when enter key is pressed
Hello,
There seems to be a strange difference in how the default button behaves in JRE 1.4.X versus 1.3.X.
In 1.3.X, when the enter key was pressed, the default button would be "pressed down" when the key was pressed, but wouldn't be fully clicked until the enter key was released. This means that only one event would be fired, even if the enter key was held down for a long time.
In 1.4.X however, if the enter key is pressed and held for more than a second, then the default button is clicked multiple times until the enter key is released.
Consider the following code (which is just a dialog with a button on it):
public class SimpleDialog extends JDialog implements java.awt.event.ActionListener
private JButton jButton1 = new JButton("button");
public SimpleDialog()
this.getContentPane().add(jButton1);
this.getRootPane().setDefaultButton(jButton1);
jButton1.addActionListener(this);
this.pack();
public void actionPerformed(ActionEvent e)
if (e.getSource() == jButton1)
System.out.println("button pressed");
public static void main(String[] args)
new SimpleDialog().show();
When you compile and run this code under 1.3.1, and hold the enter key down for 10 seconds, you will only see one print line statement.
However, if you compile and run this code under 1.4.1, and then hold the enter key down for 10 seconds, you will see about 100 print line statements.
Is this a bug in 1.4.X or was this desired functionality (e.g. was it fixing some other bug)?
Does anyone know how I can make it behave the "old way" (when the default button was only clicked once)?
Thanks in advance if you have any advice.
DaveHello all,
I think I have found a solution. The behaviour of the how the default button is triggered is contained withing the RootPaneUI. So, if I override the default RootPaneUI used by the UIDefaults with my own RootPaneUI, I can define that behaviour for myself.
Here is my simple dialog with a button and a textfield (when the focus is NOT on the button, and the enter key is pressed, I don't want the actionPerformed method to be called until the enter key is released):
package focustests;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;
public class SimpleDialog extends JDialog implements java.awt.event.ActionListener
private JButton jButton1 = new JButton("button");
public SimpleDialog()
this.getContentPane().add(new JTextField("a text field"), BorderLayout.NORTH);
this.getContentPane().add(jButton1, BorderLayout.SOUTH);
this.getRootPane().setDefaultButton(jButton1);
jButton1.addActionListener(this);
this.pack();
public void actionPerformed(ActionEvent e)
if (e.getSource() == jButton1)
System.out.println("button pressed");
public static void main(String[] args)
javax.swing.UIManager.getDefaults().put("RootPaneUI", "focustests.MyRootPaneUI");
new SimpleDialog().show();
and the MyRootPaneUI class controls the behaviour for how the default button is handled:
package focustests;
import javax.swing.*;
* Since we are using the Windows look and feel in our product, we should extend from the
* Windows laf RootPaneUI
public class MyRootPaneUI extends com.sun.java.swing.plaf.windows.WindowsRootPaneUI
private final static MyRootPaneUI myRootPaneUI = new MyRootPaneUI();
public static javax.swing.plaf.ComponentUI createUI(JComponent c) {
return myRootPaneUI;
protected void installKeyboardActions(JRootPane root) {
super.installKeyboardActions(root);
InputMap km = SwingUtilities.getUIInputMap(root,
JComponent.WHEN_IN_FOCUSED_WINDOW);
if (km == null) {
km = new javax.swing.plaf.InputMapUIResource();
SwingUtilities.replaceUIInputMap(root,
JComponent.WHEN_IN_FOCUSED_WINDOW, km);
//when the Enter key is pressed (with no modifiers), trigger a "pressed" event
km.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,
0, false), "pressed");
//when the Enter key is released (with no modifiers), trigger a "release" event
km.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ENTER,
0, true), "released");
ActionMap am = SwingUtilities.getUIActionMap(root);
if (am == null) {
am = new javax.swing.plaf.ActionMapUIResource();
SwingUtilities.replaceUIActionMap(root, am);
am.put("press", new HoldDefaultButtonAction(root, true));
am.put("release", new HoldDefaultButtonAction(root, false));
* This is a copy of the static nested class DefaultAction which was
* contained in the JRootPane class in Java 1.3.1. Since we are
* using Java 1.4.1, and we don't like the way the new JRE handles
* the default button, we will replace it with the old (1.3.1) way of
* doing things.
static class HoldDefaultButtonAction extends AbstractAction {
JRootPane root;
boolean press;
HoldDefaultButtonAction(JRootPane root, boolean press) {
this.root = root;
this.press = press;
public void actionPerformed(java.awt.event.ActionEvent e) {
JButton owner = root.getDefaultButton();
if (owner != null && SwingUtilities.getRootPane(owner) == root) {
ButtonModel model = owner.getModel();
if (press) {
model.setArmed(true);
model.setPressed(true);
} else {
model.setPressed(false);
public boolean isEnabled() {
JButton owner = root.getDefaultButton();
return (owner != null && owner.getModel().isEnabled());
This seems to work. Does anyone have any comments on this solution?
Tjacobs, I still don't see how adding a key listeners or overriding the processKeyEvent method on my button would help. The button won't receive the key event unless the focus is on the button. There is no method "enableEvents(...)" in the AWTEventMulticaster. Perhaps you have some code examples? Thanks anyway for your help.
Dave
Maybe you are looking for
-
I am using the latest version of Airport Utility. My windows 8 laptop can connect to the internet through my Airport Extreme, likewise I have no problems file or printer sharing on my network of mixed widows and apple machines but Airport Utility can
-
How to upload a dynamic website?
Hi All, I have made a project on Netbeans 6.1 using JSF architecture and Apache Tom Cat 6.0.14. The database is Microsoft Sequel Server 2005. I want to host it on a website. I am prepared to purchase web space for web hosting. What features should be
-
Problem in BAPI_ACTIVITYCRM_CREATEMULTI
Hi Experts! I am uploading activity in crm throu BAPI_ACTIVITYCRM_CREATEMULTI. When I am inserting data in structures BAPIBUS2000110_HEADER_INS BAPIBUS20001_HEADER_INS BAPIBUS2000110_HEADER_INSX than it is not updating the ACTIVITY . Msg r shown ie
-
In develop when I enable Profile corrections it shows my lens as it should. Sigam Macro 70mm. But in library under exif it says "100-300mm F4.5-5.6" Is there some way I can correct this?
-
Blank to all, they are undecided on the audio purchase between these two cards: SoundBlaster X-Fi Fatalty and the SoundBlaster X-Fi Platinum. I have read that the SB X-Fi Platinum possesses certification THX, decodes it Dts-es and Dolby FORMER Digita