Skip to content

Checkbox – skip validation on value changed

June 16, 2011

Back to a new post after some break…

This time with a very strange situation…Please note that this post can save you about 2 hours of headache if you have the same problem like me.

The problem:

I had an ice:selectBooleanCheckbox checkbox in my page. When I select it I want to show some hidden fields but this did not work because I also had two required fields on the same page so jsf PROCESS_VALIDATIONS phase came up…

I thought that putting immediate=true will solve this, but it did not…

<ice:selectBooleanCheckbox
						styleClass="graUserAppUserGroupAddChk"
						value="#{userGroupTableNewRecordBean.addNewDomain}"
						partialSubmit="true"
						immediate="true"
						valueChangeListener="#{userGroupTableNewRecordBean.addDomainListener}">
					</ice:selectBooleanCheckbox>

The solution:

You have to play with jsf phases in your value change listener. In my case this is what I’ve done:

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
		final PhaseId phaseId = valueChangeEvent.getPhaseId();
		final Boolean newValue = (Boolean) valueChangeEvent.getNewValue();
		// skip validation
		if (phaseId.equals(PhaseId.ANY_PHASE)) {
			valueChangeEvent.setPhaseId(PhaseId.UPDATE_MODEL_VALUES);
			valueChangeEvent.queue();
			this.addNewDomain = newValue;
			FacesContext.getCurrentInstance().renderResponse();
		}
	}

“Easy, isn’t it?”

“Yeah, when you already have an example… :)”

Advertisements

From → Icefaces

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: