4 Replies Latest reply on Sep 11, 2008 12:34 PM by Balvindar Dhaliwal

    Validator and outjecting new values

    Balvindar Dhaliwal Newbie


      I am using seam,weblogic, trinidad and richfaces. For an input page, I have fields that I would like validated on the the client side. I am using the f:validator tag, and I have classes that implement the Validator interface. My query is, for any of the fields that I validate, if I derive an additional value in the validate method, validatedValue, how can I outject that value. Since the validator class is not a session bean, the only way I can think of is to put the value in the session. I tried using the binding attribute of f:validator, but the validator class is not being bound, and returns null when checked in the session bean to persist the data to db. Please advise.


        • 1. Re: Validator and outjecting new values
          Michael Courcy Newbie

          I think there's a design problem there, the process of validation should not change your model.

          Do you agree ? Are you not trying to convert a value in something else ? 

          • 2. Re: Validator and outjecting new values
            Balvindar Dhaliwal Newbie


            In the validation phase, some fields are transformed as part of the validation, ie accountString to account Object. If the validation phase succeeds, then the Invoke application phase calls the relevant method on the Session bean to create the relevant object in the database. I would like to use the account object (as well as other objects generated from validate calls) on relevant method on the session bean. If the validation fails, the page is rendered with the error msgs using the values from the Object tree.

            I am including client and some business validation under the validation phase, in order to make the client useablity more smoother, all errors appear on page for a request, as opposed to having to submit the page many times to see all the errors.


            • 3. Re: Validator and outjecting new values
              Michael Courcy Newbie

              Yes, for me that's the job of a Convertor.

              JSF basic lifecycle diagram

              Then you need to plug your own custom convertor

              getAsObject, getAsString custom converter methods

              In the case of a bank account you need a custom BankAccountConverter.

              The good news here is that you're working with seam and seam allow you to register converter as a  seam component.

              Let's write the one for your use case :

              public class FooConverter implements Converter {
                public Object getAsObject(FacesContext context, UIComponent cmp, String value)
                throws ConverterException
                  EntityManager entityManager = (EntityManager) Component.getInstance("entityManager");
                  // Do the conversion
                  // and return the bank account object .... 
                  //eventually throw a converter exception
                public String getAsString(FacesContext context, UIComponent cmp, Object value) {
                  // Do the conversion

              and in the view

                            <h:inputText converter="#{bankAccountConverter}" value="#{myBean.bankAccount}" />

              Thus the idea is here is not to build an extra validatedValue in the model but rather bind directly it to the model.

              • 4. Re: Validator and outjecting new values
                Balvindar Dhaliwal Newbie

                Hi Michael,

                Thanks for your suggestion of using converters, it is exactly what I needed and it works correctly. With regards to the Seam Converter class, what is the best way to inject or lookup a local Stateless session bean in the converter class. At the moment, I am looking it up remotely but it would be better to get a handle to it locally.