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;
	}
}

相关文章

IE6是一个非常老旧的网页浏览器,虽然现在很少人再使用它,但...
PHP中的count()函数是用来计算数组或容器中元素的个数。这个...
使用 AJAX(Asynchronous JavaScript and XML)技术可以在不...
Ajax(Asynchronous JavaScript and XML)是一种用于改进网页...
本文将介绍如何通过AJAX下载Excel文件流。通过AJAX,我们可以...
Ajax是一种用于客户端和服务器之间的异步通信技术。通过Ajax...