0

我正在尝试从数据库中获取 varchar 消息,以在 jsp 中显示患者用药剂量频率的复选框字段的选定值。可能的值将保存在 varchar 中以逗号分隔的字符串中。对于大多数表单字段,只有一个表单值与一个数据库字段的比率,但在这种情况下,我需要将作为字符串 [] 出现的值合并到逗号分隔的字符串中,然后在检索该记录时该患者的药物,显示从逗号分隔的字符串中选择的值,这些值是从 selectableDosageFrequencyList 中选择的。

非常感谢您在这方面的帮助,因为我不确定我在这里缺少什么。

在应用程序上下文中,我创建了可能值列表作为 ServiceBean 的一部分。

    <property name="selectableDosageFrequencyList">
        <set>
            <value>On an empty stomach</value>
            <value>Every other day</value>
            <value>4 times daily</value> 
            <value>3 times daily</value>
            <value>Twice daily</value>
            <value>At bedtime</value> 
            <value>With meal</value>
            <value>As needed</value>
            <value>Once daily</value>               
        </set>
    </property>

这在流程中设置为 requestscope。

<view-state id="addEditMedication" model="medication">

    <on-render>
        <set name="requestScope.selectableDosageFrequencyList" value="memberService.buildSelectableDosageFrequencyList(patient)" />     
    </on-render>
...
    <transition on="next" to="assessment" >
        <evaluate expression="memberService.updateMedication(patient, medication)" />
    </transition>
</view-state>

我在 memberService 中有辅助方法,需要在表单初始化时执行,然后在表单完成时执行。

    //get the form fields selected and build the new string for db
public String setSelectedDosageFrequency(String [] dosageFrequencies){
    String frequencies = null;
    if (dosageFrequencies != null){
        for (String s : dosageFrequencies){
            frequencies = frequencies + "," + s;
        }
    }
    return frequencies;
}
//get value from database and build selected Set
public LinkedHashSet<String> getSelectedDosageFrequencyList(String dosageFrequency){
    String copyOfDosages =dosageFrequency;//may not need to do this
    LinkedHashSet<String> setofSelectedDosageFrequency = new LinkedHashSet<String> ();
    while (copyOfDosages!= null && copyOfDosages.length()>0){
        for (String aFrequency: selectableDosageFrequencyList){
        if (copyOfDosages.contains(aFrequency)){
            setofSelectedDosageFrequency.add(aFrequency);
            if (!copyOfDosages.equals(aFrequency) && copyOfDosages.endsWith(aFrequency)){
                copyOfDosages.replaceAll(","+aFrequency, "");       
            }else if (!copyOfDosages.equals(aFrequency) && copyOfDosages.contains(aFrequency=",")){
                copyOfDosages.replaceAll(aFrequency+",", "");
            }else
                copyOfDosages.replaceAll(aFrequency, "");
            copyOfDosages.trim();
        }
        }
    }   
    return setofSelectedDosageFrequency;        
}

支持表单的药物类将有一个剂量频率变量作为字符串。

private String dosageFrequency;

我目前正在这样做的jsp。

        <div class="formField">
            <form:label path="dosageFrequency">Dosage Frequency</form:label>
            <ul class="multi-column double" style="width: 550px;">
                <form:checkboxes path="dosageFrequency" items="${selectableDosageFrequencyList}" itemLabel="${selectableDosageFrequencyList}" element="li" />
            </ul>
        </div>  
4

1 回答 1

0

在看了这个之后,我有一个解决方案,希望这可以帮助其他有类似问题的人。哦,将分隔符更改为空格 '' 而不是 , :

webflow 和应用程序上下文没有改变,但是因为视图状态 id="addEditMedication"... 使用 initMedication(patient) 方法转换到视图状态,而视图状态的转换使用 memberService.updateMedication(病人,医生)。我更新了 memberServiceImpl :

@Override
public Medication initMedication(PatientInformation patient, int index) {
    ServiceUtils.assertNotNull("A patient is required", patient);
    Medication medication = patient.getMedicationList().get(index);
    medication.setDosageFrequencySet(
                  convertSelectedDosageFrequencyList(medication.getDosageFrequency()));
    return medication;
}

@Override
public void updateMedication(PatientInformation patient, Medication medication) {
    if (!patient.getMedicationList().contains(medication)){
        medication.setDosageFrequency(
               convertSelectedDosageFrequency(medication.getDosageFrequencySet()));
        patient.getMedicationList().add(medication);
    }
}

private String convertSelectedDosageFrequency(LinkedHashSet<String> dosageFrequencies){
    String frequencies = StringUtils.join(dosageFrequencies," ");
    return frequencies;
}

private  LinkedHashSet<String> convertSelectedDosageFrequencyList(String dosageFrequency){
    String copyOfDosages =dosageFrequency;
    LinkedHashSet<String> setofSelectedDosageFrequency = new LinkedHashSet<String> ();
    if  (copyOfDosages!= null && copyOfDosages.length()>0){
        for (String aFrequency: selectableDosageFrequencyList){
        if (copyOfDosages.contains(aFrequency)){
            setofSelectedDosageFrequency.add(aFrequency);
            copyOfDosages = copyOfDosages.replaceAll(aFrequency, "");
            copyOfDosages = copyOfDosages.trim();
        }
        }
    }   
    return setofSelectedDosageFrequency;        
}

药物类更新为:

private String dosageFrequency;
private LinkedHashSet<String> dosageFrequencySet;
//hibernate mapped
public String getDosageFrequency() {
    return dosageFrequency;
}
public void setDosageFrequency(String dosageFrequency) {
    this.dosageFrequency = dosageFrequency;
}
public LinkedHashSet<String> getDosageFrequencySet() {
    return dosageFrequencySet;
}
public void setDosageFrequencySet(LinkedHashSet<String> dosageFrequencySet) {
    this.dosageFrequencySet = dosageFrequencySet;
}

jsp更新为

        <div class="formField">
            <form:label path="dosageFrequency">Dosage Frequency</form:label>
            <ul class="multi-column double" style="width: 550px;">
                <form:checkboxes id="dosageFrequencySet" path="dosageFrequencySet" items="${selectableDosageFrequencyList}" element="li" />
            </ul>
        </div>
于 2013-06-18T19:39:34.897 回答