使用JSF和PrimeFaces 6.1我有一个inputText字段:
<p:inputText value="#{backingBean.stringField}">
<p:ajax event="valueChange" update="@form" />
</p:inputText>
Run Code Online (Sandbox Code Playgroud)
在同一个表单中是一个commandButton:
<p:commandButton id="btnDoThatThing"
ajax="true"
immediate="true"
update="@form"
process="@this"
action="#{backingBean.doThatThing}"/>
Run Code Online (Sandbox Code Playgroud)
当我
一切都按预期完成.但如果我:
因为第一次单击commandButton会触发inputText字段中发生的valueChange事件,因此不会触发该按钮.
如果我第二次点击它,按钮动作终于发生了.
现在,如果我按照预期更改p:ajax event="valueChange"到p:ajax event="keyup"commandButton工作的第一次单击,但不幸的是,inputField上的keyup事件非常hacky并且你在该字段中丢失了功能(复制/粘贴文本,文本选择,'快速'输入'等)
有关如何在inputText字段中启动change事件的任何想法,当用户在inputText字段中输入时立即单击按钮时,触发commandButton操作?
谢谢你的时间!
我有一个名为“View”的实体,该实体有一个名为“datetime”的属性(实体和字段的名称不相关)。
我想在 CakePHP 中为其设置默认值,而不是在数据库中定义它。
在我的实体类上我定义了:
namespace App\Model\Entity;
use Cake\ORM\Entity;
use Cake\I18n\Time;
class View extends Entity
{
protected $_accessible = [
'*' => true,
'id' => false,
];
protected function _getDatetime($datetime)
{
return Time::now();
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试将其保存在模型表类(ViewTable)的方法中时:
public function registerView(User $user){
$view = $this->newEntity();
$view->user = $user;
$this->save($view);
}
Run Code Online (Sandbox Code Playgroud)
什么也没发生,我的“日期时间”字段保存为“0000-00-00 00:00:00”。
我的问题是:如何为实体设置默认值,以便当我调用$this->newEntity()该字段时带有此默认值?