h:selectoneradio validation error [duplicate]

99封情书 提交于 2019-12-11 12:37:41

问题


Please, help me to tackle with next matter. I have error "requestAccess:selectAccess: Validation Error: Value is not valid" when submit form.

<h:form id="requestAccess">
 <h:selectOneMenu id="orgList" value="#{requestAccessBean.currentOrg}">
<f:selectItem itemLabel="-- select --"   itemValue="null" />
<f:selectItems value="#{requestAccessBean.orgList}" />
<f:ajax event="change" execute="@this" render="selectAccess"/>
 </h:selectOneMenu>

<h:selectOneRadio id="selectAccess" valueChangeListener="#          {requestAccessBean.accessChanged}" value="#{requestAccessBean.currentAccess}" layout="pageDirection">
<f:selectItems value="#{requestAccessBean.accessList}" />
 </h:selectOneRadio>
</h:form>
@ManagedBean(name = "requestAccessBean")
public class RequestAccessSection {

private List<SelectItem> accessList;
private List<SelectItem> orgList;  
private String currentOrg,currentAccess;

public void accessChanged(ValueChangeEvent event) {
 this.currentAccess = event.getNewValue();  
}

 public List<SelectItem> getAccessList() {    
  if (this.accessList == null) {
   this.accessList = returnAccessList();
  }
  return this.accessList;
}

public List<SelectItem> getOrgList() {
 if (this.orgList == null) {
   this.orgList = returnOrgList();
 }
 return this.orgList;
}

public List<SelectItem> returnOrgList() {
  List<OrgUnit> orgList = new ArrayList<OrgUnit>();
  List<SelectItem> selectItemsOrgList = new ArrayList<SelectItem>();
  orgList = getBusinessDelegate().getOfficeBranches();        
    for(OrgUnit org : orgList){
    selectItemsOrgList.add(new SelectItem(org.getGlobalid(), org.getOu()));
 }
 return selectItemsOrgList;
}

public List<SelectItem> returnAccessList() {
  List<String> accessList = new ArrayList<String>();
  List<SelectItem> selectItemsAccessList = new ArrayList<SelectItem>();    
  String userId = (String) getSessionMap().get(USER_ID_KEY);     
  accessList = getBusinessDelegate().getAccessList(userId, this.currentOrg);    
  if(accessList!=null){  
    for(String access : accessList){
      selectItemsAccessList.add(new SelectItem(access, access));
  }    
 }  
 return selectItemsAccessList; 
}

public String goToOrderAccessPage(){   
  return "orderaccess.jsf";
 } 
}

Previously, i have orgList and accessList of String type, and validation error still exists. Could someone help me? Thanks in advance!

UPDATE: I change type of currentAccess to SelectItem and add attribute immediate="true" to command button but valueChangeListener method is not called.


回答1:


Validation Error: Value is not valid

You will get this error when the submitted value does not match any of the available select items. In other words, the <f:selectItems> didn't return exactly the same items during the form submit as it did during the form display.


I change type of currentAccess to SelectItem

This is wrong. It should be the same type as the value property of SelectItem.


and add attribute immediate="true" to command button but valueChangeListener method is not called.

You don't need the valueChangeListener in this particular case. In the listener method you're just duplicating what JSF is already doing during update model values phase. Get rid of it. I have also the impression that you really don't need immediate="true" here. Remove it as well.



来源:https://stackoverflow.com/questions/6647316/hselectoneradio-validation-error

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