Using a Document Listener to update a text field
Hi,
Background:
I need to retrieve a number from a card using a hand scanner. I'm currently using a jTextField1 in Netbeans to do this. When the number is input (the format is 6 digits, i.e. 123456) the rest of the form fields are filled in and updated automatically from an oracle database as it should. I have the database being checked as soon as the field reaches 6 characters (doc.getLength() == 6), It all works great.
Problem:
The problem comes in when I need to input a card that has a newer, different format of numbers and characters, i.e. **001234567**, it's more than 6 characters. I need only the 123456 substring to update the form, and the 7 substring to input later.
What I tried:
I'm using the combination of pattern matching and substring to get the 1234567 part only. I thought of using a hidden field on the form to input the numbers to and then set the text of jTextField1. I'm not sure this would work and seems like a hack anyways.
Code:
public void updateLog(DocumentEvent e, String action) {
Document doc = (Document) e.getDocument();
Integer docLength = doc.getLength();
String isCardLegal = jTextField1.getText(); // getting card from textbox
returnString Del = new returnString();
String str = Del.getNewNumberFromCard(isCardLegal);
System.out.println("str: " +str);
if (docLength == 6) {
// see if number exists in database here
public class returnString {
public String getNewNumberFromCard(String oldString) {
Pattern p = Pattern.compile("\\*");
Matcher m = p.matcher(oldString);
String newString = m.replaceAll("");
// takes off leading zeros when using a new card
// otherwise just returns the string as-is
if (newString.length() == 9) {
newString = newString.substring(2);
return newString;
} else {
return newString;
}Does anyone have a better way to do this? I hope I was clear in my explanation.
Thank You for your help,
Alan
Edited by: shadow_coder on Oct 8, 2009 12:01 PM
I really thank you for your help, I realize I wasn't clear because I wasn't sure about too many different things. I'll try it again:
I need to use a hand scanner to input id cards having 2 different character sets. I now realize I can have the scanner insert a carriage return at the end of the scan, so I need to be able to detect this carriage return. I'm using a documentlistener to look at each character in the textfield. The character sets I need to use are 6 characters long, and an 11 character long set (including asterisks).
Here is my SSCCE:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
public class exampleCase extends JFrame implements ActionListener {
JTextField textField1;
public exampleCase() {
getContentPane().setLayout(new FlowLayout());
textField1 = new JTextField(15);
textField1.getDocument().addDocumentListener(new MyDocumentListener());
textField1.getDocument().putProperty("name", "TextField");
getContentPane().add(textField1);
setSize(300, 170);
setVisible(true);
public static void main(String argv[]) {
new exampleCase();
public void actionPerformed(ActionEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
class MyDocumentListener implements DocumentListener {
public void insertUpdate(DocumentEvent e) {
updateLog(e, "inserted into ");
public void removeUpdate(DocumentEvent e) {
updateLog(e, "removed from ");
public void changedUpdate(DocumentEvent e) {
throw new UnsupportedOperationException("Not supported yet.");
public void updateLog(DocumentEvent e, String action) {
String newline = "\n";
Document doc = (Document) e.getDocument();
int changeLength = e.getLength();
System.out.println(
changeLength +" character"+
((changeLength == 1) ? " " : "s ")
action+ doc.getProperty("name") +"."+ newline
" Text length = "+ doc.getLength() +newline);
try {
String docCharacters = doc.getText(0, 2); // Exception when increased
System.out.println("Characters are: "+ docCharacters);
if (docCharacters.equals("\\r")) { // How to check for carriage return?
System.out.println("I'm Here, Yeeaaah!!");
} catch (BadLocationException ex) {
System.out.println("Error Here, bad location" + ex);
}When I increase the '2' to be able to handle the characters, I get javax.swing.text.BadLocationException: Invalid location can anyone tell me why? I'm not sure why it works when the number is at 2 but not others!
The other issue is, what is the correct way to detect a carriage return? I was able to test this when the number above was at 2. This doesn't work.
Similar Messages
-
Hello
I currently have a project where the client has requested to have the ability to update the text fields inside the project at a later date.
This is due to the nature of the content changing rather rapidly, i would like to set this up so the client can manage this them selfs.
What would the best way to do this be?
I'm thinking XML, an external XML sheet were by Captivate imports the text from this XML sheet and then displays it within the specific text fields contained within the captivate output.
This way the client would just update the external XML document(cut and paste the text in) and then the text would be dynamically updated in the published Captivate document.
any help would be amazing !
Thanks in advance
NickHi Lieve
But isn't this thread more about an end user having an ability to change text after the Captivate has been published and delivered? I could see where that might be useful if making changes then publishing to create a new output. But I'm interpreting that the situation here is that a Captivate project has been published and delivered, and some mechanism is desired that allows the recipient to modify an external XML file to influence changes in the already compiled Captivate output.
Cheers... Rick -
Update a text field based on a SelectOneChoice field
Hi,
I have a set of Create, Confirm and Thankyou screens. These screens are bound to a global view object. The create screen has a SelectOneChoice element which allows the user to pick an employee. When the selection is made, I need to display the employee's department in a read only text field below the dropdown. The Employees list(SelectOneChoice) is associated to the read only view object and this view object also has the employee's department information. Im dont know how to set the department name in the text field and refresh the screen. Any help is appreciated. Thank You.Frank, thanks for you time. Please see my answers below.
Hi,
can you help me creating a reproducable testcase
based on the HR schema where we have a Departments
and Employees tables. To understand your usecase I
have some questions:
Im not too familiar with HR Schema.
>
First of all however, what is a "global view object",
and is it safe to assume you are using ADF Business
Components?
Its the "Globals View Object" as described in the SRDemo for creating a new Service Request and yes I am using ADF Business Components.
>
Which version of Oracle JDeveloper do you use ?
10.1.3
>
The usecase I understand is that you have a
selectOneChoiceList that whenever you select a new
name should update a read-only text field with the
department name. Is this correct ? Or is there more
in it ?
Heres the complete description. There are 4 fields on the screen
1. Program Name (text input field, - required field)
2. Program Category (SelectOneChoice field - required field)
3. Employee Name (SelectOneChoice field - required field)
4. Employee Department (Text output field - based on 3 above)
What you have described above is working for me now, but everytime I select a value for 3, it does the required fields check and gives a message like "1 & 2 are required and a value must be entered", this validation should only occur when my continue button is clicked.
>
The department name should be displayed only (read
only), or is it also bound to what you call "global
view"?
Yes its read only but I need to bind to the Globals view as I need to display it in the confirmation screen.
>
Also, just to be sure, is the department name part of
the VO or is it the departmentId?
The screen is bound to the Globals View, the selectOneChoice values are displayed from another view(EmployeeList view) which has the department name.
>
Frank -
I am working on an iBooks Author Widget and want to allow the user to switch between drawing-pad functions and a text field on screen. I'd like to create an action that will automatically re-order the layers so that the text field is accessible when typing but covered when writing by hand. Then, I'd like the opposite to be available, so that the text field is accessible when typing, but the drawing pad is left alone.
Have you tried using the selections in the Encore menu viewer that show you selected and activated states?
-
Use 2 different fonts in a dynamic text field with tf.htmlText?
i've got a dynamic text field on the screen and all of my
fonts embedded. is it possible to use 2 different fonts when
dynamically setting the fields text with the htmlText property?
i've tried the <font> and the <textformat> tags and
neither work. I can set it once via a texformat object, but that's
it.
thanksyou're answering all of my questions today aren't you? :)
right, i think this will be hard since my data is all comming
from XML and i have no way to specifically set text ranges as
different fonts within a string.
i've told the developers to just use images for the special
characters. -
Using a button to check an input text field
I am an educator and I am designing an interactive activity for my students. I created two buttons named button_B and button_G, and an input textfield named in_Text. When a student presses button_B, the letter "B" is entered into the input text field; if a student presses button_G, the letter "G" is entered into the input text field. More than one letter entry is acceptable as a student's answer: for exmple the entry BBB, BGB within the input field is okay. I have no trouble writing AS3 to accomplish this task, however:
For a student's solution to the input text field to be correct, it has to contain the four values BBB, GGG, BGB, and GBG in any order. I created an array named solution_S with these values. I also have an enter the solution button named enter_btn. The student can check their solution by pressing the enter_btn button; if the input textfield is correct, the quiz moves on to the next frame in my timeline; if it is incorrect, it moves to a different frame in my timeline. How would I enter this actionscript to accomplish this? Thanks much!var check:Boolean=false;
for(var i:uint=0;i<solution_S.length;i++)
if( solution_S[i].toString()==in_Text.Text)
check=true;}
if(check)
gotoAndStop(...);
else
gotoAndStop(...); -
Auto update of text field on drop down change (binded to XML doc)
Hi all,
I have a problem that i'm stuck with since too long and I'll be really grateful for any useful idea.
Here is my issue:
I have this XML:
<?xml version="1.0" encoding="UTF-8"?>
<ItemsList>
<Product>
<itemUnitPrice>200.00000000</itemUnitPrice>
<itemCode>lkg</itemCode>
<ItemID>2</ItemID>
<itemDescription>lk desc</itemDescription>
</Product>
<Product>
<itemUnitPrice>300.00000000</itemUnitPrice>
<itemCode>lkv</itemCode>
<ItemID>1</ItemID>
<itemDescription>lkv desc</itemDescription>
</Product>
<Product>
<itemUnitPrice>400.00000000</itemUnitPrice>
<itemCode>lks</itemCode>
<ItemID>3</ItemID>
<itemDescription>lks desc</itemDescription>
</Product>
</ItemsList>
ItemID and itemCode are bounded to my dd list and the left is bounded to the rest of the columns in my table (below).
I`d like to find a way to auto change, for example the unit price, of an item selected from the list.
I have to mention that this xml is returned by a database and data can change so i can`t write javascript static code to match itemId with their Unitprice and description.
Any ideas ??
Thanks in advance.Hi,
yes this is possible.
Add this script to the change event of your dropw down list.
Text1.value.text.value = xfa.event.change; -
In Posted Document How to Update Business Area Field ?
Hello peers,
I am training to update Business area in some of my line items, for example when i have posted a doc in MIRO it has not updated in my TAX a/C's. Now i want to update the same. So i tried doing the F.5D and F.5E, but it's saying
Nothing was selected
Message no. FR333
In one of the threads i read in OB65 business area has to deactivate, then post, and then activate the same to do F.5D. but it is activated before posting the documents.
What should i do now. and what should i maintain in OBXM.
Please guide me to do the same. or suggest if any other way of doing it.
Thanks in advance
MuraliDear Murali
Maintain a Clearing A/c under transaction GA0 e.g. Business Area Clearing A/c
Make sure you have activated Business Area FS in OB65
Then run F.5D and Post through F.5E B
However by doing this you will not be able to update the Business Area but it will pass an adjustment entry
Hope it Helps
Cheers
IMK -
Script To Update Month Text Field?
Hello SharePoint Fam,
I am wanting to add a choice field to existing list that contains each month(jan,feb,mar,etc) but was wondering is it possible for me to automate this at all so I don't have to manually change default month value to correct month on the first of each month.
Basically want the field to be hidden and index it so that I can make a easy filter option for a very big list(60k items) and want it totally invisible to users so all they have to do is load there files and have no idea that a month is being tagged
to there files.
Thanks N AdvanceYou can use an event receiver (ItemAdded/ItemUpdated) to populate the month field based on any condition (like created date, modified date etc). Or you can also create a Calculated field like (MONTH([Created]).
Moreover, the field can be set so that it is not visible in forms like NewForm, EditForm, or DisplayForm. Example of setting the field in forms
SPField.ShowInNewForm = false;
SPField.ShowInEditForm = false;
SPField.ShowInDisplayForm = false;
Blog | SharePoint Learnings CodePlex Tools |
Export Version History To Excel |
Autocomplete Lookup Field -
Updating a text field in aform based on conditions
Hi ,
We are developing a custom form which has a database datablocks.
This form is a master detail form . It has a field called "status" whose initial values is 'Draft' and this field is present in the master part of the form.
The Logic for "Draft" is written in Pre-Insert trigger of the header block.
Question
If condition "A" is met and "B" is met , status should be set as a value called as 'Submitted';
If condition a is not met and B is met , status should be set as a value called as 'Created';
We are doing this in the post-update trigger at block level. But the changes are not taking effect.
Please let us know if this is the correct approach to handle the column. Note that the column "Status" is a database column.
Thanks and Regards
SRThe above is not working
Let me restate the problem statement
Hi ,
We are developing a custom form which has a database datablocks. This form is a master detail form . It has a field called "status" whose initial values is 'Draft' and this field is present in the master part of the form.
The Logic for "Draft" is written in Pre-Insert trigger of the header block.
Question
The record is created with a status of Draft initially.
Query and requery back and if condition is met , the value of status should be updated as follows......Condition A and B involves going an chekcing in some other table and based on that , we set the status column....
If condition "A" is met and "B" is not met , status should be set as a value called as 'Submitted';
If condition "A" is not met and B is met , status should be set as a value called as 'Created';
We are doing this in the post-update trigger at block level. But the changes are not taking effect.
Please let us know if this is the correct approach to handle the column. Note that the column "Status" is a database column.
Also tried the following
1) When validate item at block level by capturing the item in a parameter and then assigning the parameter to the status column in pre-update column . This is not working
Thanks and Regards
SR
---------------------------------- -
hey,
I've an active output text component which should be updated as the data is changed in the database. I've already tried af:poll but it creates a problem when used in the template.
I've seen some descriptions on active data services which I think would a solution to this problem. but I couldn't find any example as to how this could be done.
So how can I use active data services to update the text field value when the changes are made in the db or can anyone guide me to an example?
thanksHi,
See if the following link on Active Data Services helps:
http://download.oracle.com/docs/cd/E12839_01/web.1111/b31974/adv_ads.htm
Sireesha -
Duplicate a Text Field on Every Page of a Document?
Today I wrote my first vb.net/adobe app. I managed to open the pdf doc in adobe and create a named text field. I managed to insert a java script that gets the current date when the document is open and updates the text field. I would like to duplicate the text field on all pages of the document. Manually, I can right click on a text field and select duplicate. I don't see a property or method that allows me to program this. The field property "page" appears to be read only. any help would be appreciated. thanks.
page
The page number or an array of page numbers of a field. If the field has only one appearance in the document, the page property returns an integer representing the 0-based page number of the page on which the field appears. If the field has multiple appearances, it returns an array of integers, each member of which is a 0-based page number of an appearance of the field. The order in which the page numbers appear in the array is determined by the order in which the individual widgets of this field were created (and is unaffected by tab-order). If an appearance of the field is on a hidden template page, page returns a value of -1 for that appearance.
TypeInteger | ArrayAccessRFieldsallExample 1Determine whether a particular field appears on one page, or more than one page.var f = this.getField("myField");
if (typeof f.page == "number")
console.println("This field only occurs once on page " + f.page);
else
console.println("This field occurs " + f.page.length + " times);I also tried the brute force method of moving from page to page and creating a text field on each page. I used pageNum to changes the page, but, adobe didn't seem to recognize that. I saw the page change on the screen, but, all of the textfields were created on the first page!
-
Text field is missing/blank in inventroy adjustment document
Hi all,
while posting adjustement entries for physical inventory through T-code MI07 we are getting field long text i.e. BSEG-SGTXT empty.
as these accounting documents are posted automatically this text field should be updated by system only.
can help anybody help me with possible reason for such error.
thanking in advance
sharmiHi,
I am looking for the mandatory fields that are required for migrating the following using IDOC in LSMW.. Please suggest.
Area Object Description
Master Data CUSTOMER Customer / Prospect / Site
Master Data CONTACT Contact Person
Master Data CONTACT_REL Contact Person Relationships
Installed Base IBASE Installed Base
Transactions SER_TICKET CC Ticket
Transactions SER_ORDER Service Order
Transactions SER_CONFIRM Service Confirmation
Transactions SER_CONTRACT Service Contracts
Transactions SAL_LEAD Lead
Transactions SAL_OPPORT Opportunity
Transactions SAL_QUOTE Quotation
Transactions SAL_DEMOREQUEST Demo Request
Transactions SAL_ORDER Sales Order
Transactions SAL_CONTRACT Frame Contracts
Transactions XXX_ACTIVITY Activities -
Using radio buttons to set the value of a text field
I have a set of three radio buttons on a form (a performance evaluation). If I select the "1" button, I want 1 to populate in the text field. The same goes for "2" and "3"
I have not been able to code the buttons correctly for this scenario, and can't figure out how to do it.
From a previous post, I was able to get check boxes to do what I want, but they won't really work because I can't set them so that only one back may be selected.
Can this be done?
Thanks!The information for this specific case isn't anywhere. The best that you can do is understand what triggers each of the events, then ask yourself which of those triggers are pertinent to your current issue.
http://help.adobe.com/en_US/livecycle/es/LiveCycle_Designer_Scripting_Basics.pdf ...
The above link contains a great deal of information regarding how to use scripts within Livecycle Designer. The section that you would be most interested in in order to learn about the available events can be found under "Events >> List of Events".
You needed to use the initialize event so that the text field would be updated when the document was opened. This ensure that the text field has the value of the default radio button when it is opened for the first time.
You needed to use the change event so that, when the use selects a different radio button, the text field is updated with the new value.
That's about it. That PDF file that I link to above is a bit long, but it's a great place to get a good grasp of the basics of scripts.
If you have any further questions, feel free to ask. =) Have a good one.
- Scott -
Ability to update a custom text field across multiple projects in a grid type view
We have a project level custom field for the Project Owner to enter an Executive Level project status. A project owner will have many projects. Right now the owner has to open each project individually, update the text field and save which can
take a considerable amount of time. We would like to have the ability to have the project list with the text field in a grid (looks like an excel sheet) with the ability to update the text field directly from the grid. Is there some way
to do this?Hi,
Which project version are you using?
Anyway there is no "excel-like" way to bulk edit proejct field, such as you can do for the resources. The project center is unfortunately a read-only view.
For PS2010, the
bulk edit tool allows you bulk editing pronot be "excel-like" meaning updating the value in rows. You'll have to select the project with the same value for the custom field and enter the value once and validate and redo this process for each proejct field
value.
Otherwise third-party tools are available on the market for this purpose:
http://www.senseiprojectsolutions.com/sensei-bulk-update/
http://www.fluentpro.com/productsfluentbooks2013.html
Finally you could develop a side-application to achieve this objective.
Hope this helps,
Guillaume Rouyre, MBA, MCP, MCTS |
Maybe you are looking for
-
Problems copying a row and pasting it in the following row
Hi all, In a Numbers table I have 400 rows with data separated each one by a blank row row 2 has data row 3 is blank row 4 has data row 5 is blank ... and so on. I have prepared a small script to copy row 2 into row 3, row 4 into row 5,... as follows
-
Why can't I connect to the game server
why can't I connect to the game server from my ipod touch?
-
SQL Query (PL/SQL function body returning SQL query) when using to_char
we are trying to build a report page of Type SQL Query (PL/SQL function body returning SQL query). our query is so simple, we need to extract the month from the recording_date column. declare l_query varchar2(1000); begin l_query:='select to_char(rec
-
Replace text from external source expression from AE CS6 not working in AE CC
We have used some expressions in an AE CS6 project to fill text from an external file. Here's an example: try{ /* "mypath" must be absolute to data file */ myPath = "file:////nynfile1/Production/Egg/Marque/data.txt"; $.evalFile(myPath); /* Use [0,1,2
-
Intellisync error "Duplicate records found"
I am trying to sync my BB 8300 with Outlook 2007. I am using Blackberry Desk Manager 4.2.2.14. I was able to sync before but now it get this error "Duplicate records found in the device" and it won't sync. Any ideas to fix this problem? I tried to u