JSF其他功能二级联动

来源:互联网 发布:打lol网络不稳定 编辑:程序博客网 时间:2024/04/29 13:37

GLP调查表 其他联动功能设计思路

 

实现功能:

1:选择下拉框中的其他项,文本域出现;选择的是非其他项,文本徐消失。

 

2:如果下拉框的值在下拉项中没有匹配到,下拉框的值显示为其他,真正的值显示在输入框中。

 

 

实现方法:

 

function showQita(obj,number) {

if(obj.value=='other'){                      

document.getElementById("organizationForm:"+number).style.display = "block";

}else{

document.getElementById("organizationForm:"+number).style.display = 'none';

}

}

 

使用HTML DOM 的形式改变输入框的显示特性,实现功能1

 

 

if(org.getKind().equals("other")) {

org.setKind("other"+org.getOtherKind());

}

 

控制值在数据库中的保存形式,如果不是下拉框中的固定项,则保存为other+实际值的形式。

 

if(organizationModel.getKind().indexOf("other")!=-1) {

//截取自定义机构性质other后的值,赋值给otherKind     organizationModel.setOtherKind(organizationModel.getKind().substring(5, organizationModel.getKind().length()));  

organizationModel.setKind("other");

 

修改数据库值在model中的保存格式,如果包含other,就将kind修改为other,这样下拉框就会显示为其他,真正的值将通过字符串截取保存在otherKind中,用来在输入框中进行显示。实现如果下拉框的值在下拉项中没有匹配到,下拉框的值显示为其他。

 

 

 

 

<f:verbatim>

<c:if test="${organizationForm.organizationModel.kind=='other'}">

<script>

document.getElementById("organizationForm:other").style.display='block';                                 

</script> 

</c:if>                 

</f:verbatim>

 

通过model中值的加工,如果包含other,输入框的的显示特性就会改变,实现真正的值显示在输入框中。

 

 

 

改进:(未测试)

<a4j:support action="#{organizationForm.refreshCities}" event="onchange" reRender="city"></a4j:support>

 

用联动的方式改变输入框的显示特性。rendered="true"属性控制输入框是否显示。

 

 

 

药物试验专业码表中

 

下拉框下的下拉项动态抓取数据库生成,如果无合适,选择其他,输入框中输入后,将这个值插入到数据库中,这样就减少了,程序执行中判断输入框是否显示的代码