2013-05-29 4 views
0

SelectOneMenu를 사용하여 먼저이 위치에 건물을 선택하고이 건물에 건물을 짓고이 구역에 건물 및 구역을 배치하십시오. 처음 두 가지 선택은 좋지만 건물을 가져 가면 표시 할 영역이없고 오류가 있습니다. j_idt31 : selectedBld : 유효성 검사 오류 : 값이 유효하지 않습니다. 이유를 모르겠어요, 이것은 XHTML입니다/selectOneMenu 문제 j_idt31 유효성 검사 오류 : 값이 유효하지 않습니다.

:

<h:form> 
    <p:panelGrid columns="2" position="center top"> 
     <h:outputLabel for="selectedLoca" value="#{loc['location']}" /> 
     <p:selectOneMenu value="#{caretakerCautionBean.location}" id="selectedLoca" converter="#{locationConverter}"> 
      <f:selectItem itemLabel="" itemValue="#{null}" /> 
      <f:selectItems value="#{caretakerCautionBean.locationList}" var="loca" itemLabel="#{loca.name}" itemValue="#{loca}"/> 
      <p:ajax update="selectedBld :messages" event="change" process="selectedLoca" listener="#{caretakerCautionBean.locationChanged}" /> 
     </p:selectOneMenu> 
     <h:outputLabel for="selectedBld" value="#{loc['building']}" /> 
     <p:selectOneMenu value="#{caretakerCautionBean.building}" id="selectedBld" converter="#{buildingConverter}"> 
      <f:selectItem itemLabel="" itemValue="#{null}" /> 
      <f:selectItems value="#{caretakerCautionBean.buildingList}" var="bld" itemLabel="#{bld.name}" itemValue="#{bld}" /> 
      <p:ajax update="selectedZone :messages" event="change" process="selectedLoca selectedBld" listener="#{caretakerCautionBean.buildingChanged}" /> 
     </p:selectOneMenu> 
     <h:outputLabel for="selectedZone" value="#{loc['zone']}" /> 
     <p:selectOneMenu value="#{caretakerCautionBean.zone}" id="selectedZone" converter="#{zoneConverter}"> 
      <f:selectItem itemLabel="" itemValue="#{null}" /> 
      <f:selectItems value="#{caretakerCautionBean.zoneList}" var="zone" itemLabel="#{zone.name}" itemValue="#{zone}" /> 
      <p:ajax update="selectedSubZone :messages" event="change" process="selectedLoca selectedBld selectedZone" listener="#{caretakerCautionBean.zoneChanged}" /> 
     </p:selectOneMenu> 
     <h:outputLabel for="selectedSubZone" value="#{loc['cleaningPlanner.tableHeader.subzone']}" /> 
     <p:selectOneMenu value="#{caretakerCautionBean.subZone}" id="selectedSubZone" converter="#{subZoneConverter}"> 
      <f:selectItem itemLabel="" itemValue="#{null}" /> 
      <f:selectItems value="#{caretakerCautionBean.subZoneList}" var="subZone" itemLabel="#{subZone.name}" itemValue="#{subZone}" /> 
      <p:ajax update=":messages" event="change" process="selectedLoca selectedBld selectedZone selectedSubZone" listener="#{caretakerCautionBean.subZoneChanged}" /> 
     </p:selectOneMenu> 
     <f:facet name="footer"> 
      <p:commandButton process="@form" value="#{loc['addComment']}" actionListener="#{caretakerCautionBean.addNewPosition()}" update=":messages" oncomplete="caretakerCautionsDialog.hide()"/> 
     </f:facet> 
    </p:panelGrid> 
</h:form> 

콩 :

@ManagedBean 
public class CaretakerCautionBean { 

    @ManagedProperty(value="#{caretakerCautionRepository}") 
    private CaretakerCautionRepository caretakerCautionRepo; 
    @ManagedProperty(value="#{locationRepository}") 
    private LocationRepository locationRepo; 
    @ManagedProperty(value = "#{buildingRepository}") 
    private BuildingRepository buildingRepo; 
    @ManagedProperty(value="#{zoneRepository}") 
    private ZoneRepository zoneRepo; 
    @ManagedProperty(value="#{subZoneRepository}") 
    private SubZoneRepository subZoneRepo; 
    @ManagedProperty (value="#{userRepository}") 
    private UserRepository userRepo; 
    @ManagedProperty(value="#{userService}") 
    private UserService userSvc; 

    private List<CaretakerCaution> caretakerCautionList; 
    private List<Location> locationList; 
    private List<User> userList; 
    private List<SubZone> subZoneList; 
    private List<Building> buildingList; 
    private List<Zone> zoneList; 
    private Location location; 
    private SubZone subZone; 
    private Building building; 
    private Zone zone; 
    private User user; 
    private String description; 
    private String comment; 
    private String actionsTaken; 
    private int id; 

    private transient Logger logger = Logger.getLogger("aplikacjaLogger"); 

    public void locationChanged(AjaxBehaviorEvent ev) { 
     if(location !=null) 
      logger.log(Level.INFO, "locationChanged: "+location.getName()); 
     buildingList = null; 
     getBuildingList(); 
    } 

    public void buildingChanged(AjaxBehaviorEvent ev) { 
     if(building != null) 
      logger.log(Level.INFO, "buildingChanged: "+building.getName()); 
     zoneList = null; 
     getZoneList(); 
    } 

    public void zoneChanged(AjaxBehaviorEvent ev) { 
     if(zone != null) 
      logger.log(Level.INFO, "zoneChanged: "+zone.getName()); 
     subZoneList = null; 
    getSubZoneList(); 
    } 

    public void subZoneChanged(AjaxBehaviorEvent ev) { 
     if(subZone != null) 
      logger.log(Level.INFO, "subZoneChanged: "+subZone.getName()); 
    } 

    public void addNewPosition() { 
     CaretakerCaution cc = new CaretakerCaution(); 
     cc.setLocation(location); 
     cc.setBuilding(building); 
     cc.setZone(zone); 
     cc.setSubZone(subZone); 
     getCaretakerCautionRepo().save(cc); 
     logger.log(Level.INFO, "Dodano uwage."); 
    } 

    public BuildingRepository getBuildingRepo() { 
     return buildingRepo; 
    } 

    public void setBuildingRepo(BuildingRepository buildingRepo) { 
     this.buildingRepo = buildingRepo; 
    } 

    public ZoneRepository getZoneRepo() { 
     return zoneRepo; 
    } 

    public void setZoneRepo(ZoneRepository zoneRepo) { 
     this.zoneRepo = zoneRepo; 
    } 

    public UserRepository getUserRepo() { 
     return userRepo; 
    } 

    public void setUserRepo(UserRepository userRepo) { 
     this.userRepo = userRepo; 
    } 

    public Building getBuilding() { 
     return building; 
    } 

    public void setBuilding(Building building) { 
     this.building = building; 
    } 

    public Zone getZone() { 
     return zone; 
    } 

    public void setZone(Zone zone) { 
     this.zone = zone; 
    } 

    public User getUser() { 
     return user; 
    } 

    public void setUser(User user) { 
     this.user = user; 
    } 

    public String getDescription() { 
     return description; 
    } 

    public void setDescription(String description) { 
     this.description = description; 
    } 

    public int getId() { 
     return id; 
    } 

    public void setId(int id) { 
     this.id = id; 
    } 

    public List<User> getUserList() { 
     return userList; 
    } 

    public void setUserList(List<User> userList) { 
     this.userList = userList; 
    } 

    public List<Location> getLocationList() { 
     if(locationList == null) 
      locationList = getUserSvc().getLoggedIn().getCaretakenLocations(); 
     return locationList;  
    } 

    public void setLocationList(List<Location> locationList) { 
     this.locationList = locationList; 
    } 

    public List<CaretakerCaution> getCaretakerCautionList() { 
     return caretakerCautionList; 
    } 

    public void setCaretakerCautionList(List<CaretakerCaution> caretakerCautionList) { 
     this.caretakerCautionList = caretakerCautionList; 
    } 

    public SubZoneRepository getSubZoneRepo() { 
     return subZoneRepo; 
    } 

    public void setSubZoneRepo(SubZoneRepository subZoneRepo) { 
     this.subZoneRepo = subZoneRepo; 
    } 

    public List<SubZone> getSubZoneList() { 
     if(subZoneList == null && zone != null) 
      subZoneList = getSubZoneRepo().findByZone(zone); 
     return subZoneList; 
    } 

    public void setSubZoneList(List<SubZone> subZoneList) { 
     this.subZoneList = subZoneList; 
    } 

    public SubZone getSubZone() { 
     return subZone; 
    } 

    public void setSubZone(SubZone subZone) { 
     this.subZone = subZone; 
    } 

    public LocationRepository getLocationRepo() { 
     return locationRepo; 
    } 

    public void setLocationRepo(LocationRepository locationRepo) { 
     this.locationRepo = locationRepo; 
    } 

    public Location getLocation() { 
     return location; 
    } 

    public void setLocation(Location location) { 
     this.location = location; 
    } 

    public List<Building> getBuildingList() { 
     if(buildingList == null && location != null) 
      buildingList = getBuildingRepo().findByLocation(location); 
     return buildingList; 
    } 

    public void setBuildingList(List<Building> buildingList) { 
     this.buildingList = buildingList; 
    } 

    public List<Zone> getZoneList() { 
     if(zoneList == null && building != null) 
      zoneList = getZoneRepo().findByBuilding(building); 
     return zoneList; 
    } 

    public void setZoneList(List<Zone> zoneList) { 
     this.zoneList = zoneList; 
    } 

    public CaretakerCautionRepository getCaretakerCautionRepo() { 
     return caretakerCautionRepo; 
    } 

    public void setCaretakerCautionRepo(
     CaretakerCautionRepository caretakerCautionRepo) { 
     this.caretakerCautionRepo = caretakerCautionRepo; 
    } 

    public UserService getUserSvc() { 
     return userSvc; 
    } 

    public void setUserSvc(UserService userSvc) { 
     this.userSvc = userSvc; 
    } 

    public String getComment() { 
     return comment; 
    } 

    public void setComment(String comment) { 
     this.comment = comment; 
    } 

    public String getActionsTaken() { 
     return actionsTaken; 
    } 

    public void setActionsTaken(String actionsTaken) { 
     this.actionsTaken = actionsTaken; 
    } 
} 

변환기 : 당신은 콩 범위를 지정하지 않은

@Override 
public Object getAsObject(FacesContext fc, UIComponent uiComp, String stringVal) { 
    if(stringVal == null || stringVal.trim().equals("")) return null; 
    else { 
     Integer userId = Integer.parseInt(stringVal); 
     for(Zone zon: this.getZonRepo().findAll()) 
      if(zon.getId() == userId) { 
       return zon; 
      } 
     return null; 
    } 
} 

@Override 
public String getAsString(FacesContext fc, UIComponent uiComp, Object obj) { 
    if(obj == null || obj.equals("")) { 
     return ""; 
    } else { 
     try { 
      return String.valueOf(((Zone)obj).getId()); 
     } catch(ClassCastException cce) { 
      return ""; 
     } 
    } 
} 

public ZoneRepository getZonRepo() { 
    return zonRepo; 
} 

public void setZonRepo(ZoneRepository zonRepo) { 
    this.zonRepo = zonRepo; 
} 
} 
+0

가능한 중복 [유효성 검사 오류 : 값이 유효하지 않습니다] 기본 그것으로 (http://stackoverflow.com/a/9069660/157882) – BalusC

답변

1

, 그래서 기본적으로 RequestScoped입니다. 현재 execute="" 속성없이 AJAX 요청을 수행하고 있으며 기본값은 @this이므로 콩은 데이터의 일부만으로 다시 작성됩니다.

귀하의 경우에는 작업 사이에 값을 유지해야 ViewScoped 또는 SessionScoped을 사용해야합니다.

나는이 같은 ViewScoped를 사용하는 것이 좋습니다 :

@ManagedBean 
@ViewScoped 
public class CaretakerCautionBean { 
    // ... 
} 
+0

'@ RequestScoped'가 아니라'@ NoneScoped'가됩니다. –

+0

@LuiggiMendoza http://www.tutorialspoint.com/jsf/jsf_managed_beans.htm _Scope 주석은 관리 빈이 배치 될 범위를 설정합니다. 범위가 지정되지 않으면 bean은 요청 범위로 기본 설정됩니다. 각 범위는 아래에서 간략하게 논의됩니다. –

+0

@LuiggiMendoza이 예제를 사용하여 테스트 할 수도 있습니다. http://www.gregbugaj.com/?p=126 –

관련 문제