The input text formatting

Hello

I have a requirement for formatting the text entry in a format [(XXX) XXX-XXXX phone number].

Implementation:
1.Defined an input text component in the UI.
        <af:inputText id="it2" value="#{pageFlowScope.testAppBean.phoneNumber}" label="Enter Phone number:">
            <f:converter converterId="CustomConverter"/>
        </af:inputText>

2.Implemented custom converter as mentioned below.
public class CustomConverter implements javax.faces.convert.Converter, org.apache.myfaces.trinidad.convert.ClientConverter{    
    public CustomConverter() {
        super();
    }

    public Object getAsObject(FacesContext facesContext,
                              UIComponent uiComponent, String value) {
        if (value == null || (value.trim().length() == 0))
                     {
                         return value;
                     }
           
             // format phone numbers to display correctly
           
               String phone = value.trim();
               if (phone.length() == 10) {
                   phone = phone.substring(0, 3) + "-" + phone.substring(3, 6) + "-" + phone.substring(6, 10);
               }
               else if (phone.matches("\\d{10}\\s*\\d+")) {
                   phone = phone.replaceAll("\\s+", "");
                   phone = phone.substring(0, 3) + "-" + phone.substring(3, 6) + "-" + phone.substring(6, 10) + " x" + phone.substring(10);
               }
         
             return phone;
    }

    public String getAsString(FacesContext facesContext,
                              UIComponent uiComponent, Object value) {        
        
        String phoneNumber = (String)value;
                 if (phoneNumber == null || (phoneNumber.trim().length() == 0))
                  {
                      return "";
                  }
                  String phone = phoneNumber.trim();


                  if (phone.length() == 10) {
                      phone = phone.substring(0, 3) + "-" + phone.substring(3, 6) + "-" + phone.substring(6, 10);
                  }
                  else if (phone.matches("\\d{10}\\s*\\d+")) {
                      phone = phone.replaceAll("\\s+", "");
                      phone = phone.substring(0, 3) + "-" + phone.substring(3, 6) + "-" + phone.substring(6, 10) + " x" + phone.substring(10);
                  }
                
                return phone;
    }

    public String getClientLibrarySource(FacesContext facesContext) {
        return null;
    }

    public Collection<String> getClientImportNames() {
        return Collections.emptySet();
    }

    public String getClientScript(FacesContext facesContext,
                                  UIComponent uiComponent) {
        return null;
    }

    public String getClientConversion(FacesContext facesContext,
                                      UIComponent uiComponent) {
        return null;
    }
}
3.Registered in faces-config.xml
 <converter>
    <description>A Converter for phone number</description>
    <converter-id>CustomConverter</converter-id>
    <converter-class>view.util.CustomConverter</converter-class>    
    </converter>

4.Ran the application.
The question is, at the entrance of text in text box... the custom converter is not called. Can someone help me to convert the text entered in planned phone number format.

* Note: I expect that for every key stroke... the custom converter is called.

Kind regards
Kiran

Check out this blog https://blogs.oracle.com/jdevotnharvest/entry/get_social_security_numbers_right
or this example: http://multikoop.blogspot.de/2012/11/adf-smart-input-date-client-converter.html

Timo

Tags: Java

Similar Questions

  • How to display the ToolTip when the input text is disable

    How to display the ToolTip when the input text is disable?

    Just checked in FF and IE11, works fine for me (jdev 12.1.3)

    
          
    
    

    Dario

  • How to set the width of the input text

    Hello


    I form, which have little input text.the layout of the form is not correct.some input text is so long, it's hard to do in any seizure of text the same length. Some inputtext have varchar2 (1000). How do I?

    Hello

    first of all to mention the jdev version that you are working

    In the input text is property called columns. You can give a value such as 200 or 300 according to your need.

    Try this.

  • How to detect if the cursor is no longer within the input text area

    Hello.

    My question today is:

    How to detect (in AS3) if the cursor is no longer within the input text area?

    I tried to mouse events, events, events in text but without success.

    Any ideas?

    Concerning

    If you have a textfield of entry with the instance name it '...

    it.addEventListener (FocusEvent.FOCUS_OUT, focusOutHandler);

    function focusOutHandler(evt:FocusEvent):void {}
    trace (evt. Target.Name);
    }

  • Form field style (Input Text formatting)

    Is there a way to format multiple form fields (input text) at the same time? For example, I have a form with text entry fields 10 and I want each of them to have black borders and grey backgrounds. To do this, I coded one as that:
    txtInput1.border = true;
    txtInput1.borderColor = 0 x 000000;
    txtInput1.background = true;
    txtInput1.backgroundColor = 0xCCCCCC;

    Y at - there a way for me to create a kind of 'style' I could apply all these values in a text input easily, the way TextFormat can apply text styles?

    I am answering my own question, but I thought I got it would close out of myself. I realized that I could create my own function that accepted the TextField object as an argument and then applied to the formatting in this TextField. The code is attached.

  • I want to accept only Arab characters in the input text

    Hello

    Is it possible to let the user just write in Arabic in the af input text?

    If he enter English tank when you use keyboard ENG that I want to prevent this event and not let him write without error msg and if it helps keyboard AR I want let write

    Thank you.

    You can implement something like this using javascript. You should prevent the addition of English characters of:

    -Keyboard

    -By using ctrl + v (in case you have copied English words)

    -Using right-click + spent (in the case where you have copied English words)

    To do this test to track the following:

    1 - inside af:inputText add 2 clientListener. One to accept only Arabic characters and the other for the deactivation of ctrl + v as:

    
              
              
    
    

    2 - Add af:resource with type = "javascript" and inside this write three functions:

    -an acceptArabic function.

    b disabledPastFunction

    c disabled right click on the page.

    as:

    
    
            = 1560 && k <= 1610) || k == 32)
        {
        }
        else
        {
          evt.cancel();
        }
      }
      ]]>
    
      function disabledPastFunction(evt)
      {
        var k=evt.getKeyCode();
        var e = window.event;
    
        if(e.ctrlKey)
        {
          if (window.event.keyCode == 86)
          {
            evt.cancel();
          }
        }
      }
    
      function dis_rightclickNS(e)
      {
        if ((document.layers || document.getElementById && !document.all) && (e.which == 2 || e.which == 3))
        {
          return false;
        }
      }
      if (document.layers)
      {
        document.captureEvents(Event.MOUSEDOWN);
        document.onmousedown = dis_rightclickNS;
      }
      else if (document.all && !document.getElementById)
      {
        document.onmousedown = dis_rightclickIE;
      }
      document.oncontextmenu = new Function("return false")
    
    
  • How to check the answer in the input text area

    Hey, I have a project for school on the colons and semicolons. As part of it, I want to make a box of text input that puts the answer to a question in the player then clicks on a button that controls the input box, and if its correct goes to a correct screen so bad it goes to a screen that is incorrect. Unfortunately I do not know how to do someone help me. Thank you!

    var answerA:Array is ["the correct answer to the question 1', 'address 2', '3 ', answer...];.

    var questionA:Array = ['question 1', "Q2", "q3",...];

    var currentQuestion:int = 0;

    checkAnswer.addEventListener (MouseEvent.CLICK, checkF);

    function checkF(e:MouseEvent):void {}

    {if (answer_tf. Text is answerA [currentQuestion])}

    as much as goto

    }

    }

    increment currentQuestion somewhere

    Check if the quiz is completed.

  • How to add a string to the end TLFTextField without losing the current text format!

    • I have a TLFTextField which loads the text of the external text file.
    • Then a function changes the format of certain parts.
    • Then, as soon as I add a string to the end my TLFTextField, all previous formatting is lost!

    I use this code to add the string:

    • myTLF.text += ".";

    or

    • myTLFText.text = myTLFText.text.concat(".");

    Should I use another method?

    Sample.png


    pass again the text through your function put shaped, or try appendText:

    • myTLF.appendText(".");
  • Change only the similar text format?

    Hi all

    I'm changing the formatting of the similar text.

    for example

    I R-6-6 (more like this one where the number of change) which is light and I want to make it regular.

    I want to change all elements of similat thus, if 4-R-11 and R-5-3 and so on.

    I thought that the wildcards would, but it's not. At least I'm not getting to work.

    Thank you.

    Kevin J

    Thanks Peter.

    I thought about it it. Took a little fiddling with grep. My solution: \d-\d-R and R-\d\d-\d for mor than one number.

    KJ

  • Height of the input text box...

    Hi all

    Is there a way to dynamically get the size of an input text throught javascript box? For example, I have an < input type = "text" id = "myBox" size = "50" >, and I would like to get the height of the text box with the id "myBox" through javascript dynamically.

    Thanks in advance!

    Daverms wrote:
    > Hi,.
    >
    > You can not retrieve the height of the text box since there are actually no 'height' attribute is available for theand also the width is represented as an attribute of "size".

    a text box CAN have HEIGHT and WIDTH set in style = attribute.
    If so, you can get these values with
    document.getElementById("yourid").style.height and
    document.getElementById("yourid").style.width

    However, WITHOUT setting the height and width in the style = attribute, that you can't
    get the default width/height of a textbox
    --

    Azadi Saryev
    SABAI - Dee.com
    http://www.SABAI-Dee.com

  • Setting focus to the input text area

    I use MX 2004 and construction of a simple game where the contribution of users numbers in a dynamic text box. To limit the number of mouse clicks, I'm wanting to set the focus to the input box when that screen/page loads. Right now, we have to click on the area of input text field, enter their choices, then click on the submit button. I just want to type first, then click on the submit button.

    I set a variable to the text box of entry as "answer_box".

    I thought I remember a 'setFocus' or a 'onFocus' in ActionScript once before, but I can't find an example.

    Any help would be great!
    Thank you

    Thanks Rothrock. It worked. The 'Sélection' class allows you to define and control the text box where the insertion point.

    My text entry box is called, "years1.

    In the layer actions, the first line, I put - Selection.setFocus ("years1");

    Works perfectly. Thank you for pointing me in the right direction

  • No text box for the ADF form the input text.

    Hi all

    Im trying to create a form of ADF that can send data to a table. Ive never done this in a tutorial and it seemed pretty simple. Now, when I run the project page comes up with any type of data. Is there a solution to this?

    Screen 3.pngscreen 4.png

    Drag and drop the Insert to create the data to the form control.

    a descent of the project area click on create the text of the button Shows.You Enter input data and click on submit.

    I have tried.it worked fine

  • Conditionally display and hide the input text

    JDev 11.1.1.5.0

    I have two texts of the PROFILE and the SCORE entry.

    SCORE is displayed only if my PROFILE is E or F.

    And if it must be hidden once the value of the PROFILE is replaced by another value.

    In addition, please note SCORE field should be mandatory if the PROFILE is E or F.

    Here is the code I tried so far:

    < af:inputText value = "#{bindings." Profile.inputValue}.

    label = "#{resources." Profile} ".

    required = "true".

    columns = "#{bindings." Profile.hints.displayWidth}.

    maximumLength = '1 '.

    shortDesc = "#{bindings." Profile.hints.ToolTip}.

    ID = "it94" autoSubmit = "true" >

    < f: validator binding = "#{bindings." PsamProfile.validator} "/ >"

    < / af:inputText >

    < af:inputText value = "#{bindings." Score.inputValue}.

    label = "#{resources.score} '"

    required = "#{bindings." Profile.inputValue is 'E' or links. Profile.inputValue == 'F'} '.

    columns = "#{bindings." Score.hints.displayWidth}.

    maximumLength = "#{bindings." Score.hints.Precision}.

    shortDesc = "#{bindings." Score.hints.ToolTip}.

    ID = "it164".

    visible = "#{bindings." Profile.inputValue is 'E' or links. Profile.inputValue == 'F'} '.

    partialTriggers = "it94.

    contentStyle = "" text-align: left; ""

    autoSubmit = "true" >

    < f: validator binding = "#{bindings." Score.Validator} "/ >"

    < af:convertNumber groupingUsed = "false".

    model = ' #{bindings. " Score.format} "/ >"

    < / af:inputText >


    I tried to use a component parent and using rendering attribute for the NOTE field as explained in https://blogs.oracle.com/Didier/entry/only_rendered_adf_faces_compon, but it did not always help.

    Ah, OK, in that case you ave to use the showRequired instead of the required property and validate the score field once you submit the data or in the model.

    You can't have both. Once the message appears you have erase as you otherwise cannot continue to work. Showrequired shows the * before the label but does not check.

    Timo

  • function which checks if the input text is the same as the text in the Flash file

    Hello!

    I'm doing a Flash AS2 project for learning the word and I would like to know your opinions and your advice on this topic:

    I have Word check the task, where you have to write (text input) the correct names under these 3 photos and check if you wrote them properly with the key - "CHECK!"

    It would be simple, but it is mandatory that the text of the inscription must be compared to a text file and then checked if they match.

    I added a picture to better understand...

    Picture1.png

    Is this possible in AS2?

    Thank you!

    you don't know.

    Use the text property of the textfield object and load the text file using loadvars.  you will have to parse text loaded using the string of flash (and perhaps array) methods.

    p.s. that apple looks more like a tomato for me.

  • Throw the pasted text Format

    Hello

    I am facing problem with text, I have docs PDF and Word that uses the text from.

    When I copy some text for example in document InDesign CS 5.5, some 'Points of mark' or extra spaces between words is displayed under the rectangle shape.

    I tried to copy and paste the text in the text field, so there is no formatting, but the "question mark" appears.

    any idea

    Thank you

    Finally found a way to Insert a character in ID - so now I find how the find .

    Copy-paste in the discovery of this area in fact does not work (which is weird), but type in Unicode only. Search

    and replace it with what you want. In GREP, it's another notation, in there, you would use this

    \x{FFFD}

Maybe you are looking for