制作 JSF 按钮,其行为类似于 "Backspace" 和 "Enter" 键的输入文本区域?



更新:我在这里更新是为了清楚起见,而不是写评论或做一个回答帖子。

这是这些按钮将如何操作的代码的一部分:

我做了这样的按钮:

  <h:commandButton value="Delete"  onclick="return addBackspace();">
                    <f:ajax execute="@form" render="formula"/>
                </h:commandButton> //the backspace button
textArea:

 <h:inputTextarea id="formula" value="#{output.formula}" /> 

我做了一些简单的按钮,这些按钮会将它们的值写入textArea,这样用户在构建公式时就可以看到公式:

 <h:commandButton value="+ "  onclick="return checkButtons(this.value);">                   
                    <f:ajax execute="@form" render="formula"/>
                </h:commandButton>

我不完全确定我放在那里的ajax部分,用它来阻止每次点击页面刷新。

我使用的selectBoxes现在有一些硬编码的值,但最终将填充从WS获取的数据。

 Property:
                <h:selectOneMenu  value ="#{output.propertyReferenceValue}" id="selectTwo" onchange="return checkItem(this.value);">    
                    <f:selectItems value="#{property.propertyReference.keySet()}"/> 
                </h:selectOneMenu>

现在,如果我使textArea禁用或只读,我仍然能够在其中编写selctBoxes的内容(这很好),但如果我尝试像"+"这样的简单按钮,它们的值将很快出现,然后消失得同样快。如果我尝试退格,它会删除整个文本区域的内容,同样的,如果我把一些内容的选择框在文本区域,然后如果我点击"+"按钮(例如),整个区域的内容将被删除。我仍然在深入研究代码,看看是什么使它以这种方式运行:)

END OF UPDATE

是否有可能在JSF中制作一些命令按钮,这些按钮将在inputTextArea上操作,就像"Enter"one_answers"Backspace"键一样?例如:

当按下"回车键"时,光标将移动到textArea的新行。"退格键"将删除光标后面的下一个字母或空格。

我一直在寻找一段时间,但我似乎只找到如何使所有的文字消失的细节。

谢谢,丹尼尔

你可以直接使用JavaScript。

<h:inputTextarea id="textarea" binding="#{textarea}" value="#{bean.text}" />
<input type="button" value="Enter" onclick="addEnter('#{textarea.clientId}')" />
<input type="button" value="Backspace" onclick="addBackspace('#{textarea.clientId}')" />

具有这些功能

function addEnter(textareaId) {
    var textarea = document.getElementById(textareaId);
    textarea.value += 'n';
    textarea.focus();
}
function addBackspace(textareaId) {
    var textarea = document.getElementById(textareaId);
    textarea.value = textarea.value.substring(0, textarea.value.length - 1);
    textarea.focus();
}

最新更新