[jboss-user] [JBoss Seam] - AJAX4JSF: Problems with validation.

bfo81 do-not-reply at jboss.com
Wed Sep 13 11:15:40 EDT 2006


First of all: Yes I know, this isn't a pure Seam topic and it usually doesn't belong here. BUT

1. There are 2 weeks left for me to solve this single issue. If I don't suceed I'll have to fallback to static stuff :(. have mercy with me ;).
2. The Exadel forum is quite empty, and the forum here is full of experts.
3. Using Seam and AJAX4JSF together is quite interesting, since both enable you to easily create great webapps. They complement one another, and many Seam developers might encounter the same prob.


Ok, now the prob: I have the following code:

  | What are you interested in?
  | <h:selectOneMenu value="#{bean.interested}" required="true">
  |     <f:selectItems value="#{backingBean.interestedOptions}" />
  |     <a4j:support event="onchange" reRender="menu2" ajaxSingle="true" />
  | </h:selectOneMenu>
  | 
  | And which is your favourite?
  | <h:selectOneMenu id="menu2" value="#{bean.favourite}" required="true">
  |     <f:selectItems value="#{backingBean.favouriteOptions}" />
  | </h:selectOneMenu>
  | 
  | Your name?
  | <h:inputText value="#{bean.name}" required="true" />

You can see that I have 3 inputs and they all require to be filled. The second selectOneMenu is initially empty, since the choices depend on what you select in the first menu.

Simple Example:

- You select "hockey" in menu 1, and then menu 2 offers a list of hockey teams.
- You select "cars" in menu 1, menu 2 offers car brands etc.

Those updates shall be done via AJAX4JSF.

Every select menu has a top (invalid) entry "---" to show the user that he should select something here. It's important that there aren't any pre-selected entries since this might lead to accidently chosen but unwanted options.

Ok, now my problem: Whenever menu 1 is changed, AJAX4JSF submits the menu 1 selection and starts the complete JSF lifecycle including validation... for ALL input fields. And if validation fails, the AJAX update does not succeed and everything remains like it was.

Scenario 1: I use ajaxSingle="true" to submit only the changed selection. Then validation will fail since there's no value submitted for the second select menu. (Plus: if there is any field marked invalid during a previous form submit, it stays invalid and causes a validation fault here, too).

Scenario 2: I don't use ajaxSingle="true" and all fields of the form are submitted upon selection change in menu 1. Then validation will fail, too, if there is any empty or invalid field. And this might occur very often, since you can't force a user to first fill in all text fields and then perform selection.

Any scenario will drive the user mad - and me, too ;). And it's not only this select menu possibility. There are many other real life application situations where a AJAX4JSF request might fail.

Long explanation, short conclusion: I'd need a way to prevent JSF to validate any field other then the changed one. Skipping the whole validation during AJAX processing would be nice, too (unfortunately there's no immeditate="true" like in JSF action commands... well ok, there is such an attribute, but it has a completely different meaning).

I could completely leave out JSF validation here and put it in my business logic (if something is not filled in correctly, I add a message and redisplay the page)... but hey, that's crazy ;).

Soooo... anyone out there... experienced with this problem? Solved it? Give me a hint ;).

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3971290#3971290

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3971290



More information about the jboss-user mailing list