【发布时间】:2014-06-09 14:49:44
【问题描述】:
JSF 代码。
<ice:inputText id="txtemailFrom" required="true"
requiredMessage="please enter proper value in From Address field" value="#{emailBean1.sender}" maxlength="100" size="40">
<f:validator validatorId="emailValidator" />
</ice:inputText>
<ice:selectOneRadio id="emailType"
value="#{emailBean1.currentEmailType}"
valueChangeListener="#{emailBean1.onEmailTypeChange}"
partialSubmit="true"
style="margin-left:95px">
<f:selectItem itemLabel="Do Not Reply" />
<f:selectItem itemLabel="User's Email" />
<f:selectItem itemLabel="Custom Email" />
</ice:selectOneRadio>
验证器的java代码:
public void onEmailTypeChange(ValueChangeEvent event) {
logger.debug(new LogEntry(" EmailBean.onEmailTypeChange() execution is started."));
String emailType = event.getNewValue().toString();
FacesContext context = FacesContext.getCurrentInstance();
this.setUserEmailId(roleHandler.getUserId() + "@xxx.com");
HtmlInputText txtComponent = (HtmlInputText) Utils.findComponent(
context.getViewRoot(), "txtemailFrom");
if (emailType.equals("Do Not Reply")) {
this.setEmailFrom("donotreply@fedex.com");
txtComponent.setValue("donotreply@fedex.com");
} else if (emailType.equals("User's Email")) {
this.setEmailFrom(this.getUserEmailId());
txtComponent.setValue(this.getUserEmailId());
} else if(emailType.equals("Custom Email")){
this.setEmailFrom("");
txtComponent.setValue("");
}
logger.debug(new LogEntry(
" EmailBean.onEmailTypeChange() execution is ended."));
}
当我更改单选按钮值时,它会更新 fromEmailaddress 的 inputTextField 中的值。我正在使用此代码通过 java 更新值。
HtmlInputText txtComponent = (HtmlInputText) Utils.findComponent(
context.getViewRoot(), "txtemailFrom");
但是我的问题就像我在更改单选按钮时对 inputtext 字段使用验证器,如果电子邮件无效,那么它会失败并显示错误消息。它按照 jsf 方法工作,但根据我的要求,它应该更改电子邮件 inputTextFied 中的值。我尝试了 immediate="true" 然后跳过验证阶段,但没有将值更新到 Emailtextfield 中。
【问题讨论】:
-
如果我的解释不充分,请评论
-
不要分享客户详细信息 "@fedex.com" ;)
-
是 onEmailTypeChange 你提到的验证器吗?
-
不,这是我在代码中提到的 valueChangListener
-
你能试着在
标签: java validation jsf icefaces