How to highlight invalid component in custom validator?

Hi
I have created a custom validator to verify two DateField components, and the doValidation() is working so far so good.
The question is, how to highlight the two DateField components when the validation failed?

The problem is solved by override the actualListeners() to return the two DateFields.

Similar Messages

  • How to use I18N with a custom validator?

    This is my custom validator:
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
            Pattern pat=Pattern.compile(".+@.+\\.[a-z]+");
            Matcher m= pat.matcher(value.toString());
            if(!m.find())
                FacesMessage message = new FacesMessage("Not a valid e-mail address");
                throw new ValidatorException(message);
        }Instead of providing the text "Not a valid e-mai address", I'd like to get the text out of my ApplicationResources property file.
    How can I do this?
    I know how to use it with the provided validators, but not with own custom ones
    Please help me out, thanks

    I found a solution for this problem, I don't know it's best practice but here it is :
        public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException
            String errortext;
            Pattern pat=Pattern.compile(".+@.+\\.[a-z]+");
            Matcher m= pat.matcher(value.toString());
            if(!m.find())
                ResourceBundle bundle =
                ResourceBundle.getBundle("be.vdab.resources.ApplicationResources", context.getViewRoot().getLocale());
                errortext = bundle.getString("erroremail");
                FacesMessage message = new FacesMessage(errortext);
                throw new ValidatorException(message);
        }

  • How can i get localecontext within customer validator?

    Hi,
    I want to localize my error message ,so I need to get entity attribute label
    within customer validator,I write code as follows( eo is entityImpl object eo=valCtx.getSource();)
    String attributeLable=eo.getStructureDef().findAttributeDef(tempAttrName).getUIHelper().getLabel();
    but getLabel need localeContext parameter,How can I get it or where can set it ?
    thanks very much
    lixz
    2006/12/5

    Hi,
    try this:
    DefLocaleContext dlc = new DefLocaleContext();
    String attributeLable=eo.getStructureDef().findAttributeDef(tempAttrName).getUIHelper().getLabel(dlc);

  • How to construct the component tree in my custom component?Help!

    Hi, i am writing a custom component like this:
    public class HtmlCategory extends HtmlPanelGrid
         public void processRestoreState(javax.faces.context.FacesContext context,
                java.lang.Object state)
              setColumns(1);
              HtmlCommandLink link=new HtmlCommandLink();
              link.setValue("Let's Bingo");
              MyUtil.setActionListener(context,link,"#{temp.mytest}");
              UIParameter param=new UIParameter();
              param.setName("name");
              param.setValue("Robin!");
              link.getChildren().add(param);
              param.setParent(link);
              getChildren().add(link);
              link.setParent(this);
              super.processRestoreState(context,state);
    }         you see, i want to construct the compont tree at Restore View phase this way,because the structure of the component tree will always be the same, so i don't the user to write extra code.
    But the children of the component are not rendered,the renderer of the HtmlCategory component just extends the HtmlGridRenderer(myfaces) directly,and always calls the "super" methods in the encode methods of the renderer.
    I got a message from the console:
    Wrong columns attribute for PanelGrid id0:id4: -2147483648
    but i have set the columns attribute in the code above, so what's happening? or please give some advice about how to render the component tree by myself in Restore View with the tree constructing code in the custom component class code,just lke the code above.
    Best Regards:)
    Robin

    Well, i don't know if i have got my question clear.
    usually, according to the tags you use in the jsf page, a component tree will be created at the Restore View phase,for example:
    <f:form>
      <h:panelGrid ...........>                         
              <h:dataTable ................>
              </h:dataTable>
       </h:panelGrid>
    </f:form>but because i am writing a component for my web app, all the child components and their attributes are not likely to change. so i want to reduce the tags into one custom tag, and construct the component tree internally by myself.But it is not the case of backing bean.So i wrote the the code in the method:
    public void processRestoreState(javax.faces.context.FacesContext context,java.lang.Object state)as it is shown in my orginal message.But it seems that it is not right way to construct my component tree.So where should i put the code that construct the component tree?Overriding the method :
    public void processRestoreState(javax.faces.context.FacesContext context,java.lang.Object state)is not the right way?
    Best Regards:)
    Robin

  • How do you create custom validation rule in WS 9.2?!?!?!

    Hello,
    I am using Workshop 9.2. I created a page flow, and want to do some form validations.
    I saw the simple 9.2 example, but it is only good for very basic validation, what if you have to validate the form field against a database, must you write a custom validation rule? HOW would you do this in 9.2 so that will still stay with the workshop/netui paradigm?
    http://beehive.apache.org/docs/1.0.1/netui/validation.html
    Keith

    Hi Keith,
    Staying within the declarative validation framework the answer is probably that you do need to write a custom validation rule and refer to it using the @Jpf.ValidateCustomRule annotation.
    The NetUI Annotation Reference shows how the Struts validations are supported via the framework.
    http://beehive.apache.org/docs/1.0.1/netui/annotations/pageflow_annotations.html
    Specifically, if you look through the @Jpf.Validate* annotations, while most of these are "canned" common validations, there are a few that are more open-ended, such as @Jpf.ValidateMask and @Jpf.ValidateValidWhen.
    Those two let you write the validation logic in the annotation while @Jpf.ValidateCustomeRule only refers to a custom rule in the struts validator file.
    In any case, there is a validation rule editor which should help in authoring and managing the annotations. In the Page Flow Explorer or Page Flow Editor just right click on the action or form bean bean of interest and choose Validation Rules and the appropriate scope.
    I hope that's of some use,
    Troy

  • Custom Validator for a Custom Component

    I am having troubling passing values from my custom component
    to my custom validator (via a model). For some reason when the
    validate() function is called for the validator the value parameter
    passed to the validator is not showing the value from my custom
    component.
    I have attached some example code to illustrate.
    Here is my model:
    <mx:Model id="myModel">
    <root>
    <mod>
    <name>{myTextInput.text}</name>
    <date>{myDateField.selectedDate.getTime()}</date>
    <length>{myComp.getLength()}</length>
    </mod>
    </root>
    </mx:Model>
    When I update the value of myTextInput or myDateField the
    model (as sent to the validator) shows the correct value. When I
    change the value of myComp the change is not reflected.
    Is there a particular event (or something) being dispatched
    in the other components to cause the model to get the new value
    that I need to include in my custom component? I am pretty stuck
    and would appreciate any help.
    Many thanks

    Does myComp extend EventDispatcher (or any class which does)?
    You need to flag the getLength() function as bindable and to
    dispatch an event:
    [Bindable('getLengthChange")]
    public function getLength() : Number
    // does whatever it does
    When you update myComp have it dispatchEvent( new
    Event("getLengthChange") ) and I think it will work.

  • Custom validator for a SelectMany component

    I did not succeed at validating a selectManyCheckBox with a custom validator.
    I want to validate that the user selected at least 1 and at most 3 checkboxes.
    The UIComponent.getSelectedValues always returns an array of length 0, even when some boxes are checked.
    Page code:
         <h:selectManyCheckbox id="selectProfessions" value="#{userBackingBean.selectedProfessionIDs}" layout="pageDirection" styleClass="category">
              <f:selectItems value="#{categoryTreeBackingBean.professionSelectItems}" />
              <f:validator validatorId="com.studio184.news.ui.validator.SelectCategoriesValidator"/>
         </h:selectManyCheckbox>
    Validate method:
    UISelectMany select = (UISelectMany)component;
    if (select.getSelectedValues() == null || select.getSelectedValues().length < 1 || select.getSelectedValues().length > 3) {
         String summary = ...
         String detail = ...
         FacesMessage message = new FacesMessage(summary, detail);
         message.setSeverity(FacesMessage.SEVERITY_ERROR);
         throw new ValidatorException(message);
    Any help would be greatly appreciated.
    Bruno
    http://www.practicalsoftwarearchitect.com

    In general, the value property is set at the end of the Process Validations phase.
    You can use getSubmittedValue() to access the submitted values.
    More simply, you can use the third argument of the validate method which is the same as the submitted value.
    For example:
    public void validate(FacesContext arg0, UIComponent arg1, Object arg2)
              throws ValidatorException {
         Object values[] = (Object [])arg2;
         if (values() == null || values().length < 1 || values().length > 3) {
         // throw exception!!
    }

  • How to skip custom validator  if other validators fail

    I have a custom validator that checks data from db, the validator is at the end of the page so it gets called last. If there already are fields in the form that don't validate i don't want to run my custom validator since will not submit anyways and no need to put extra strain on the db. How can i accomplish that?

    Sorry for the confusion. the triggerEvent="click.add" should be triggerEvent.add="click"
    I am using Flex 4. The validation is fail if the user don't input anything. Does clickHandler still process the code even though the validation is fail?

  • How to find the status of package (valid/invalid) was at a particular time

    How to find the status of package (valid/invalid) was at a particular time ?
    I want to find the status of one oracle package at 3pm yesterday. The status of this package today is INVALID.
    I am sure it was VALID yesterday. But no way to prove it. Can any one help please???
    I can generate AWR report for last 7 days...

    Try using a flashback query, like this:
    select object_name, object_type, status
    from dba_objects AS OF TIMESTAMP (SYSTIMESTAMP - INTERVAL '18' HOUR)  -- 18 hours ago
    where object_name = 'MY_OBJECT'
    ;if you haven't granted FLASHBACK privs, you may need to connect as SYS to do a flashback query on a data dictionary table.
    But this should give you the info you need - if it's still in undo.

  • How to use  or call component in custom script expression

    i want to use component in custom script expression .(custom script expression is located at :
    when yow will click on one of the steps in criteria workflow
    1)there is a tag named as event on clicking the event tag,there are two buttons named edit and clear on clicking edit.there is a screen having custom as a tag,on clicking that tag there is written custom script expression, here i hav to write a code to include a component).

    you can define code in a component (a service or an IDOC Include) that you can then call from the workflow "custom" tab.
    So if your component has an include like this:
    <@dynamichtml myInclude@>
    <$do Some Stuff$>
    <@end@>
    Then in your workflow step event "custom" tab you can write:
    <$include myInclude$>
    The workflow event will then execute the <$do Some Stuff$> line.
    With a service, you would define the service in your component then call <$executeService("MYService")$> in the step event custom code.
    You cannot define includes or services in the custom script tab for workflow.

  • Modifying component tree after validation failures

    I'm reworking a JSF web app to use JSF's validation capabilities. As it is now, the validation all occurs in various action methods, during the invoke application phase. I volunteered to do this update to separate the business processing code from the data validation code as well as take advantage of the fact that using JSF validation guarantees that the data in the model won't be updated unless the user data is valid.
    So, I've run into one thing that I can't figure out how to accomplish using JSF's validation capabilities.
    Here's the old form...
    <!-- CITY -->
    <h:inputText id="city" value="#{userDetailsBean.city}" rendered="#{userDetailsHandler.showCityInput}"/>
    <h:selectOneMenu id="cityFromList" value="#{userDetailsBean.city}" rendered="#{userDetailsHandler.showCityList}">
        <f:selectItems value="#{userDetailsHandler.cityDropList}"/>
    </h:selectOneMenu>
    <!-- STATE -->
    <h:selectOneMenu id="state" value="#{userDetailsBean.state}">
        <f:selectItem itemValue="#{null}" itemLabel=""/>
        <f:selectItems value="#{userDetailsHandler.statesList}"/>
    </h:selectOneMenu>
    <!-- ZIP -->
    <h:inputText id="zipCode" value="#{userDetailsBean.zipCode}"/>Note that there are two components representing the city. When the form is first presented, the inputText is shown. Then, if the address doesn't validate, we present the selectOneMenu after filling userDetailsHandler.cityDropList with the appropriate city options (based on the zipcode).
    So, can anybody think of a good way (from within a custom JSF validator) to set the appropriate properties in userDetailsHander in order to make the selectOneMenu render and show the proper options? Feel free to suggest a change in architecture as well. I'm not stuck on using this userDetailsHandler that was previously in use.
    I figure I could always right a custom validator that takes in a bean as an attribute in the tag and the bean. On a validation error, the validator could then setup the appropriate properties in the bean. This just seams a little hacky.
    By the way, the validator will probably be written to take in the names of the city, state, and zip components. I'm following the multi-component validator idea that is presented in Core Java ServerFaces, 2nd Edition. (The validator takes in the component names, which it uses to get the local values, then performs multi-component validation work.) I guess I could pass both the cityTextInput and cityListInput components into the validator, right?

    Here's what I have so far for my validator's validate() method. Some stuff has been omitted to make this a smaller code chunk. I've attached this validator to the zip component.
    public void validate(FacesContext facesCtx, UIComponent uiComponent, Object value)
                   throws ValidatorException {
        // get a handle to the other components
        // city
        UIComponent cityTextComp = uiComponent.getParent().findComponent(cityTextComponent);
        EditableValueHolder cityValHolder = (EditableValueHolder) cityTextComp;
        // state
        UIComponent stateComp = uiComponent.getParent().findComponent(stateComponent);
        EditableValueHolder stateValHolder = (EditableValueHolder) stateComp;
        String city  = (String) cityValHolder.getLocalValue();
        String state = (String)stateValHolder.getLocalValue();
        String zip   = (String) value;
        System.out.println("Validating " + city + ", " + state + " " + zip);
        boolean isValid = GenericValidator.validateAddress(city, state, zip);
        if (isValid) return;
        // assume this is an invalid city for the zipcode given
        // I've removed the code for the other possibilities since it
        // doesn't pertain to my issue here
        // Setup the city list
        UIComponent cityListComp = uiComponent.getParent().findComponent(cityListComponent);
        UISelectOne cityListSelectOne = (UISelectOne) cityListComp;
        List<String> cities = GenericValidator.listCitiesForZip(zip);
        // add the appropriate items to the selectOneMenu
        for (String c: cities) {
        // WHAT DO I DO HERE?
        cityListComp.setRendered(true);
        cityTextComp.setRendered(false);
        // now signal a validation exception
        FacesMessage msg = <some faces message>;
        throw new ValidatorException(msg);
    }If I can just figure out how to add the appropriate items to the h:selectOneMenu from within the validator code I presented, I'm home free, I think.

  • Custom Validation in ESS Edit Screen

    All,
    We have a requirement in ESS Address screens that all country users should key in only English Data. We are in SAP ESS SP12 and all the Address Components are in WD Java. The validation on all the address screen fields for this requiement has to be handled and give an error message back to the user.
    The Options that I Checked out were:
    1) Handling the Validation through BADI HRPAD00INFTYUI or HRPAD00INFTYBL.
    2) Handling the validation in WD Java layer inside the country spoecific components isConsistent method of the Detail View Component controller
    Which is the best place (ABAP or JAVA) to handle Custom validations on the Edit Screen and give back message to the user? Please suggest if any other better options are available other than the above mentioned ones.
    Regards,
    Nagarajan.

    Hi,
    Both are doable if you are good in java and have NWDI ,handling validations in the wd java layer is easy. If you are good in ABAP you can handle in ABAP.It depends on how you write your code, if you do validations in java and if your validation fails you can show errors to user right away which will reduce your call to backend at isconsitent method for checking the errors.
    Thanks,
    pkv

  • Pass parameter to the custom validator

    Hi, How can we pass parameters to the custom validator, i want something like:
    <f:validator validatorId="validators.dateRangeValidaor">
         <f:param id="toDate" value="#{issue.toDate}"/>
         <f:param id="fromDate" value="#{issue.fromDate}"/>     
    </f:validator>but tld dosnot support f:param tags in f:validator tag, is there any possible solution for that??

    Use f:attribute; something like as follows:<h:inputText ...>
      <f:validator .../>
      <f:attribute name="toDate" value="#{issue.toDate}"/>
      <f:attribute name="fromDate" value="#{issue.fromDate}"/>
    </h:inputText>Note that these attributes are not of the validator but of the parent component.
    You can get these attributes using UIComponent.getAttributes().get("toDate").
    I think this is not so friendly for page authors.
    So, I recommend you to develop a custom validator tag which can be specified
    the parameters you want.

  • Custom validation rules

    Using adf/bc with jdev 10.1.3.3. I've created a custom validation rule class according to the instructions in the adf guide. In that class, I've defined just one property, along with its getters/setters. I've registered my rule in the business component project and associated the rule to an entity attribute via the entity object editor. My problem is that I don't see any way for me to set the property/value of the property that's defined in the validation rule class. For example, in the SRDemo app, in the entity editor for ServiceRequest, if you highlight Validation in the left pane then select the AttributeMustExistInViewRowRule for the Status attribute and click the Edit button, you can set various property values that have been defined in the validation rule class. These values appear to then be updated to that entity's xml file. When I'm in my entity object editor and i've assigned a validation rule to an attribute, I can type in the error message text in the Edit Validation Rule dialog, but it says there are no properties to edit! I guess I haven't wired something together quite right? Note, I have not created the customizer and bean info classes for the design time aspect of this stuff. I assume that you do not absolutely need these classes to create and work with a customr validation rule? Anyone know what I'm doing wrong?

    ok, i figured out the problem. The property/value fields in the Edit Validation Rule dialog will not appear until you've actually compiled the custom validation rule class. I had tried to create the validation rule class, register it with the bc project, and assign it to an entity attribute all without first compiling the class. I stumbled upon this 'fix' in jdev's help, which leads me to another question. For the help topic entitled Creating Custom Declarative Validation Rules for Oracle ADF Business Components, the instructions have you create a class that implements JbiValidator and provide implementation for the method vetoableChange, from which you typically call validateValue. The adf guide's example has the custom validation rule class that extends AbstractValidator and implements JboValidatorInterface. In this example, you provide implementation for the validate method. What's the difference between these two approaches and when should I use one over the other? Thanks.

  • How to get the handle of the Validation Failure Message Popups.

    Hi,
    I'm using Jdev 11.1.2.0
    I have added validation rule(less than system date) and failuremessage("date should not after currentdate") on the date field in EO.
    when I enter greated than the sysdate in date field in page, I'm getting validation failure message in a popup with ok button. its working good.
    but when i click on the popup ok button, the focus should go the date field again and it is higlighted.
    So, how to get the handle of the popup's ok buton? and how to highlight the datefield after clicking the popup's ok button?
    Any suggestion would be appreciated.
    thank you.

    if i understood correclty means,
    i hope that, error popup is provided by framework.. how could be possible? to catch the error popup ok button.
    am not well aware of catching the error popup which is provide by framework..
    but i had answer for your part of the question,
    if the condition go off false means you force the cursor into date field. this is can be done using 'javascript'. unless using script you can't do that. ADF doesnt provide any force focusing feature.
    please google how to focus the field.
    https://blogs.oracle.com/jdevotnharvest/entry/how_to_programmatically_set_focus
    http://technology.amis.nl/2008/01/04/adf-11g-rich-faces-focus-on-field-after-button-press-or-ppr-including-javascript-in-ppr-response-and-clientlisteners-client-side-programming-in-adf-faces-rich-client-components-part-2/
    http://lspatil25.blogspot.in/2012/04/adf-default-cursorfocus-to-input-field.html
    http://donatas.nicequestion.com/2012/04/component-to-set-initial-focus-in-adf.html

Maybe you are looking for

  • Error: 'bobj' is undefined - crystal report for VS2013 - please help ASAP

    Currently we are trying to migrate from VS2008 to VS2013 and we installed Microsoft Visual Studio Ultimate 2013 on a windows 7 laptop. All our crystal report programs are migrated to VS2013. I downloaded Crystal report Support Pack 10 (v. 13.0.10.138

  • My iPhone 4 won't work with my car adapter but all other iPhones do. What's wrong with mine?

    I have an iPhone 4 ad I have a car adapter that says it is compatible with my phone. Every thing else works fine with the adapter. All different kinds of iPods and anyone's iPhone that I try on the adapter works except mine. Could there e something i

  • Import files from rca lyra

    I am new to mac and am trying to transfer files via usb from my rca lyra to my mini mac. The files are .asf the mac is asking me to id the software to open the files with, this is were I am encountering the problem, how do I acc. this task? thanks in

  • TES 6.1.x - how do you tell what DB is used by ClientMgr?

    We just externalized the Client Mgr DB to Oracle, updated config files, etc. How do you tell what db is using - Derby or Oracle?        

  • Problem scaling with AffineTransform()

    I am writing on a small program which scale,translate,rotate and shear an rectangle or ellipse. However, when I select either one of the transform from the combobox, no transformation happen at all after the redraw button is drawn. In my program, I m