在BackingBean中将值从表单提交到方法中,而无需变量 [英] Submit value from form to method without variable in the BackingBean

查看:176
本文介绍了在BackingBean中将值从表单提交到方法中,而无需变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的表单,其中用户输入用户名和密码,在bean中检查值是否正确.

I have a simple form where a user enters his username and password, in the bean it's checked if the values are correct.

.xhtml

<p:outputLabel value="Username:" />
<p:inputText value="#{fooBean.username}" />

<p:outputLabel value="Passwort:" />
<p:password value="#{fooBean.password}" />

<p:commandButton value="Login" action="#{fooBean.check()}" />

fooBean

public void check() {
    if(username == "name" && password == "pass") {
        // do stuff
    }
}

现在我的问题是,是否有一种方法可以将inputTexts的值提交给函数check(String username, String password),而不必在bean中声明字段.

Now my question is if there is a way to submit the values of the inputTexts to a function check(String username, String password), without having to declare the fields in the bean.

推荐答案

简单地:

<p:outputLabel value="Passwort:" />
<p:password value="#{password}" />

<p:commandButton value="Login" action="#{fooBean.check(username, password)}" />

可以,但是扩大范围可能更好:

will work, but maybe enlarging scope is better:

<p:outputLabel value="Passwort:" />
<p:password value="#{viewScope.password}" />

<p:commandButton value="Login" 
    action="#{fooBean.check(viewScope.username, viewScope.password)}" />

这篇关于在BackingBean中将值从表单提交到方法中,而无需变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆