2011-04-21 1 views
0

wicket 1.3 CheckBoxMultipleChoice() 메서드를 사용하여 사용자가 프로젝트에 대한 관련 팀을 선택하게합니다. 팀 목록을 데이터베이스에 저장하면 다음과 같이이 세션에 고유 한 식별자를 사용하여 저장됩니다. [[email protected], [email protected], info.tpath.domain.Team @ 1d26ddd, [email protected]]. 선택한 항목의 목록을 도용하여 개체 ID를 저장하는 방법이 있습니까? Team.getId();? 어떤 도움이라도 대단히 감사합니다 ...CheckBoxMultipleChoice SQL에 저장

최대 절전 모드를 사용하여 MS SQL08 DB에 문자열로 팀 목록을 저장하고 싶습니다.

List<Team> choices = new ArrayList<Team>(); 
    for(int i=1;i<5;i++){ 
     for(Team team:getJtrac().findTeamGroup(i)){ 
      choices.add(team); 
     } 
    } 
    CheckBoxMultipleChoice pcrTeamz = new CheckBoxMultipleChoice("pcrTeams", choices, new IChoiceRenderer() { 
     public Object getDisplayValue(Object o) { 
      return ((Team) o).getName(); 
     } 
     public String getIdValue(Object o, int i) { 
      long lTeam = ((Team) o).getId(); 
      return Long.toString(lTeam); 
     } 
    }); 
    add(pcrTeamz); 

폼 태그의 onsubmit()는 아래이다. storeManagementOfChange() 아래에있어서, 상기 dao.storeManagementOfChange (MOC) 단지이 getHibernateTemplate를()를 호출 병합 (MOC)에서

@Override 
    protected void onSubmit() { 
     ManagementOfChange managementOfChange = (ManagementOfChange) getModelObject(); 
     managementOfChange.setStatus(status); 
     managementOfChange.setProject(project); 
     managementOfChange.setLoggedBy(getPrincipal()); 
     getJtrac().storeManagementOfChange(managementOfChange); 
     setResponsePage(new ProjectPage(project, new ManagementOfChangeSubSectionPanel("projectSubSectionPanel",project))); 
    } 

;

<class name="ManagementOfChange" table="management_of_change"> 
    <id column="id" name="id"> 
     <generator class="native"/> 
    </id> 
    <many-to-one column="project_id" index="idx_project_id" name="project" not-null="true"/> 
    <property column="requester" name="requester"/> 
    <property column="phase" name="phase"/> 
    <property column="description" name="description"/>   
    <property column="third_party" name="thirdParty"/> 
    <many-to-one column="entered_by" index="idx_user_id" name="enteredBy" not-null="true"/> 
    <property column="internal_or_external" name="source"/> 
    <property column="change_number" name="changeNum"/> 
    <property column="pcr_number" name="pcrNum"/> 
    <property column="milestone_affected" name="milestoneAffected"/> 
    <property column="new_due_date" name="newDueDate"/> 
    <property column="pcr_group_num" name="pcrGroupingNumber"/> 
    <property column="pcr_title" name="pcrTitle"/> 
    <property column="status" name="status"/> 
    <property column="time_estimate" name="timeEstimate"/> 
    <property column="teams" name="pcrTeams"/> 
    <property column="timestamp" name="timestamp"/> 
    <property column="sow" name="sow"/> 
    <property column="req_date" name="reqDate"/> 
    </class> 
+0

DB에 저장하는 코드는 문제와 관련이 있습니다. –

답변

0

솔루션은 목록 반대로 CheckBoxMultipleChoice에게 목록을 통과 었죠. 그런 다음 선택된 문자열 목록이 세션 객체 식별자 목록 대신 데이터베이스에 병합됩니다. CheckBoxMultipleChoice에서 팀 객체를 추출하는 데 성공한 적이 없었습니다. 누구든지이 일을하는 방법을 알고 있다면 나는 흥미로울 것이다. 감사!

// associated team list ================================================= 
    List<String> choices = new ArrayList<String>(); //init as List<String> 
    for(int i=1;i<5;i++){ 
     for(Team team:getJtrac().findTeamGroup(i)){ 
      choices.add(team.getName()); //extract team names to List<String> 
     } 
    } 
    pcrTeamz = new JtracCheckBoxMultipleChoice("pcrTeams", choices, new IChoiceRenderer() { 
     public Object getDisplayValue(Object o) { 
      return o; 
     } 
     public String getIdValue(Object o, int i) { 
      return o.toString(); 
     } 
    }); 
    add(pcrTeamz); 
1

당신의 CheckBoxMultipleChoice의 모델 객체가 List<Team> 아닌 List<Long>, 그래서 당신은 팀 전체 개체를 지속됩니다

public void storeManagementOfChange(ManagementOfChange moc) { 
     History history = new History(moc); 
     Date now = new Date(); 
     moc.setTimeStamp(now); 
     history.setTimeStamp(now); 
     history.setLoggedBy(moc.getEnteredBy()); 
     if(history.getComment()==null){ 
      history.setComment("Creation of New PCR"); 
     } 
     moc.add(history); 
     SpaceSequence spaceSequence = dao.loadSpaceSequence(moc.project.getProjectId()); 
     moc.setPcrNum(spaceSequence.nextPcr()); 
     // the synchronize for this storeItem method and the hibernate flush() call in the dao implementation 
     // are important to prevent duplicate sequence numbers 
     dao.storeSpaceSequence(spaceSequence); 
     //this call should not be required actually, but the cascase setting has some problem probably 
     //because we are using a polymorphic association between a moc and history. that is why we 
     //are explicitly saving history before actually saving the moc itself. 
     dao.storeHistory(history); 
     // this will at the moment execute unnecessary updates (bug in Hibernate handling of "version" property) 
     // see http://opensource.atlassian.com/projects/hibernate/browse/HHH-1401 
     // TODO confirm if above does not happen anymore 
     dao.storeManagementOfChange(moc); 
     indexer.index(moc); 
     indexer.index(history); 
     mailSender.send(moc, moc.isSendNotifications()); 
    } 

그리고 마지막으로는, 최대 절전 모드 매핑은 다음과 같습니다. 엔티티가 데이터베이스에 제대로 매핑되지 않은 것 같습니다. pcrTeamz.getModelObject()를 유지되지 않습니다,

  1. 이 JPA/JDO 매핑 (권장) 양식의
  2. 제출 수정 :

    난 당신이 몇 가지 옵션을 가지고 같아요. 대신 각 팀 객체에서 ID를 추출하고 그 목록을 유지하십시오. 예를 들어

는 :

List<Long> teamIds = new ArrayList<Long>(); 
for(Team team : pcrTeamz.getModelObject()) { 
    teamIds.add(team.getId()); 
} 
myBO.save(teamIds); 
+0

원본 pcrTeamz 객체가 유지되지 않게하려면 어떻게해야합니까? – OnesAndZeros

+0

pcrTeamz.getModelObject()가 다음과 같은 문자열을 반환합니다. ' "[[[email protected], [email protected], [email protected]]"' 목록이나 팀 객체로 다시 가져올 수 있습니까? – OnesAndZeros