简体   繁体   English

如何访问托管Bean中的对象?

[英]How to access an object that is in a Managed Bean?

I'm using JSF 2.2. 我正在使用JSF 2.2。

For example, i had a form: 例如,我有一个表格:

<section class="form-group">
    <input type="text" class="flat-textbox" id="names" placeholder="Nombres"/>
</section>
<section class="form-group">
    <input type="text" class="flat-textbox" id="surnames" placeholder="Apellidos"/>
</section>
<section class="form-group">
    <input type="datetime" class="flat-textbox" id="birth-date" 
           placeholder="F. Nacimiento"/>
</section>

And i wanna bind player with each input: 我想将播放器与每个输入绑定:

<input type="text" class="flat-textbox" id="names"
       jsf:value="#{playerbean.player.names} placeholder="Nombres"/>

The bean is: Bean是:

@Named(value="playerbean")
@RequestScoped
public class PlayerBean {
    @Inject private PlayerServiceImpl playerService;
    @Inject private PlayerVO player; // i want set properties from view form

    // methods...
}

What options do I have for it? 我有什么选择呢?

  • Add Named(value="player") annotation to PlayerVO class? Named(value="player")注释添加到PlayerVO类吗?
  • Add a getter for player into Bean? 在Bean中添加播放器的吸气剂?

Thanks. 谢谢。

Providing accessors for the property you want to modify, should be just enough. 为您要修改的属性提供访问器就足够了。

Do: 做:

public PlayerVO getPlayer() { return player; }
public void setPlayer(PlayerVO player) { this.player = player; }

and: 和:

<input type="text" class="flat-textbox" 
       id="names" jsf:value="#{playerbean.player.names}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM