开发者

jsf and controller, bean

开发者 https://www.devze.com 2023-03-05 10:44 出处:网络
I want to learn that if I can define user input parameters at bean class and take these input parameters from a controller function with submit button :

I want to learn that if I can define user input parameters at bean class and take these input parameters from a controller function with submit button :

for example input jsp :

<h:inputSecret value="#{control.userObj.pwrd}"></h:inputSecret>
   <开发者_JAVA百科;h:commandButton type="submit" value="Giris" action="#{control.check}">
</h:commandButton>

"User" bean class :

  private String userName;   (with getter and setter)

"Control" controller class :

 private User userObj;


When using nested bean properties, then you need to prepare it yourself so that JSF can call the setters on it. JSF/EL namely won't prepare them for you.

public class Control {

    private User userObj;

    @PostConstruct
    public void init() {
        userObj = new User();
    }

    // ...
}

This way #{control.userObj.userName} will work in input fields.

See also:

  • JSF 2.0 Hello World - The Model, Controller and View
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号