Html 输入文本字段自动完成不执行';I don’我提交表格时不要拿数据
我有一个输入数据登录:用户名和密码和提交按钮。像这样 那里的文本字段由Chrome填充,但当我获取这些信息进行登录时,就好像没有数据一样。我必须重写文本字段中的所有信息。我希望此信息用于登录过程。 我该怎么做 控制器类:Html 输入文本字段自动完成不执行';I don’我提交表格时不要拿数据,html,forms,zk,Html,Forms,Zk,我有一个输入数据登录:用户名和密码和提交按钮。像这样 那里的文本字段由Chrome填充,但当我获取这些信息进行登录时,就好像没有数据一样。我必须重写文本字段中的所有信息。我希望此信息用于登录过程。 我该怎么做 控制器类: public class LoginController extends SelectorComposer<Component>{ //Wire Components @Wire private Textbox user; @Wire
public class LoginController extends SelectorComposer<Component>{
//Wire Components
@Wire
private Textbox user;
@Wire
private Textbox password;
@Wire
private Label message;
private AuthenticationService serviceAuth = new AuthenticationService();
/*
* Method: doLogin
* Details: Login function with the data provided: User and password
*
*/
@Listen("onClick=#loginButton")
public void doLogin(){
String userName = user.getValue();
String pass = password.getValue();
//Now we use the Authenthication service
if(!serviceAuth.login(userName, pass)){
message.setValue("Datos ingresados son incorrectos");
return;
}
UserCredential tmpCred = serviceAuth.getUserCredential(); //check
message.setValue("Bienvenido, "+userName);
Executions.sendRedirect("/inquiries.zul");
}
}
公共类登录控制器扩展选择器或编译器{
//电线元件
@电线
私人文本框用户;
@电线
私人文本框密码;
@电线
专用标签信息;
private AuthenticationService serviceAuth=新建AuthenticationService();
/*
*方法:多洛金
*详细信息:提供数据的登录功能:用户和密码
*
*/
@听(“onClick=#loginButton”)
公共空间多洛金(){
字符串userName=user.getValue();
字符串pass=password.getValue();
//现在我们使用身份验证服务
如果(!serviceAuth.login(用户名,密码)){
message.setValue(“Datos ingresados son incorrectos”);
返回;
}
UserCredential tmpCred=serviceAuth.getUserCredential();//检查
message.setValue(“Bienvenido,”+用户名);
Executions.sendRedirect(“/inquires.zul”);
}
}
这听起来可能有点奇怪,但您可以尝试以下方法:
<textbox value="@bind(vm.userName) @save(vm.userName, before='submit')"/>
<button onClick="@command('submit')"/>
<window id="win" border="normal" title="hello" apply="be.chillworld.LoginController" xmlns:w="http://www.zkoss.org/2005/zk/client" >
<vlayout>
<textbox id="user"/>
<textbox id="password" type="password"/>
<button label="login" id="loginButton" w:onClick="persistValuesToServer()"/>
<script type="text/javascript">
function persistValuesToServer()
{
zAu.send(new zk.Event(zk.Widget.$('win'), 'onUser', jq('$user').val()));
zAu.send(new zk.Event(zk.Widget.$('win'), 'onPass', jq('$password').val()));
}
</script>
</vlayout>
</window>
public class LoginController extends SelectorComposer<Component> {
@Wire
private Textbox user;
@Wire
private Textbox password;
@Listen("onUser=#win")
public void autoFillUser(Event e) {
user.setValue(String.valueOf(e.getData()));
}
@Listen("onPass=#win")
public void autoFillPass(Event e) {
password.setValue(String.valueOf(e.getData()));
}
@Listen("onClick=#loginButton")
public void doLogin() {
System.out.println(user.getValue() + " : " + password.getValue());
}
}
小解释:当我们按下按钮时,我们的JavaScript将首先被触发=>并且我们将向控制器发送2个事件(1个用于用户名,1个用于密码),其中包含实际文本框中的数据。
在控制器中,我们将正确的数据放入文本字段,然后处理真正的登录事件。
这是完美的解决方案吗当然不是,但当我们按下按钮时,它的工作开销很小。是的,我如何使用MVC做到这一点?是否可以提供一些代码,MVC中有很多不同的方法来实现登录表单。你能提供反馈吗?嗨,@chillworld。谢谢你花时间回答我的问题。我会尝试你的解决方案,然后我会给你反馈(: