About Validation in JSF

i encounter such a problem that: when a jsf page fails in validation, i cannot do anything on that page till validation success or i kill the session. For example when i fill a field with an inappropriate value, it fails in validation. then i send another parameter to that page which is appropriate to the scope of validation. then the jsf page refreshes but the value that caused the validation failed is rendered not the parametre i sent. when i asked it to the senior developers they said it is such the way. they said the wrong value kept somehow. if u share your knowledge i will be appreciate. santiago

you can create a demo use JSF achitecture, and create the simple page,
for example ,login.jsp, and add tag <h:inputText/> <h:commandButton/> in you login page,
add custom validation and custom converter to <h:inputText/>
for your tag <h:commandButton/>, adding the phaseListener and track the JSF lifeCycle by log4j.
you will learn more about component-based JSF achitecture.
...

Similar Messages

  • Validation in JSF using alert boxex with javascript

    Hi,
    I want to validate the input of the user as client-side validation, without returning to the server..
    So, if for example he doesn't fill in a field, an alert box should be displayed : " No valid input !!"
    Can soemone help me..
    Thanks

    <h:selectOneRadio id="myradio" required="true" ... >
    </h:selectOneRadio>
    <h:message for="myradio" />Submit the form, if the radio is not selected while the 'required' attribute is set to true, you will get a default validation error in the h:message.
    Get through a good JSF book/tutorial and read on about the validation. JSF offers a robust and highly customizeable validation framework. The error messages are also customizeable. The only difference with the Javascript approach is that it costs one trip to the server as well. But the big advantage is that it is much more robust. As Javascript is clientside, it can easily be disabled by the client or even hacked by the client.
    Here are some useful links:
    JSF book: http://www.amazon.com/JavaServer-Faces-Complete-Reference/dp/0072262400
    JSF specification: http://jcp.org/aboutJava/communityprocess/final/jsr252/index.html
    JSF tutorial (Java EE tut chapter 10 and on): http://java.sun.com/javaee/5/docs/tutorial/doc/bnaph.html

  • How to do Javascript validations in JSF

    Hi ,
    I want to know about the javascript validation in JSF. I want to know simple validations like field should not be empty.
    I have a problem with my code can any one suggest me on this. for your reference here i'm attaching my code.
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
    <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
    <f:view>
         <%@ include file="../includes/header.jsp"%>
         <h:form id="createForm">
              <script>   
             function validate() { 
                 if((document.createForm.courseId.value=='') ||(document.createForm.courseId.value==null))
                    alert("Please Enter Course Id");     
                     return false; 
                 if(document.createForm.fileName.value=='')
                    alert("Please Enter File Name");     
                     return false; 
                   retutrn true;
                         </script>
              <table width="768" height="100%" border="0" cellpadding="0"
                   cellspacing="0">
                                  <tr>
                                                      <td width="200" height="25" align="left" class="formtext">
                                                           Course Id:
                                                      </td>
                                                      <td height="25" align="left">
                                                           <h:inputText id="courseId"  value="#{bean.courseId}"  required="true"  />
                                                      </td>
                                                 </tr>
                                                 <tr>
                                                      <td width="200" height="25" align="left" class="formtext">
                                                           File Name:
                                                      </td>
                                                      <td height="25" align="left">
                                                           <h:inputText id="fileName" value="#{bean.fileName}" />
                                                      </td>
                                                 </tr>
                                            </table>
                                  <tr>
                                       <td colspan="2" align="center" class="formtext">
                                            <h:commandButton value="Create"
                                                 action="#{control.getSelectedItems}"
                                                 onclick=" return validate();" />
                                       </td>
                                  </tr>
                             </table>
                        </td>
                        <td width="12" valign="top" background="images/tile_left_right.jpg">
                             <img src="images/tile_left_right.jpg" width="6" height="1" />
                        </td>
                   </tr>
              </table>
         </h:form>
         <%@ include file="../includes/footer.jsp"%>
    </f:view>

    Have you checked the element ID's? Maybe you have overlooked the woodstocked ID's. Look in the generated HTML source and base your Javascript on this.

  • XSchema: How to get (more) Information about validation errors?

    I changed the file car.xml to have an invalid xml-file, then
    i validate the demo car.xml using the demo programm xsdtest.
    I got the following error message:
    In line 7 of car.xml:
    LSX-00290: invalid enumeration choice "Hugo"
    LSX-00213: only 0 occurrences of particle "sequence", minimum is 1
    Validation failed, error 213
    The first 2 lines are dumped from the SchemaProzessor. Unfortunatly there is no
    possibility to get this information with a methodcall or by return value
    to use for further processing!
    The only thing i got controlled back is the error code 213.
    But how do i get the correspondening errortext ? What means error 213 ?
    So here is my suggestion:
    Please give accurate information about validation errors! Including:
    1) The position where the error occurred. (maybe in XPath notation)
    2) An error Number to classify the error (Including a possibility to resolve the errormessage via program.)
    3) An error text for the specific case : (for example : invalid enumeration choice "Hugo")
    Please give this information in a struct back or provide methods on the
    Xschema prozessor.
    Otherwise the XSchema support is useless!!!!!
    Sorry for my bad English & Greetings
    Martin Frenzel
    By the way: The XDK for Java uses a different Error Messages !!!! But there is the same problem...

    1.How to check when user last time login to database.AUDIT
    2.If user account is lock why it is locked? if it is locked by trying to loing with wrong password how to check how many times he attempted with wrong password...and other reasons alsoCheck Profile For this user and attr.
    3.Wheni was trying to select user expire date it is showing empty value...can we check expire date through querys or we need to check profile?
    SQL> select EXPIRY_DATE from dba_users ;
    EXPIRY_DA
    24-SEP-11
    24-SEP-11
    24-SEP-11
    24-SEP-11
    24-SEP-11
    24-SEP-11
    24-SEP-11
    23-MAY-13
    24-SEP-11
    24-SEP-11
    24-SEP-11 check
    expiry_date in dba_users is null
    4.How to check when he was reset his password last time.SELECT PTIME FROM SYS.USER$;

  • Customised validation in jsf

    hi,
    pls help
    my requirement is that, in the case of implementing customised validation in jsf ,i have to call an xml(which is outside of our application context ) in backing bean's method using java unified expression laguage . i'm not able to parse and read this xml's data using expression language.
    please send code.

    I should not used the hx library.So,please give a soluntion other than this.
    Message was edited by:
    Yamini_screen

  • About visual web jsf  tuotorials

    hi i am developing web application using visual web jsf frame work in netbeans iDE.can any one give me details about visual web jsf tutorials or books

    I don't use "visual JSF", but if I am correct, Netbeans has a lot of tutorials at their website.

  • Issue with back end validation in jsf 2.0

    I am upgrading my apps to jsf2.0 and I came across something that I hope you have already solved.
    In jsf 1.1 action methods returned a string. If that string was NOT mapped as a navigation in faces-config.xml, then it just rerendered the active page. this made doing back end validation easy because I could add messages to the faces context and when the active page rerendered the validation messages would get displayed and no one was the wiser than it was done on the back end instead of on the front end.
    In jsf 2.0 I get null pointers if I return a string that is NOT mapped as a navigation. So I changed the code to return a string that is mapped as a navigation for that page when there is a validation error. but that is treating it like a new request and not a rerender so the validation messages I added to the faces context are not there when the page renders.
    if i test submit a form that has only front end validation then it works fine and the validation messages are correctly shown.
    any suggestions?

    In 11.2.0.3 you are unlikely to see the various truncate/drop issues relating to large numbers of small extents - unless you use dictionary managed tablespaces.
    There are a couple of possible threats with small extents and highly concurrent inserts with ASSM that might be a temporary problem when the object size is small. There may still be some issues with large uncommitted inserts or deletes making other session's work very hard to identify free blocks until the large transaction has committed - these things can be hard to test.
    There may still be a couple of inefficiencies with parallel query and small extents, although parallel CTAS did have a (possibly temporary) hack to allocate immediate large extents to work around some of the silly details.
    Really you need to think through your requirements and them model them on your system - some of the anomalies have changed several times over the last three years.
    Regards
    Jonathan Lewis
    http://jonathanlewis.wordpress.com
    Now on Twitter: @jloracle

  • How to make custom  validator in jsf

    hi
    i am using jsf for web designing in my projects.now we are using java script for JSF validation .but i am interested to do validation using validator tag of JSF.i have tried ,but it is not working.what can i do for this problem.can u give some simple examples with clear explanations.
    My validator class file is
    package com.obs.ftw.util.validation;
    public class isEmpty implements Validator{
         public isEmpty(){}
         public void validate(FacesContext context, UIComponent uiComponent,Object value) throws ValidatorException{
              System.out.println("Inside the validate");
    FacesContext context=new FacesContext();
              String firstName=(String)value;
              if(StringUtils.isEmpty(firstName)){
                   FacesMessage message=new FacesMessage();
                   message.setSeverity(FacesMessage.SEVERITY_ERROR);
                   message.setSummary("First Name is Empty");
                   message.setDetail("First Name is Empty");
                   context.addMessage("Application:T5",message);
    faces-config is
    <validator>
              <validator-id>isEmpty</validator-id>
              <validator-class>com.obs.ftw.util.validation.isEmpty</validator-class>     
         </validator>
    jsf page is
    <h:message for="T5"></h:message>
    <h:inputText value=#{mybean.lcFirstname} id="T5" required="true">
    <f:validator validatorId="isEmpty"/>
    </h:inputText>
    this function calls isEmpty constructor.but system.out.println("Hi") isn't called which is defined inside the validate()
    fuction.
    any problem in this isEmpty function?any one give me a solution with an example
    advance thanks
    with regards
    oasisdeserts

    Thanks for reply.i was expecting this one and it is working fine .but i want to validate null or empty string using
    validator tag.Is any other way to do this .There is no standard way to do this. You may consider to write your own implementation of the JSF LifeCycle.
    can u give some explanation to create messagebundle Check chapter 2.5.2.4 of the JSF specification: [http://jcp.org/aboutJava/communityprocess/final/jsr252/index.html]
    whether it will be useful to validate empty string?The default behaviour is:
    The 'required' attribute already validates the empty value. If the value is empty and the 'required' attribute is set to true, then the "field is required" message will show up (text may depend on the message settings and configuration -- in JSF 1.2 you can use the 'requiredMessage' attribute to specify that message right in the JSF page). If the value is not empty, then the attached validator will be fired, regardless of the setting of the 'required' attribute. If the value is empty and the 'required' attribute is false or not set, then no validation will be taken place.jsf

  • How to implement JavaScript validation in JSF

    Dear all,
    if i wish to implement JavaScript front end validation function in JSF. what should i do?
    thanks.

    Hi,
    in Core JSF from David Geary there is a chapter on using
    Jakarta Commons Validator for javaScript validation
    source could be found here:
    http://www.horstmann.com/corejsf/
    HTH,
    Matthias

  • Question about validating xml against schema

    Hi,
    I am new to JAXP. I try to validating a xml against a schema. I wrote following code:
    SAXParserFactory spf = SAXParserFactory.newInstance();
    spf.setNamespace(true);
    spf.setValidating(true);
    SAXParser sp = spf.newSAXParser();
    sp.setProperty("http://java.sun.com/xml/properties/jaxp/schemaLanguage",
    "http://www.w3.org/2001/XMLSchema");
    sp.setProperty("http://java.sun.com/xml/properties/jaxp/schemaSource",
    "mySchema.xsd") ;
    sp.parse(<XML Document>, <ContentHandler);
    but when compile, it has error: can't resolve ""http://java.sun.com/xml/properties/jaxp/schemaLanguage", and
    "http://java.sun.com/xml/properties/jaxp/schemaSource".
    It seems it didn't support above two property.
    I saw some code in forum is:
    fact.setFeature("http://xml.org/sax/features/validation", true);
    fact.setFeature("http://apache.org/xml/features/validation/schema",true);
    fact.setFeature("http://apache.org/xml/features/validation/schema-full-checking", true);
    SAXParser sp = fact.newSAXParser();
    sp.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",schemas);
    Why sun tutorial use property:http://java.sun.com/xml/properties/jaxp/schemaLanguage
    and someone use:http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation
    where to get information about setting properties for SAXParserFactory?
    Thanks

    In the past, ColdFusion's XML validation mechanism seems to have had issues with schemas that contain imports, e.g., http://forums.adobe.com/message/155906. Have these issues still not been resolved?
    Do you not think that perhaps you're answering your own question here?
    I don't see an issue about this on the bug tracker.  It might be an idea if you can get a simple, stand-alone repro case together and raise an issue (and post the reference back here and against that other thread so people know to vote for it).  If you post the repro case here too, it would be helpful.
    Adam

  • Validation Error - JSF Custom Component

    I am trying to create a Custom Component. It is a pre-populated list of selection items. So all that the page author would have to do is use a tag like
    <jsfcust:mySelectOneComponent  value="#{requestScope.selectedItem}/>and this should display a drop-down list from which only one item can be selected. I got this working except for the final stretch.
    I created the following...
    1. tag in the .tld file
    2. CustSelectOneTag.java (set the value as a ValueBinding in setProperties() method)
    3. CustSelectComponent.java
    4. CustSelectRenderer.java (In the decode() method, called setSubmittedValue(value) on the component)
    5. updated the faces-config.xml file
    The display seems to be working fine. The problem is when I click on a Submit button and go to the next page where I want to display the selected value. It shows up as null. All that I want to do is be able to select an item from the custom drop down and display it in the next page after hitting submit.
    What is the proper way to send the value back in the response? In my case, I was merely trying to pass the value so that the next page can access it from the request scope and display it.
    I was not sure if I had to implement the getConvertedValue() method in my renderer. Can someone help?
    Thanks,
    JM

    Thanks for your reply! Your answer fixed my problems, so definitely thanks! I need to use escaped values for things like "<,&,#, etc", like the pound "amp" semicolon stuff. If I try to type out strings like these the forum unescapes them - fun part of posting forum questions about HTML escaping on HTML-based forums! :) I didn't realize an escaped querystring would still work as expected in a <a href ... />. You actually fixed both of my problems, and I... I do feel appropriately foolish now :) Had a feeling this might be a slaps forehead one. Thanks for the quick answer!,
    Jim

  • Form getting submitted even A4j validation fails +jsf

    i am using a4j for checking username exists or not for onblur event
    it displays the error messages when user already exists but ,if i click on
    submit button after displaying the error message it gets submitted
    when it comes to the required=true for inputtext it doesn't get submitted
    <h:inputText id="firstName" label="#{msg['msg.firstName']}"
                                                            value="#{RegistrationBean.firstName}"                                                        
                                                            required="true" validator="#{RegistrationBean.checkFirstName}">
                                                            <a4j:support event="onblur" reRender="msg" onsubmit="true" oncomplete="true" />                                 
                                                         </h:inputText>
    public void checkFirstName(FacesContext facesContext, UIComponent component, Object value) 
              String name = (String) value;
             if(name.trim().length()==0){
                  System.out.println("Name *******");
                  String message = bundle.getString("Name_Required");
                   FacesContext.getCurrentInstance().addMessage("Reg:firstName",
                         new FacesMessage(FacesMessage.SEVERITY_ERROR, message,message));                    
             if(name.trim().equalsIgnoreCase("tom")){
                  String message = bundle.getString("Name_exists");
                   FacesContext.getCurrentInstance().addMessage("Reg:firstName",
                         new FacesMessage(FacesMessage.SEVERITY_ERROR, message,message));                    
           }could anyone suggest me where i went wrong
    thanks

    bean is configured as request in faces-config and also tried changing to session

  • New to the product - question about validating multiple fields as a group

    I have a static form that I'm building from a word document.  Part of that form requires a person to fill any 3 out 5 text fields.
    Since it looks like scripts are applied on a field by field basis, is it possible to have a script that encompasses multiple fields? 
    Would any script need to be applied to each field in turn?
    Assuming the answer to question 1 is a yes, how would you script it to require x number of fields out of a total of y to have some sort of content in order to validate?
    I'm pretty familiar with JavaScript and am looking at the Scripting reference guides but was hoping for a helping hand to get me there quicker as I'm in a bit of a time crunch - doing 18 forms with validation and database connectivity by January 15 certainly qualifies in my book.
    I would assume you'd do something like this but am unsure of the syntax...
    Get values of each field
    Set a valid counter variable for the number of fields with content
    If field 1 is not empty, increment the valid counter
    (rinse and repeat)
    if the valid counter is less than 3 throw an error message
    Many thanks in advance for any help offiered

    1). Yes, scripting within Livecycle can be for a single field or even static text, images and other artifacts within the PDF. Really anything, within Adobe's reason, when it comes to scripting.
    2). It depends on what you want to do. Things like field validations, calculations and other instances where fields are tied togther really dictate how the script runs.
    3). Fields that have calculations or validations with them work in the same, I believe. So for example I have a PDF that I made that is an Excel-type sheet that contains a few hundred cells and every single one has some type of validation or calculation associated with it. I generally run the calculations/validations from the user inputting the data and then after that the script runs, but again, it really dpeneds on what you are doing and with what, so answering some of your questions are a bit difficult.
    Javascrip/Formcalc are wonderful tools within PDF, but don't forget the Action Builder (Tools -Action Builder). It is a set of preloaded actions that are turn-key. Just select the cells that will have the action and select the result you want from the preloaded list of actions, using those actions can get you very far, and most of all; they are quick to implement without researching code. So for example, you could use the Action Builder to create an action that checks certain fields and if they are null to return a 1 value to a specific numericField (these could be hidden). Then have a "total" numericField (this would be your counter) that adds all of those fields with the 1 in it. Then create another Action Builder for that "total" numericField and if it is less than 3, display a message box that is a warning.

  • How to avoid page validation in JSF / ADF

    In my form I have "cancel" button ( type="reset" ). But when I press it, validation started. But I don't need validation when this button pressed.
    What I can do to avoid validation ?

    You should set the immediate="true" attribute.
    Regards,
    Kati

  • Help me about Initialization in JSF

    Could JSF developers give me a way to call method (ex: obj.init();) once when the first visitor visit my site?
    Many thanks

    3. code just use general jsp and java code(can't work):
    <%
    UserListBean userlistBean = (UserListBean)FacesUtils.getManagedBean("userlistBean");
    int start = userlistBean.getStartPageOfShowPage();
    int end = userlistBean.getEndPageOfShowPage();
    %>
    <%
    for(int i = start; i < end; i ++){
    System.out.println(i);
    %>
    <td>
    <h:commandLink action="#{userlistBean.searchAction}">
    <!-- The follow two lines is wrong. -->
    <h:outputText value="<%=i%>"/>
    <f:param name="pageNo" value="<%=i%>"/>
    </h:commandLink>
    </td>
    <%
    %>
    BTW, I think that JSF must provide a standard iterate or direct use JSTL�s <c:forEach> tag, <h:dataTable> is a nice choice for tabled data but not so good for common var iterate just like my need.
    Someone had told me that oracle' ADF is a choice. but I refuse to use oracle's ADF and like to find a standard and easy way. I think high of simple and independent solution.

Maybe you are looking for

  • Unable to load OS X.3 on iMac G3

    I bought a used iMac G3, 450 mHz, 1 Gig hard drive. It came with 9.2 (which is now gone). I installed X.3 on a tower G3 earlier in the day with 9.2 on it... it went fine. Went to the iMac... put the CD in, go through all the beginning stuff, starts l

  • Start Up / Wake up issues

    I have a refurbished Mac Pro 2.8GHz Quad-Core Intel Xeon . I have had a problem with it sometimes booting up and the screen either is just black or it is all a grey snow . It will do this sometimes when it comes out of sleep as well . If I have a pro

  • Strange error in teststand from labview-vi

    Hello, i have the attached vi "labview.jpg" that i call in Teststand. But: There is see much more error-text what i never set in labview. Where is this text coming from? Thanks Solved! Go to Solution. Attachments: labview.jpg ‏25 KB error2.jpg ‏33 KB

  • ATV totally dysfunctional after 5.1 Update, any ideas?

    I own the MD199LL/A, ATV 1080p. I was prompted to upgrade to 5.1, I did so, and this has caused almost compete failure of the unit. The main menu screen is limited now to "Computers" and "Settings". Restart did not fix. I attempted to Restore, but th

  • Potential maleware

    I updated adobe reader to XI, from the automated updater program, and it installed a .exe file named "iobroltncb" in the directory "C:\Users\xxxxx\AppData\LocalLow\Adobe\Aklngjlpmm".  it keeps opening 20 instances of google chrome processes, and when