Enter in Textfields

hi guys
i have two textfields and i would like to run some event if the ENTER is pressed. before i had only textfield and i was using this
    public void actionPerformed(ActionEvent e) {
        if (e.getModifiers() == 0) {
                //do something
    }but now with the extra textfield i don't know how i can distinguish between two ENTERS. any help is appreciated?

The most recommended & Clean way to do is by adding anonymous ActionListeners to both the buttons
button1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
             // Ur Logic;
        button2.addActionListener( new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                // Ur Logic;
        });

Similar Messages

  • Newbie question - Auto enter into textfield via SQL

    I am not even sure what to put for the subject!!
    I have a page that creates a new record in our leave tracking database.
    The users are logging in via LDAP
    The username is also in my employee table and can be used with a where statement
    where "USERNAME" like :APP_USER
    I want to bring in FIRSTNAME and LASTNAME and automatically put them in the form so the user does not have to.
    I tried making the TEXTFIELD source a SQL query and I can get the data to load. When the record is submitted the data is not inserted into the new record it is blank.
    The only way I can get the data to load is if the field source is set to Database Column.
    My next efforts were to try and get the default value to be inserted via a SQL statement but as there is no option for SQL only it appears that I have to put in a PL/SQL Function body or expression.
    I know that there needs to be a Declare then Begin and End but I do not know the syntax for what should be a reasonable simple query.
    the sql for the records is
    select "FIRSTNAME"
    from "NWOCASTAFF"
    where "USERNAME" like :APP_USER
    the field I am trying to insert this default value is
    P2_FIRST_NAME
    it is a Text Field
    I hope that someone can help me with this.
    A small PS
    If I wanted the text that is inserted to be Title Case how would I do that, with a format mask or is there some function like upper() which I can use.
    thanks
    John MP

    Scott
    Thanks for the code, it works perfectly! The field must be set to display as a textfield but other than that it is exactly what I need.
    there is another thread that goes down the computation route
    Query to set item default value
    I may pursue that route if I find the default value SQL query to be too restrictive.

  • Send PDF form to email address user enters in textfield on form.

    I would like to be able to allow the person using the form to choose what email address the PDF form is emailed to. I read this post which sounds like what I want but I keep getting a Submit Cancelled error. The email does get generated and the form is attached as a PDF so that part works okay.
    http://forums.adobe.com/message/4167414#4167414
    This is the code I am using as I only need the To: address populated.
    form1.Page1.Button1::preSubmit:form - (JavaScript, client)
    var strToAddress
    //Capture the values from the form fields.
    strToAddress = txtToAddress.rawValue;
    event.target.submitForm({cURL:"mailto:"+ strToAddress,cSubmitAs:"PDF",cCharset:"utf-8"});

    Hi,
    There is an example here: http://assure.ly/eUR4wJ.
    // Declare the variable
    var vEmail;
    // Check that the email field is not null
    if (txtToAddress.rawValue !== null) {
         vEmail = txtToAddress.rawValue;
    // Send email
    event.target.submitForm({cURL:"mailto: " + vEmail + "?subject=&body=",cSubmitAs:"PDF",cCharset:"utf-8"});
    Niall

  • KeyStroke Problem (except ENTER) in Textfield

    I like to activate and track within KeyLisener all keys like...Esc key, Shift-Tab key or any other key while in a Text Field .
    I have tried a lot... but failed.
    I used this code...
    txtBillNo.addKeyListener(new java.awt.event.KeyAdapter()
    public void keyPressed(KeyEvent e)
    if ( ( (e.getModifiers() == KeyEvent.SHIFT_MASK) &&
    (e.getKeyCode() == KeyEvent.VK_TAB))
    ||
    ( (e.getKeyCode() == KeyEvent.VK_ENTER)
    ||
    (e.getKeyCode() == KeyEvent.VK_TAB)))
    System.out.println("xxxxxxxxxxxxx ");

    Hi. Try this code:
    The problem is the focusmanager is handling the tab event so it never gets to the listener. If you disable the manager, then the key listener can get a crack at the event.
         public static void main(String[] args) {
              JTextField txtBillNo = new JTextField     ("adfasdfasf");
              txtBillNo.setFocusTraversalKeysEnabled(false);
              txtBillNo.addKeyListener(new java.awt.event.KeyAdapter() {
                   public void keyPressed(KeyEvent e) {
                        if ((((e.getModifiersEx() & KeyEvent.SHIFT_DOWN_MASK)
                             == KeyEvent.SHIFT_DOWN_MASK)
                             && (e.getKeyCode() == KeyEvent.VK_TAB))
                             || ((e.getKeyCode() == KeyEvent.VK_ENTER)
                                  || (e.getKeyCode() == KeyEvent.VK_TAB))) {
                             System.out.println("xxxxxxxxxxxxx ");
              JFrame frame = new JFrame();
              frame.getContentPane().add(txtBillNo);
              frame.pack();
              frame.show();
         }

  • Is there a simple way to detect a textfield value has been changed on exit?

    The filler may enter the textfield then type something and revert it back,
    any command that can simply detect a field's value has been changed on it's exit event?

    Niall,
    I was thinking if there is any simple command like xfa.event.prevText in dropdown box that I can use,
    anyway, thanks for your help.
    Rgds.

  • RE: TextField Border [Ref:C436802]

    TextGraphics do not automatically wordwrap, but the text can span multiple lines
    by using \n in the text as line breaks.
    Steve Elvin
    Systems Developer
    Frontline Ltd
    UK
    -----Original Message-----
    From: INTERNET [email protected]
    Sent: Wednesday, December 02, 1998 1:38 PM
    To: Steve Elvin; X400
    p=NET;a=CWMAIL;c=GB;DDA:RFC-822=forte-users(a)sagesoln.com;
    Subject: TextField Border [Ref:C436802]
    Hi All,
    We have a message window in our system which displays a system message to our us
    ers. If the message is not acknowledged within 1 minute, the window will automat
    ically timeout and disappear; for this reason we created our own window with a t
    imer which shuts it down. The message is placed into a TextField in the window,
    but when we converted our system to Forte v3.0 the TextField displayed with a bo
    rder around it. We tried to remove this border with no luck. We also tried chang
    ing the widget to a TextEditField but this would not allow WordWrap so most of t
    he message would disappear.
    Is there anyway to get rid of the border on the TextField or use another which t
    hat will allow WordWrap? Basically we want the window to look exactly like the F
    orte MessageDialog or QuestionDialog windows.
    Many Thanks,
    Michael Mamarot
    EMail : [email protected]
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>
    To unsubscribe, email '[email protected]' with
    'unsubscribe forte-users' as the body of the message.
    Searchable thread archive <URL:http://pinehurst.sageit.com/listarchive/>

    Well, I've determined the cause of the problem has to do with the lack of support provided by the Adobe XML Form Object Model. Every TextField encapsulates a caption object. This object has two properties, placement and reserve, that can be used to manipulate the placement of the "Caption", hence the cursor when it enters the TextField.
    The problem is that we only have one placement property per caption object. This limits the ability to specify both the height and width of the caption region. According to the XML Form Object Model 2.2, "the effect of the reserve property is determined by the placement property. When the caption is placed at the left or right, the reserve property specifies the height of the caption region. When the caption is placed at the top or bottom the reserve property specifies the width." A more ideal Object Model would specify two placement properties with corresponding reserve properties so that both the width and height can be manipulated at the same time, allowing us to squeeze the caption region within the boundary of the TextField border.
    I initially though the cursor was overlaying the TextField border but now Im convinced it is the caption object overlaying the TextField. By adjusting the reserve property of the caption object I began to see more of the underlying border changing color when the enter event fired, the problem is that I can only adjust the width or height but not both.
    I'm still trying to find a workaround so if you happen to know one please let me know.
    Alex

  • Textfield action

    Hello world,
    I have a problem with a program am writing. I want some one to input a number from 1-3 in the textfield and the button should change color.
    for example, if you enter 2 in the textfield and press enter, the number 2 button should be changed to blue. But if its blue already, it should do nothing. I have not been able to implement the actionPerformed method properly.
    Here is the code so far.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Last extends Frame implements ActionListener
        private String[] names ={"1 ","2 ","3 "};
        private Button[] buttons;
        private TextField enter;
        public Last (){
            super ("Trial");
        public static void main (String[] args){
            Last trial = new Last ();
            trial.initialize ();
            trial.setSize (250, 100);
            trial.show ();
        public void initialize (){
            Panel p = new Panel ();
            p.setLayout (new FlowLayout ());
            buttons = new Button[names.length];
            for(int i = 0; i < names.length; i++){
               buttons[i] = new Button(names);
    buttons[i].addActionListener(this);
    p.add (buttons[i]);
    enter = new TextField(9);
    enter.addActionListener(this);
    p.add(enter);
    add (p);
    public void actionPerformed (ActionEvent evt){
    // help me with this.
    String text = enter.getText();
    for(int i = 0; i < names.length; i++){
    Button button = (Button)buttons[i];
    if(button.getLabel()==text)
    button.setBackground(Color.blue);
    Thanks guys for your help.

    if(button.getLabel()==text)Don't confuse String's equals() method with the equality operator '=='. The == operator checks that two references refer to the same object. If you want to compare the contents of Strings (whether two strings contain the same character sequence), use equals(), e.g. if (str1.equals(str2))...
    Example:String s1 = "foo";
    String s2 = new String("foo");
    System.out.println("s1 == s2: " + (s1 == s2)); // false
    System.out.println("s1.equals(s2): " + (s1.equals(s2))); // true

  • Newline in textfield

    Hi everyone!
    If I press ENTER while editing textfield a newline is inserted. How can I change ENTER on something else, for example CONTROL+ENTER or SHIFT+ENTER(i.e. SHIFT+ENTER inserts new line into textfield)

    I'm sorry, but I just created an air app to see if that's really like you say.
    if you use a textarea you can press enter and you get a new line without pressing any other keys.
    At the end this doesn't matter. This should at least prevent the default behaviour of pressing the ENTER key:
    textfield.addEventListener(KeyboardEvent.KEY_UP, keyHandler); 
    private function keyHandler(event:KeyboardEvent):void
           if( event.type == KeyboardEvent.KEY_UP && event.keyCode == Keyboard.ENTER )
                     event.target.text = event.target.text.replace( "\r", "" );

  • Displaying value only in Drop Down List

    Greetings,
    I have a drop down list with value:text as follows:
    01:Daylight
    02:Dusk
    03:Dawn
    04:Night
    I would like to present the user who clicks on the drop down list with all of the literal text options (daylight, night, etc), but once selected, the object populate and print only the value (01, 02, etc).
    I thought about resizing the object when the user clicks on it, and then resizing it back once selected, but this seems rather cumbersome.  Space on the printed form is very limited, which is why the value/codes are used to represent the actual literal options.
    Any methods or ideas would be greatly welcome
    Thanks!
    Brad

    Here is a sample that shows what I think you want. I have a TextField that is displayed. When the user enters the field, I hide this field and make a DDlist available to the user. This DDList is placed behind the TextField and is hidden (not part of the layout) until the user enters the TextField. I also hide the TextField (this code is on the Enter event of the TextField). Now that the DDlist is visible you can set up a DDList to display one thing but report another. This is what I did (look at the binding tab of the DDList). Now when the user selects an item from the DDList the TextField is updated, the DDList is hidden and the TextField is made visisble, then the cursor is placed in the next field. This code is on the Exit event of the DDList.
    Is this what you were trying to accomplish?
    Paul

  • New to Java. Want to write a simple applet for a mobile phone.

    Hello,
    I want to write a simple java applet for a mobile phone. currently I am in the stage of thinking about whether this is possible in a timeframe of about a month. I have very little java experience from a while back so I'm pretty much starting from scratch.
    All I want is an applet that lets you send 2 or 3 variables to an online server. The server will then reposition telescopes.
    All i'm concerned with is the mobile phone part, which doesn't have to be secure or impressive. Just a simple interface.
    Ideally it should work on my nokia 6070, which occording to the official specs has the following java technology:
    MIDP 2.0
    CLDC 1.1
    JSR 120 Wireless Messaging API
    JSR 135 Mobile Media API
    Nokia UI API
    (I don't know what any of this means but am a good learner).
    Can anyone offer me any advice? Is this possible in my timeframe? where should I start? I need a editor and compiler also (I'm using windows XP).
    Many thanks and kind regards,
    Jason

    Actually it is working on my phone now.
    I changed the target platform in the wireless toolkit settings to MIDP 1.0
    Now to create the fields coordinate fields etc. I don't have much of a clue really.
    Current I have:
    import java.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    public class AtmosMIDlet extends MIDlet implements CommandListener
    Form WelcomeForm = new Form("AtmosMIDlet");
    StringItem WelcomeMes = new StringItem(null, "Please enter coordinates:");
    TextField Longitude = new TextField("Longitude", "", 3, TextField.NUMERIC);
    TextField Lattitude = new TextField("Lattitude", "", 3, TextField.NUMERIC);
    public AtmosMIDlet()
    try
    ImageItem logo = new ImageItem(Image.createImage("/logo.png"));
    WelcomeForm.append(logo);
    catch (java.io.IOException x)
    throw new RuntimeException ("Image not found");
    WelcomeForm.append(WelcomeMes);
    WelcomeForm.append(Longitude);
    WelcomeForm.append(Lattitude);
    WelcomeForm.addCommand(new Command("Exit", Command.EXIT, 0));
    WelcomeForm.setCommandListener(this);
    public void startApp()
    Display.getDisplay(this).setCurrent(WelcomeForm);
    public void pauseApp() {}
    public void destroyApp(boolean unconditional) {}
    public void commandAction(Command c, Displayable s)
    notifyDestroyed();
    I'm trying to get the image logo.png to display at the top but I get the error:
    C:\WTK25\apps\AtmosSpec\src\AtmosMIDlet.java:19: cannot find symbol
    symbol : constructor ImageItem(javax.microedition.lcdui.Image)
    location: class javax.microedition.lcdui.ImageItem
    ImageItem logo = new ImageItem(Image.createImage("/logo.png"));
    ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    Build failed
    When I try to build.. Any help would be great.
    Ideally the image would be on a seperate screen for a couple of seconds.

  • Calculation problem. pls help

    hi all, i am really very new to Java programming.
    And really got stuck with this program. I am not asking or expecting anybody to help me to do my assigment.
    This I understand.
    But how to add in the calculation part. I am really stuck.
    Request:
    Proctor and Gambol is a manufacturing organization. It has many plants and machineries, which run right around the clock. It has a work force of 200 production operators. The operators are paid based on the ?hourly rate?. Most of them work on shifts; there are three shifts to fit in the operators. Each shift has different rate of payment and rate differs on the grades of employee.
    Any employee working for more than 45 hours are paid based on an overtime rate.
    Analysis of the Request:
    To development a Java program to calculate the payment for employees based on the following factors:
    1. Grade of employees (senior, junior, new and temporary.)
    2. Shift worked (hourly rate for shift 1,2 and 3)
    3. Working hrs.
    4. Overtime rate (if total hrs worked in a week > 45hrs)
    Data to be input for calculation:
    1. Employee number (0 to 200)
    2. Grade of Employee (S,J,N or T)
    3. Shift number (1,2 or 3)
    4. Hours worked (>45 hrs are based on overtime rate)
    Data or Information required for calculation:
    1. Employee grade (S/J/N/T)
    2. Employee shift levels (1/2/3)
    3. Normal shift rate
    4. Overtime shift rate (>45 hrs per week = 1.5 times Normal shift rate)
    5. Standard working hours at 0 to 45 hours per week
    6. Maximum working hours at 99 hours per week
    Expected Output of the program:
    1. Employee number
    2. Employee grade
    3. Shift worked
    4. Total hours worked in the week
    5. Wage payable
    6. Options to Continue another query or Quit the program.
    Design:
    Calculation of the wage payable is as follows:
    Normal Wage = 45 hrs @ normal rate, based on Grade and shift worked.
    Overtime Wage = (Total hours worked ? 45 hrs) * normal rate, based on Grade and shift
    Worked.
    Brief flow of the program is as follow:
    1. Start of the program.
    2. Enter the Employee number. (001 to 200, with a max of 999)
    3. Enter the Grade of Employee.
    4. Enter the Shift worked.
    5. Enter the Total hours worked.
    6. Program will then calculate Wages payable based on Grade of employee, shift worked and total hours worked per week.
    7. Program will display the Wage payable on screen.
    8. Program will then provide options for user to Continue or to Quit.
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.util.*;
    public class Testprogram extends Applet implements ActionListener
    Label screena = new Label (" Proctor and Gambol Co Ltd");
    Label screenb = new Label (" ");
    Label screen1 = new Label ("Enter Employee Number");
    TextField empnum = new TextField(1);
    Label screenc = new Label (" ");
    Label screen2 = new Label ("Click on Employee's Grade");
    Button Senior = new Button("Senior");
    Button Junior = new Button("Junior");
    Button New = new Button("New");
    Button Temporary = new Button("Temporary");
    Label screen3 = new Label ("Click on Shift Number");
    Button Shift1 = new Button("1");
    Button Shift2 = new Button("2");
    Button Shift3 = new Button("3");
    Label screen4 = new Label ("Enter hour worked");
    TextField hours = new TextField(1);
    Label screen5 = new Label ("Enter rate");
    TextField rate = new TextField(1);
    TextField grossPay = new TextField(10);
    Button WagePayable = new Button("Wage Payable");
    public void init()
    add(screena);
    add(screenb);
    add(screen1);
    add(empnum);
    add(screenc);
    add(screen2);
    add(Senior);
    add(Junior);
    add(New);
    add(Temporary);
    add(screen3);
    add(Shift1);
    add(Shift2);
    add(Shift3);
    add(screen4);
    add(hours);
    add(screen5);
    add (rate);
    add(grossPay);
    add(WagePayable);
    WagePayable.addActionListener(this);
    Senior.addActionListener(this);
    public void actionPerformed(ActionEvent e)
    if(e.getSource()==Senior)
    double x = Double.valueOf(rate.getText
    ()).doubleValue();
    double y = Double.valueOf(hours.getText
    ()).doubleValue();
    double gross = x + y;
    grossPay.setText(""+gross);

    Hello,
    Model each employee as an object - and thus you need a class Employee to initialize these, for example (please note that I have not tested it - nor compiled it):
    * This class represents an employee.
    public class Employee{
       private int employeeNumber;
       private String employeeGrade;
       private int shiftNumber;
       public Employee( int e, String g, int s){
          employeeNumber = e;
          employeeGrade = g;
          employeeShiftNumber = s;
       public int getNumber( ){
          return employeeNumber;
       public String getGrade( ){
          return employeeGrade;
       public int getShift( ){
          return employeeSiftNumber;
    }Now you can write a small test program (this is just the method which calculates the pay and not the whole program). The method is below:
    * This method calculates the pay for an employee.
    public void paymentDue( Employee e, int hoursWorked){
       double payRate = 0.00;
       double pay = 0.00;
       double overTime = 0.00;
        * Obtain the payRate for this employee.
       if( e.getGrade( ) == t) payRate = 1.00;
       else if( e.getGrade( ) == n) payRate = 2.00;
       else if( e.getGrade( ) == j) payRate = 3.00;
       else if( e.getGrade( ) == s) payRate = 4.00;
        * Obtain the shift for this employee.
       if( e.getShift( ) == 1) payRate = payRate + 0.50;
       else if( e.getShift( ) == 2) payRate = payRate + 1.00;
       else if( e.getShift( ) == 3) payRate = payRate + 1.50;
        * Calculate the pay for this employee.
       if( hoursWorked <= 45)
           pay = hoursWorked * payRate;
       else{
           overTime = ( hoursWorked - 45) * ( payRate * 1.5);
           pay = 45 * payRate + overTime;
        * Print out the information for this employee.
       System.out.prinln( "Employee number: " + e.getNumber( ));
       System.out.prinln( "Employee grade: " + e.getGrade( ));
       System.out.prinln( "Shift worked: " + e.getShift( ));
       System.out.prinln( "Hours worked: " + hoursWorked);
       System.out.prinln( "Wage payable: " + pay);
    }This method can be called for example, with the call:
    paymentDue( new Employee( 20, j, 1), 47);I hope this helps - please ask if you need any more points.
    Best regards
    -marek.

  • Filter on report

    I have a report with several text fields. I would like to search by just one of those fields, whether the other fields are filled in or not.
    So for example, when textfield A is not null then I want to ignore whats entered in textfield B,textfield C, and textfield d and serach by just textfield A. Else if textfield A is null, then search by the other three textfields.
    Deanna

    Sorry, I really didnt have much for means of a query. All i really had was:
    begin
    -- setup sql for report source
    q := 'select * from
    (select
    "RECNUM",
    "CASE_NUMBER",
    "PURSUIT_DATE",
    "PURSUIT_TIME_BEGAN",
    "OFFICER_TROOP",
    "OFFICER_ZONE",
    "OFFICER_RADIO",
    "OFFICER_LNAME",
    "OFFICER_FNAME",
    "OFFICER_MI",
    "OFFICER_YEARS_SERVICE",
    "DURATION_MILES",
    "DURATION_MINUTES",
    "SPEED_MAX",
    "ACCIDENT",
    "ACCIDENT_TYPE",
    "REASON_FOR_INITIATION",
    "REASON_FOR_TERMINATION",
    "REASON_FOR_FLIGHT"
    from "PURSUIT")
    WHERE(
    instr(upper("RECNUM"),upper(nvl(:P6_REPORT_SEARCH,"RECNUM"))) > 0  or
    instr(upper("CASE_NUMBER"),upper(nvl(:P6_REPORT_SEARCH,"CASE_NUMBER"))) > 0  or
    instr(upper("PURSUIT_DATE"),upper(nvl(:P6_REPORT_SEARCH,"PURSUIT_DATE"))) > 0  or
    instr(upper("PURSUIT_TIME_BEGAN"),upper(nvl(:P6_REPORT_SEARCH,"PURSUIT_TIME_BEGAN"))) > 0  or
    instr(upper("OFFICER_TROOP"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_TROOP"))) > 0  or
    instr(upper("OFFICER_ZONE"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_ZONE"))) > 0  or
    instr(upper("OFFICER_RADIO"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_RADIO"))) > 0  or
    instr(upper("OFFICER_LNAME"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_LNAME"))) > 0  or
    instr(upper("OFFICER_FNAME"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_FNAME"))) > 0  or
    instr(upper("OFFICER_MI"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_MI"))) > 0  or
    instr(upper("OFFICER_YEARS_SERVICE"),upper(nvl(:P6_REPORT_SEARCH,"OFFICER_YEARS_SERVICE"))) > 0  or
    instr(upper("DURATION_MILES"),upper(nvl(:P6_REPORT_SEARCH,"DURATION_MILES"))) > 0  or
    instr(upper("DURATION_MINUTES"),upper(nvl(:P6_REPORT_SEARCH,"DURATION_MINUTES"))) > 0  or
    instr(upper("SPEED_MAX"),upper(nvl(:P6_REPORT_SEARCH,"SPEED_MAX"))) > 0  or
    instr(upper("ACCIDENT"),upper(nvl(:P6_REPORT_SEARCH,"ACCIDENT"))) > 0  or
    instr(upper("ACCIDENT_TYPE"),upper(nvl(:P6_REPORT_SEARCH,"ACCIDENT_TYPE"))) > 0  or
    instr(upper("REASON_FOR_INITIATION"),upper(nvl(:P6_REPORT_SEARCH,"REASON_FOR_INITIATION"))) > 0  or
    instr(upper("REASON_FOR_TERMINATION"),upper(nvl(:P6_REPORT_SEARCH,"REASON_FOR_TERMINATION"))) > 0 or
    instr(upper("REASON_FOR_FLIGHT"),upper(nvl(:P6_REPORT_SEARCH,"REASON_FOR_FLIGHT"))) > 0) ';
    *--Filter Case Number*
             *if :p6_case_number is not null then*
                   *q :=q || ' and instr(upper("CASE_NUMBER"),upper(nvl(:P6_CASE_NUMBER,"CASE_NUMBER")))> 0';*
            *END IF;*

  • Use of servlet http tunneling for client server communication

    Hello I am having a problem connecting a simple client applet to a server application. I can connect the two directly using sockets. However, when I try to connect the two via a servlet the input stream cannot be accessed. The application is purely for demonstration. Here is some of the source code
    A servlet for http tunneling
    import java.io.*;
    import java.net.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class SocketServlet extends HttpServlet
         ServletInputStream servletinput;
         ServletOutputStream servletoutput;
         Socket socket;
         DataOutputStream dataoutput;
         DataInputStream datainput;     
         public SocketServlet()
    public void init(ServletConfig servletconfig) throws ServletException
    super.init(servletconfig);
    log("Socket servlet initialized.");
         public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException
    try
    servletinput = request.getInputStream();
    socket = new Socket( InetAddress.getByName( "127.0.0.1" ), 5000 );
    dataoutput = new DataOutputStream( socket.getOutputStream() );
    try
                        byte[] inbytes = new byte[1024];
                        servletinput.read( inbytes );
                        String inmessage = new String( inbytes );                    
                        dataoutput.writeBytes( inmessage );
    catch(IOException ioex)
    dataoutput.flush();
    datainput = new DataInputStream( socket.getInputStream() );
    servletoutput = response.getOutputStream();
    try
    byte[] outbytes = new byte[1024];
    datainput.read( outbytes );
    servletoutput.write( outbytes );
    catch(IOException ioex)
    servletoutput.flush();
    servletoutput.close();
    catch(Exception ex)
    // Server.java
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Server extends JFrame {
    private JTextField enter;
    private JTextArea display;
    DataOutputStream output;
    DataInputStream input;
    public Server()
    super( "Server" );
    Container c = getContentPane();
         enter = new JTextField();
         enter.setEnabled( false );
         c.add( enter, BorderLayout.SOUTH );
    display = new JTextArea();
    c.add( new JScrollPane( display ),
    BorderLayout.CENTER );
    setSize( 300, 150 );
    show();
    public void runServer()
    ServerSocket server;
    Socket connection;
    int counter = 1;
    try {
    // Step 1: Create a ServerSocket.
    server = new ServerSocket( 5000, 100 );
    while ( true ) {
    // Step 2: Wait for a connection.
    display.setText( "Waiting for connection\n" );
    connection = server.accept();
    display.append( "Connection " + counter +
    " received from: " +
    connection.getInetAddress().getHostName() );
    // Step 3: Get input and output streams.
    output = new DataOutputStream(
    connection.getOutputStream() );
    input = new DataInputStream(
    connection.getInputStream() );
    display.append( "\nGot I/O streams\n" );
    // Step 4: Process connection.
    String message =
    "SERVER>>> Connection successful";
    output.writeBytes( message );
    enter.setEnabled( true );
                   display.append( "\nConnected\n" );
    do {
    try {
                        byte[] mess = new byte[1024];
    input.read( mess );
    display.append( "\n" + message );
    display.setCaretPosition(
    display.getText().length() );
                   catch (IOException ioex )
    } while ( !message.equals( "CLIENT>>> TERMINATE" ) );
    // Step 5: Close connection.
    display.append( "\nUser terminated connection" );
    enter.setEnabled( false );
    output.close();
    input.close();
    connection.close();
    ++counter;
    catch ( EOFException eof ) {
    System.out.println( "Client terminated connection" );
    catch ( IOException io ) {
    io.printStackTrace();
    private void sendData( String s )
    try {
    output.writeBytes( "SERVER>>> " + s );
    display.append( "\nSERVER>>>" + s );
    catch ( IOException cnfex ) {
    display.append(
    "\nError writing object" );
    public static void main( String args[] )
    Server app = new Server();
    app.addWindowListener(
    new WindowAdapter() {
    public void windowClosing( WindowEvent e )
    System.exit( 0 );
    app.runServer();
    // Fig. 21.4: Client.java
    // Set up a Client that will read information sent
    // from a Server and display the information.
    import java.io.*;
    import java.net.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.zip.*;
    public class Client extends Applet implements ActionListener {
    private TextField enter;
    private TextArea display;
    DataOutputStream output;
    DataInputStream input;
    private Button button, button2;
    URLConnection connection;
    private byte[] bytes1, bytes2;
    private String message, message2;
    public void init()
    setLayout( new BorderLayout() );
    enter = new TextField( " Enter text here " );
    enter.setEnabled( false );
    enter.addActionListener( this );
    add( enter, BorderLayout.NORTH );
    display = new TextArea( 4, 30 );
         display.setEditable( false );
    add( display, BorderLayout.CENTER );
         button = new Button( "Connect" );
         button.addActionListener( this );
         add( button, BorderLayout.SOUTH );
    public void runClient()
    Socket client;
    try {
    // Step 1: Create a Socket to make connection.
    display.setText( "Attempting connection\n" );
              URL currentpage = getCodeBase();
              String protocol = currentpage.getProtocol();
              String host = currentpage.getHost();
              int port = 8100;
              String urlsuffix = "/servlet/SocketServlet";
              URL dataurl = new URL( "http://localhost:8100/servlet/SocketServlet" );
              connection = dataurl.openConnection();
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Content-type", "application/octet-stream");
              connection.setUseCaches( false );
              display.append( "\nConnected to: " + host );          
    // Step 2: Get the output streams.
    output = new DataOutputStream(
    connection.getOutputStream() );
              display.append( "\n got output stream\n" );
              // Step 3 get input connection
              try
              display.append( "\nAttempting to connect to input stream\n" );
                   input = new DataInputStream( connection.getInputStream() );
                   bytes1 = new byte[1024];
                   input.readFully( bytes1 );
                   display.append( "\nGot input stream\n" );
                   message = new String( bytes1 );
                   display.append( "\n" + message + "\n" );          
              catch ( IOException ioex )
              // Step 3: Process connection.
              enter.setEnabled( true );
              do {
              try {
    bytes2 = new byte[1024];
              input.readFully( bytes2 );
              message2 = new String( bytes2 );
              display.append( "\n" + message2 );
              display.setCaretPosition(
              display.getText().length() );
              catch ( IOException ioex ) {
              display.append(
              "\nUnknown object type received" );
              } while ( !message.equals( "SERVER>>> TERMINATE" ) );
    // Step 4: Close connection.
    display.append( "Closing connection.\n" );
    output.close();
    input.close();
         catch (MalformedURLException mfe )
    catch ( EOFException eof ) {
    System.out.println( "Server terminated connection" );
    catch ( IOException e ) {
    e.printStackTrace();
    private void sendData( String s )
    try {
    message = s;
    output.writeBytes( "CLIENT>>> " + s );
    display.append( "\nCLIENT>>>" + s );
    catch ( IOException cnfex ) {
    display.append(
    "\nError writing object" );
    public void actionPerformed( ActionEvent e )
         if ( e.getActionCommand() == "Connect" )
              runClient();
         else
              sendData( e.getActionCommand() );
    public static void main(String args[])
    Frame f = new Frame("Chat Client");
         Client c = new Client();
         c.init();
         f.add("Center", c);
         f.setSize(300, 150);
         f.show();
    the connection appears to fail at client step 3, any help is super, thanks
    Aidan

    Hi,
    In your client you are trying to open OutputStream even though you are not using it.
    So there are two solutions here.
    1. If you dont need OutputStream your code shoud look like this
    try {
    // Step 1: Create a Socket to make connection.
    display.setText( "Attempting connection\n" );
    URL currentpage = getCodeBase();
    String protocol = currentpage.getProtocol();
    String host = currentpage.getHost();
    int port = 8100;
    String urlsuffix = "/servlet/SocketServlet";
    URL dataurl = new URL( "http://localhost:8100/servlet/SocketServlet" );
    connection = dataurl.openConnection();
    //connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Content-type", "application/octet-stream");
    connection.setUseCaches( false );
    display.append( "\nConnected to: " + host );
    // Step 2: Get the output streams.
    //output = new DataOutputStream(
    //connection.getOutputStream() );
    //display.append( "\n got output stream\n" );
    display.append( "\n Not interested in output stream\n" );
    //Step 3 Inpustream related
    // Step 4: Close connection.
    display.append( "Closing connection.\n" );
    //output.close();
    input.close();
    1. If you need OutputStream, close your OutputStream before even trying to get InputStream, your code should like this
    try {
    // Step 1: Create a Socket to make connection.
    display.setText( "Attempting connection\n" );
    URL currentpage = getCodeBase();
    String protocol = currentpage.getProtocol();
    String host = currentpage.getHost();
    int port = 8100;
    String urlsuffix = "/servlet/SocketServlet";
    URL dataurl = new URL( "http://localhost:8100/servlet/SocketServlet" );
    connection = dataurl.openConnection();
    //connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Content-type", "application/octet-stream");
    connection.setUseCaches( false );
    display.append( "\nConnected to: " + host );
    // Step 2: Get the output streams.
    output = new DataOutputStream(
    connection.getOutputStream() );
    display.append( "\n got output stream\n" );
    //I'll do whateve I've to do with outputstream
    //done with output stream closing
    output.close();
    //Step 3 Inpustream related
    // Step 4: Close connection.
    display.append( "Closing connection.\n" );
    //output.close();
    input.close();
    hope this works
    all the best,
    Raj

  • How to make my program work using 2 files separately?

    My main file is ExpenseTracker.java. When u
    compile the ExpenseTracker.java , there is a column of buttons on the left
    and a right box. I would like to make the output of the RecordMenu.java
    appear(not pop out) in the right box of my ExoenseTracker when i click one
    of the button 'Record Expenses'. I wonder you can help me in this? I am
    facing that problem right now.=======================================================================
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    public class ExpenseTracker extends JFrame {
    public ExpenseTracker() {
    super("Expense Tracker");
    // FirstPanel
    JPanel FirstPanel = new JPanel();
    FirstPanel.setLayout(null);
    JLabel labeltracker = new JLabel("Expense Tracker");
    JButton recordExpenses = new JButton("Record Expenses");
    JButton viewExpenses = new JButton("View Expenses");
    JButton calendar = new JButton("Calendar" );
    JButton exit = new JButton("Exit");
    labeltracker.setBounds(40,120,135,30);
    recordExpenses.setBounds(25,160,135,30);
    viewExpenses.setBounds(25,210,135,30);
    calendar.setBounds(25,260,135,30);
    exit.setBounds(25,310,135,30);
    FirstPanel.setBounds(5,5,200,500);
    FirstPanel.add(labeltracker);
    FirstPanel.add(recordExpenses);
    FirstPanel.add(viewExpenses);
    FirstPanel.add(calendar);
    FirstPanel.add(exit);
    //SecondPanel
    JPanel SecondPanel = new JPanel();
    SecondPanel.setLayout(new BorderLayout(1,2));
    // SecondPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
    SecondPanel.setBorder(new LineBorder(Color.black));
    SecondPanel.setBounds(210,120,530,270);
    getContentPane().setLayout(null);
    getContentPane().add(FirstPanel);
    getContentPane().add(SecondPanel);
    setSize(800,500);
    setVisible(true);
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    public static void main(String [] args) {
    new ExpenseTracker();
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    public class RecordMenu extends JFrame implements ItemListener,ActionListener {
    >>
    JCheckBox weekly;
    JCheckBox monthly;
    public RecordMenu() {
    super("Choose");
    Container c = getContentPane();
    JPanel checkPanel = new JPanel();
    checkPanel.setLayout(new GridLayout(4,2));
    checkPanel.setBorder(new TitledBorder("Record Expenses"));
    JLabel label2 = new JLabel("Amount to track:");
    JTextField amtField = new JTextField(5);
    //Create the check boxes.
    weekly = new JCheckBox("Weekly");
    weekly.setSelected(false);
    monthly = new JCheckBox("Monthly");
    monthly.setSelected(false);
    //Register a listener for the check boxes.
    weekly.addItemListener(this);
    monthly.addItemListener(this);
    amtField.addActionListener(this);
    //Put the check boxes in a column in a panel
    checkPanel.add(weekly,BorderLayout.NORTH);
    checkPanel.add(monthly,BorderLayout.SOUTH);
    checkPanel.add(label2);
    checkPanel.add(amtField);
    JPanel buttonPanel = new JPanel();
    JButton buttonOk = new JButton("OK");
    JButton buttonCancel = new JButton("Cancel");
    buttonPanel.add(buttonOk);
    buttonPanel.add(buttonCancel);
    c.add(checkPanel,BorderLayout.NORTH);
    c.add(buttonPanel);
    setSize(370,200);
    setVisible(true);
    /** Listens to the check boxes. */
    public void itemStateChanged(ItemEvent event) {
    public static void main(String[] args) {
    new RecordMenu();

    but i wan e program to work wit 2 file, not all e 2 file codes put together in a file. I wonder if can call e code from the recordmenu file when i execute the expenseTracker file. I not sure i explain this way u will understand?
    When the record menu 'ok' is clicked there will b a JOptionpane tat will pop out saying
    'Total amt to b tracked on a weekly basis is (amt entered in textfield)"
    if e checkbox is selected weekly, the output will be like e above
    otherwise it will display 'Total amt to b tracked on a monthly basis is (amt entered in textfield)".
    ya e textfield input must be numbers.

  • About DDl and Dml Operations On B1

    Hi ,
    I had Created A form In SDk Using UiAPI, It Contains Five Text Fields And One Button. And I had Created An EMP Table.It Contains Five Fileds. My Question Is:----
    >
    When I clicked Button , The data Entered In TextFields(EditText) Need To stored in Database.  Similirly All The Operation Need To Do. How Can we Do In sdk. Please tell Me code
    Regards
    Srinivas

    Srinivas,
    Please look at the subject of "Binding Items to Data SourcesBinding Items to Data Sources" in the SAP Business One SDK Help Center Documentation.  This should assist you and show you code samples.
    Eddy

Maybe you are looking for