Using Enter key and space to commit data
<af:clientListener type="keyUp" method="submitTempChanges"/>
<af:serverListener type="AddTempLine" method="#{investBean.addTempLineAction}"/>
<af:clientListener type="keyUp" method="sendByEnter"/>
<af:serverListener type="AddLineByKey" method="#{investBean.addLineByEnterKey}"/>
<af:clientListener method="(function(evt){evt.getSource().getPeer().getDomElement().setAttribute('spellcheck','true');})"
type="focus"/>
</af:richTextEditor>
<af:resource type="javascript">
function submitTempChanges(event) {
var evt = event.getNativeEvent();
if ((evt.which || evt.keyCode) == 32) {
var comp = event.getSource();
var textAreaId = comp.getClientId();
var textAreaFrame = document.getElementById(textAreaId + '::cont');
var textAreaFrameDoc = (textAreaFrame.contentWindow || textAreaFrame.contentDocument);
var frameDocBody = textAreaFrameDoc.document.getElementsByTagName('body')[0];
var compValue = frameDocBody.innerHTML;
AdfCustomEvent.queue(comp, "AddTempLine",
{
tempLineContent : compValue
},
true);
evt.cancel();
}
}
function sendByEnter(event) {
var _keyCode = event.getKeyCode();
if (_keyCode == AdfKeyStroke.ENTER_KEY) {
var evt = event.getNativeEvent();
var comp = event.getSource();
var textAreaId = comp.getClientId();
var textAreaFrame = document.getElementById(textAreaId + '::cont');
var textAreaFrameDoc = (textAreaFrame.contentWindow || textAreaFrame.contentDocument);
var frameDocBody = textAreaFrameDoc.document.getElementsByTagName('body')[0];
var compValue = frameDocBody.innerHTML;
AdfCustomEvent.queue(comp, "AddLineByKey",
{
lineContent : compValue
},
true);
evt.cancel();
}
}
</af:resource>
-------------------------------------------------
public void addTempLineAction(ClientEvent clientEvent) {
if (isNewInvestigation()) {
String tempLineContent = (String) clientEvent.getParameters().get("tempLineContent");
DCIteratorBinding iterator = ADFUtils.findIterator("CaseInvstgLnViewIterator");
iterator.setRangeSize(-1);
RowSetIterator rsi = iterator.getRowSetIterator();
Row lastRow = rsi.last();
int lastRowIndex = 0;
String lastRowStatus = null;
if (lastRow != null) {
lastRowStatus = (String) lastRow.getAttribute("Status");
lastRowIndex = Integer.parseInt(lastRow.getAttribute("LnSeq").toString());
}
if ("TEMP".equals(lastRowStatus)) {
lastRow.setAttribute("LnContent", tempLineContent);
ADFUtils.findOperation("Commit").execute();
} else {
Row newRow = rsi.createRow();
int newRowIndex = lastRowIndex + 1;
newRow.setAttribute("LnContent", tempLineContent);
String statementType = getStatementType(tempLineContent);
newRow.setAttribute("LnType", statementType);
newRow.setAttribute("LnSeq", newRowIndex);
newRow.setAttribute("Status", "TEMP");
System.out.println("last row index +1 is: " + newRowIndex);
rsi.insertRowAtRangeIndex(newRowIndex, newRow);
iterator.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
ADFUtils.findOperation("Commit").execute();
}
} else {
JSFUtils.addFacesErrorMessage(JSFUtils.getStringFromResourceBundle("INVSTG_FREEZ",
"moj.main.view.ZViewControllerBundle"));
}
}
---------------------
public void addLineByEnterKey(ClientEvent clientEvent) {
if (isSendByEnter()) {
if (isNewInvestigation()) {
DCIteratorBinding iterator = ADFUtils.findIterator("CaseInvstgLnViewIterator");
iterator.setRangeSize(-1);
RowSetIterator rsi = iterator.getRowSetIterator();
Row lastRow = rsi.last();
int lastRowIndex = 0;
String lastRowStatus = null;
String javaScriptContent = (String) clientEvent.getParameters().get("lineContent");
System.out.println("javaScriptContent = " + javaScriptContent);
setLineContent(javaScriptContent);
System.out.println("public void addLineByEnterKey: " + getLineContent());
String newLineContent = removeQAChar(getLineContent());
String statementType = getStatementType(getLineContent());
Row newRow = null;
if (lastRow != null) {
lastRowStatus = (String) lastRow.getAttribute("Status");
lastRowIndex = Integer.parseInt(lastRow.getAttribute("LnSeq").toString());
}
if ("TEMP".equals(lastRowStatus)) {
lastRow.setAttribute("LnContent", newLineContent);
lastRow.setAttribute("Status", null);
lastRow.setAttribute("LnType", statementType);
} else {
int newRowIndex = lastRowIndex + 1;
newRow = rsi.createRow();
newRow.setAttribute("LnContent", newLineContent);
newRow.setAttribute("LnType", statementType);
newRow.setAttribute("LnSeq", newRowIndex);
rsi.insertRowAtRangeIndex(newRowIndex, newRow);
iterator.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
}
setLineContent(null);
System.out.println(statementType);
ADFUtils.findOperation("Commit").execute();
AdfFacesContext.getCurrentInstance().addPartialTarget(getScrtinvstgTable());
AdfFacesContext.getCurrentInstance().addPartialTarget(getInvestgRichTextAreaComp());
} else {
JSFUtils.addFacesErrorMessage(JSFUtils.getStringFromResourceBundle("INVSTG_FREEZ",
"moj.main.view.ZViewControllerBundle"));
}
}
}
<af:serverListener type="AddTempLine" method="#{investBean.addTempLineAction}"/>
<af:clientListener type="keyUp" method="sendByEnter"/>
<af:serverListener type="AddLineByKey" method="#{investBean.addLineByEnterKey}"/>
<af:clientListener method="(function(evt){evt.getSource().getPeer().getDomElement().setAttribute('spellcheck','true');})"
type="focus"/>
</af:richTextEditor>
<af:resource type="javascript">
function submitTempChanges(event) {
var evt = event.getNativeEvent();
if ((evt.which || evt.keyCode) == 32) {
var comp = event.getSource();
var textAreaId = comp.getClientId();
var textAreaFrame = document.getElementById(textAreaId + '::cont');
var textAreaFrameDoc = (textAreaFrame.contentWindow || textAreaFrame.contentDocument);
var frameDocBody = textAreaFrameDoc.document.getElementsByTagName('body')[0];
var compValue = frameDocBody.innerHTML;
AdfCustomEvent.queue(comp, "AddTempLine",
{
tempLineContent : compValue
},
true);
evt.cancel();
}
}
function sendByEnter(event) {
var _keyCode = event.getKeyCode();
if (_keyCode == AdfKeyStroke.ENTER_KEY) {
var evt = event.getNativeEvent();
var comp = event.getSource();
var textAreaId = comp.getClientId();
var textAreaFrame = document.getElementById(textAreaId + '::cont');
var textAreaFrameDoc = (textAreaFrame.contentWindow || textAreaFrame.contentDocument);
var frameDocBody = textAreaFrameDoc.document.getElementsByTagName('body')[0];
var compValue = frameDocBody.innerHTML;
AdfCustomEvent.queue(comp, "AddLineByKey",
{
lineContent : compValue
},
true);
evt.cancel();
}
}
</af:resource>
-------------------------------------------------
public void addTempLineAction(ClientEvent clientEvent) {
if (isNewInvestigation()) {
String tempLineContent = (String) clientEvent.getParameters().get("tempLineContent");
DCIteratorBinding iterator = ADFUtils.findIterator("CaseInvstgLnViewIterator");
iterator.setRangeSize(-1);
RowSetIterator rsi = iterator.getRowSetIterator();
Row lastRow = rsi.last();
int lastRowIndex = 0;
String lastRowStatus = null;
if (lastRow != null) {
lastRowStatus = (String) lastRow.getAttribute("Status");
lastRowIndex = Integer.parseInt(lastRow.getAttribute("LnSeq").toString());
}
if ("TEMP".equals(lastRowStatus)) {
lastRow.setAttribute("LnContent", tempLineContent);
ADFUtils.findOperation("Commit").execute();
} else {
Row newRow = rsi.createRow();
int newRowIndex = lastRowIndex + 1;
newRow.setAttribute("LnContent", tempLineContent);
String statementType = getStatementType(tempLineContent);
newRow.setAttribute("LnType", statementType);
newRow.setAttribute("LnSeq", newRowIndex);
newRow.setAttribute("Status", "TEMP");
System.out.println("last row index +1 is: " + newRowIndex);
rsi.insertRowAtRangeIndex(newRowIndex, newRow);
iterator.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
ADFUtils.findOperation("Commit").execute();
}
} else {
JSFUtils.addFacesErrorMessage(JSFUtils.getStringFromResourceBundle("INVSTG_FREEZ",
"moj.main.view.ZViewControllerBundle"));
}
}
---------------------
public void addLineByEnterKey(ClientEvent clientEvent) {
if (isSendByEnter()) {
if (isNewInvestigation()) {
DCIteratorBinding iterator = ADFUtils.findIterator("CaseInvstgLnViewIterator");
iterator.setRangeSize(-1);
RowSetIterator rsi = iterator.getRowSetIterator();
Row lastRow = rsi.last();
int lastRowIndex = 0;
String lastRowStatus = null;
String javaScriptContent = (String) clientEvent.getParameters().get("lineContent");
System.out.println("javaScriptContent = " + javaScriptContent);
setLineContent(javaScriptContent);
System.out.println("public void addLineByEnterKey: " + getLineContent());
String newLineContent = removeQAChar(getLineContent());
String statementType = getStatementType(getLineContent());
Row newRow = null;
if (lastRow != null) {
lastRowStatus = (String) lastRow.getAttribute("Status");
lastRowIndex = Integer.parseInt(lastRow.getAttribute("LnSeq").toString());
}
if ("TEMP".equals(lastRowStatus)) {
lastRow.setAttribute("LnContent", newLineContent);
lastRow.setAttribute("Status", null);
lastRow.setAttribute("LnType", statementType);
} else {
int newRowIndex = lastRowIndex + 1;
newRow = rsi.createRow();
newRow.setAttribute("LnContent", newLineContent);
newRow.setAttribute("LnType", statementType);
newRow.setAttribute("LnSeq", newRowIndex);
rsi.insertRowAtRangeIndex(newRowIndex, newRow);
iterator.setCurrentRowWithKey(newRow.getKey().toStringFormat(true));
}
setLineContent(null);
System.out.println(statementType);
ADFUtils.findOperation("Commit").execute();
AdfFacesContext.getCurrentInstance().addPartialTarget(getScrtinvstgTable());
AdfFacesContext.getCurrentInstance().addPartialTarget(getInvestgRichTextAreaComp());
} else {
JSFUtils.addFacesErrorMessage(JSFUtils.getStringFromResourceBundle("INVSTG_FREEZ",
"moj.main.view.ZViewControllerBundle"));
}
}
}
Comments