<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
xmlns:trh="http://myfaces.apache.org/trinidad/html">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1" title="不能正常工作的字数自动统计输入框实验">
<trh:script id="showAutoNum">
var leftLen = 300;
function counterNum2(actionEvent) {
var component = actionEvent.getSource();
var markContent = component.findComponent("markContent");
var content = markContent.getValue();
var usedLen = content.length;
var maxLen = markContent.getMaximumLength();
leftLen = maxLen - usedLen;
var showNum = AdfPage.PAGE.findComponent("showNum");
showNum.setValue("可写 " + leftLen + " 字");
}
</trh:script>
<af:panelSplitter id="ps1">
<f:facet name="first">
<af:panelGroupLayout layout="scroll"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
id="pgl1">
<af:inputText label="备注" id="markContent" rows="10"
clientComponent="true" maximumLength="300">
<af:clientListener type="keyUp" method="counterNum2"/>
</af:inputText>
</af:panelGroupLayout>
</f:facet>
<f:facet name="second">
<af:outputText id="showNum" value="可写 300 字" clientComponent="true"/>
</f:facet>
</af:panelSplitter>
</af:document>
</f:view>
</jsp:root>
<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
xmlns:trh="http://myfaces.apache.org/trinidad/html">
<jsp:directive.page contentType="text/html;charset=UTF-8"/>
<f:view>
<af:document id="d1" title="desc:auto count textarea input demo by using oracle adf framework. author:beanor@gmail.com">
<af:panelSplitter id="ps1" orientation="vertical" collapsed="false"
disabled="true" splitterPosition="200">
<f:facet name="first">
<af:inputText label="备注" id="markContent" rows="10"
clientComponent="true" maximumLength="300"></af:inputText>
</f:facet>
<f:facet name="second">
<af:outputText id="showNum" value="可写 300 字" clientComponent="true"/>
</f:facet>
</af:panelSplitter>
<trh:script id="autoCountInput">
//获取输入框对象,markContent为af:inputText的id
var markContentObj = document.getElementById('markContent::content');
//获取显示字数对象,showNum为af:outputText的id
var showNumObj = document.getElementById('showNum');
//设置输入框背景
markContentObj.style.backgroundColor = "White";
//设置输入框监听函数
markContentObj.onkeyup = function () {
//获取输入框中的字符串
var markContent = markContentObj.value;
//获取输入框中的字符串的长度
var usedLen = markContent.length;
//无法直接获取输入框允许输入的最大数,请保持与af:inputText的maximumLength一致
var maxLen = 300;
//计算还剩余多少字可输入
var leftLen = maxLen - usedLen;
var showNum = showNumObj.innerText;
//设置界面显示剩余的字数
var showMsg = "可写 " + leftLen + " 字";
if (typeof(showNum) == "undefined") {
showNumObj.textContent = showMsg;
} else {
showNumObj.innerText = showMsg;
}
};
</trh:script>
</af:document>
</f:view>
</jsp:root>
因篇幅问题不能全部显示,请点此查看更多更全内容