开发者

Why conversion is not skipped?

I have two input components on my page. Each of them has a converter (It's 开发者_开发百科a converter which checks for empty values, like JSF required one, but for some reasons I cannot use jsf one so I've made my own converter).

I also have a ice:selectBooleanCheckbox:

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

As you see I put immediate=true attribute on it, becase when I select this checkbox I do want the conversion phase to be skipped but it does not work, the converters still show their warnings. Do you know why?

I also add a valueChangeListener on this checkbox and called there the renderResponse directly, based on this quote:

So in the value changed listener method for the dropdown lists, just 

call renderResponse() from the FacesContext object and validation and conversion is bypassed and you can still do what you want.

public void addDomainListener(final ValueChangeEvent valueChangeEvent) {
    // skip validation
    logger.info("listener calleddddddddddddd");
    FacesContext.getCurrentInstance().renderResponse();
}

Maybe a JSF guru can help?

Thanks a lot...

UPDATE: I know that a solution would be to put the checkbox in a separate form but I cannot afford this...

UPDATE 2: I've corrected some code about listener, so now it is called when clicked but still the converter fails and render response phase is not done...

UPDATE 3: This is not an icefaces issue... I've tried with a h:selectBooleanCheckbox and it happens the same...


The whole question and the functional requirement behind this all is pretty confusing. Why are you using a converter instead of a validator to validate the inputs? Why are you using a converter/validator if you don't seem to care about the conversion/validation outcome?

As you see I put immediate=true attribute on it, becase when I select this checkbox I do want the conversion phase to be skipped but it does not work, the converters still show their warnings.

Putting the immediate="true" on input components does not skip conversion/validation. They just shifts conversion/validation to an earlier phase (i.e. it takes place in apply request values phase instead of validations phase). You basically need to remove immediate="true" from those inputs and put it on the command link/button in order to skip conversion/validation of those inputs. See also Debug JSF lifecycle:

Okay, when should I use the immediate attribute?

If it isn't entirely clear yet, here's a summary, complete with real world use examples when they may be beneficial:

  • If set in UIInput(s) only, the process validations phase will be taken place in apply request values phase instead. Use this to prioritize validation for the UIInput component(s) in question. When validation/conversion fails for any of them, the non-immediate components won't be validated/converted.

  • If set in UICommand only, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s). Use this to skip the entire processing of the form. E.g. "Cancel" or "Back" button.

  • If set in both UIInput and UICommand components, the apply request values phase until with update model values phases will be skipped for any of the UIInput component(s) which does not have this attribute set. Use this to skip the processing of the entire form expect for certain fields (with immediate). E.g. "Password forgotten" button in a login form with a required but non-immediate password field.


Solved it finally...

I post here the sum up of the question and the solution.

I had a checkbox in my popup. 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...

So, in my ValueChangeListener of the checkbox I had to manually skip the jsf validation phase:

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

            this.addNewDomain = newValue;
            FacesContext.getCurrentInstance().renderResponse();
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜