开发者

h:selectoneradio validation error [duplicate]

This question already has answers here: Validation Error: Value is not valid (3 answers) Closed 6 years ago.

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. 开发者_StackOverflow社区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.


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜