-
1. Re: Validator and outjecting new values
michaelcourcy Sep 8, 2008 1:57 PM (in response to dhaliwal)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
dhaliwal Sep 8, 2008 4:14 PM (in response to dhaliwal)Hello,
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.
Thanks,
Bal. -
3. Re: Validator and outjecting new values
michaelcourcy Sep 8, 2008 8:07 PM (in response to dhaliwal)Yes, for me that's the job of a Convertor.
Then you need to plug your own custom convertor
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 :
@Name("bankAccountConverter") @BypassInterceptors @Converter public class FooConverter implements Converter { @Transactional public Object getAsObject(FacesContext context, UIComponent cmp, String value) throws ConverterException { EntityManager entityManager = (EntityManager) Component.getInstance("entityManager"); entityManager.joinTransaction(); // 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
dhaliwal Sep 11, 2008 12:34 PM (in response to dhaliwal)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.
Thanks,
Balvindar