Ajax4jsf validation

Hello all,

I have a JSF webapp and I use ajax4jsf to put some Ajax capability, I have a few problematic issues.

I use popup forms, I want to load the content of the form dynamically

With Ajax (not iframe) but I had problem with that so eventually I used <jsp:include... and just change the container div style (display).

I work not as pretty as I wanted but it does. My problem is with the validations, I want to close (hide) the popup if the form submitted successfully.

The form rerender some areas in the main page.

I抦 new to JSF and from what I saw, the popup subject is problematic.

I抳e looked at some frame works like http://www.jenia.org/ and I use tomahawk but the popup solution they suggest is far from perfect.

Is there a nice "clean" popup solution in JSF+ajax4jsf?

Thanks>

[852 byte] By [Choyoa] at [2007-11-26 13:51:01]
# 1

Hi, let me try to answer your question.

Firstly, I do not think that Ajax4JSF can rerender a page other than itself. Rerendering in A4J can only be used to rerender ids within the same JSP page. Correct me if I am wrong..

However, for the question, I think you can solve it with Javascript.

Step 1.

Use the following JSF tag to pop-upthe Form and at the same time, call a method to alter whatever is necessary in the backing-bean. The Form should appear dynamically according to what your method does

<h:commandLink target="_blank" value="Your Form" action="#{ManagedBean.alterTheFormMethodAndThenPopUpTheForm}"/>

Step 2.

On the popped up window (with the form), do all validation checks on that new window itself. Only when the form inputs are successful, you call a Javascript to REFRESH the originating window which called out the form.

That should be it. I hope I answered your question. Do reply in here if you need further assistence.

justinlima at 2007-7-8 1:28:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks for the replay

I do have some more questions.

1. How can I detect if form was submitted successfully with no validation errors?

2. I have a problem with a4j and validation, if there is a validation error and the user cancel the operation, the next time he open the form, the non validated field/s are empty. All fields?values are taken from backing bean.

3. What is the deferent between action and action listener?

4. last question, if I have a form to add new item, is it right to bind the input field to backing bean instead of set the value attribute ?

I knew a lot of questions...

Thanks :)

Choyoa at 2007-7-8 1:28:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

> I do have some more questions.

>

> 1. How can I detect if form was submitted

> successfully with no validation errors?

If an validation error (ValidatorException) occurs, then the INVOKE_ACTION phase will be skipped and therefore the definied action method will never be invoked.

> 2. I have a problem with a4j and validation, if there

> is a validation error and the user cancel the

> operation, the next time he open the form, the non

> validated field/s are empty. All fields?values are

> taken from backing bean.

Sounds like the bean is request scoped. Is this true?

> 3. What is the deferent between action and action

> listener?

The method behind the actionListener methodbinding must have an ActionEvent parameter.

> 4. last question, if I have a form to add new item,

> is it right to bind the input field to backing bean

> instead of set the value attribute ?

This depends on the design and functionality requirements. It is "clean" to use just the valuebinding.

BalusCa at 2007-7-8 1:28:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
thanks for the replay,1. but how in in the jsp page i can check if there was validatorexception ?2. you are right the bean scope is request, should i change it to session ?thanks
Choyoa at 2007-7-8 1:28:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

1. Tricky .. You can try to use a boolean property. In the validator you can access the managed bean by FacesContext and then set the property.

2. If you want to keep the same instance of the backing bean during the whole session, then yes. But this might affect other parts of the application, if any. Keep this in mind.

BalusCa at 2007-7-8 1:28:05 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...