jsf (richfaces) readonly input text validation [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-18 04:54:14

问题


Is there any way I can validate a jsf input text that is readonly but the value is changed upon some other events triggered?


回答1:


Set the readonly attribute to true only during render response phase. This way it won't be seen as readonly in all other phases than the render response phase.

<h:inputText ... readonly="#{facesContext.currentPhaseId.ordinal eq 6}" />



回答2:


Answering from comment: "Woudn't it be easier to validate it in the jsf page backing bean?" You can do application-level validation on a button click or some similar event. You can do something like this in your backing bean and link it to the event.

public String login(){
        FacesContext context = FacesContext.getCurrentInstance();
        if(**<<some validation for value in field 'firstName' in form 'userForm'>>**){
            FacesMessage message = new FacesMessage();
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            message.setSummary("Some Valication check");
            message.setSummary("Some Valication check!!");
            context.addMessage("userForm:firstName", message);//adds validation message for field firstName in form userForm
            return "ERROR";
        }
        return "SUCCESS";
    }

Hope this helped.




回答3:


I have solved this problem with a workaround. I have added an inputHidden field that has the required attribute true that will not appear on the interface, but will be validated:

<h:inputHidden value="#{bean.value}" required="true"
                    requiredMessage="Data must be entered" />

The value of bean.value is changed by other event, and at some reRender on the inputHidden, the validation takes place.




回答4:


You will most likely have to manually call the validation logic directly from your event. Here is a model of the JSF lifecycle from IBM.

You will notice that Process Validations phase occurs before the Invoke Application phase where events are typically handled. This occurs well after so validation will not occur automatically.



来源:https://stackoverflow.com/questions/9614706/jsf-richfaces-readonly-input-text-validation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!