我正在尝试从数据库中获取 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>