微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PrimeFace JSF中使用ajax控件无法实时更新文本框inputTextarea内容

PrimeFace+JSF实际工作需要点击一个树将关联的文本添加到inputTextarea文本框,inputTextarea允许用户随意更改,ajax绑定树的select事件,但点击时,后台Bean对象无法实时获取前台文本框改变的实际内容

wKioL1Xfv2TTC2k-AABKs_U6Mvo654.jpg


原因估计ajax控件无法将前台文本框数据关联到后台


解决方案:

添加一个按钮和文本框鼠标事件,事件JS调用按钮click事件,由按钮将文件夹数据同步到后台


前台代码

 
<script>
	functioncallButton(){
		document.getElementById("first:tj").click();
	}
</script>


<h:form>
	<h:inputHiddenvalue="#{inputRule.init}"/>
</h:form>

<h:formid="first">
	<h:panelGrid>								
		<p:inputTextarearows="5"cols="50"id="bigout"value="#{inputRule.text}"onmouSEOut="callButton()">
		</p:inputTextarea>
		
		<p:treevalue="#{inputRule.sgnrRoot}"var="node"selection="#{inputRule.sgnrNode}"selectionMode="single"style="width:215px;height:150px;border:0;">
			<p:treeNodeexpandedIcon="ui-icon-folder-open"collapsedIcon="ui-icon-folder-collapsed">
					<h:outputTextvalue="#{node}"style="display:none;"/>
					<h:outputTextvalue="#{node}"/>
			</p:treeNode>
			<p:ajaxevent="select"listener="#{inputRule.addInputString}"update="@form"/>
		</p:tree>
		
		<p:commandButtonvalue="提交"id="tj"style="display:none">
		</p:commandButton>
	</h:panelGrid>
</h:form>


后台代码

@ManagedBean(name="inputRule")
@SessionScoped
publicclassInputRuleimplementsSerializable{
	//施工常用语tree操作定义区
	privateTreeNodesgnrRoot;//施工内容root
	privateTreeNodesgnrNode;//选择某条内容常用语
	privateList<String>nrcyyList=newArrayList<String>();//内容常用语所有对象
	
	publicStringgetinit(){
		sgnrRoot=newDefaultTreeNode("Root",null);
		nrcyyList.clear();
		nrcyyList.add("a");
		for(Stringstr:nrcyyList){
			TreeNodesgxm=newDefaultTreeNode(str,sgnrRoot);
		}
		returnnull;
	}
	
	
	
	privateStringtext="";

	publicStringgetText(){
		returntext;
	}

	publicvoidsetText(Stringtext){
		this.text=text;
	}
	
	publicvoidaddInputString(){
		text+="测试1,";
	}
	
	publicvoidgetInputString(){
		Stringa=text;
	}
}

原文地址:https://www.jb51.cc/ajax/162965.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐