2015-04-12 76 views
0

我正在使用JSF 2.2。如何訪問Managed Bean中的對象?

例如,我有一個表格:

<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> 

而且我想綁定玩家與每個輸入:

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

這個bean:

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

    // methods... 
} 

做我該怎麼選擇有它嗎?

  • Named(value="player")註釋到PlayerVO類?
  • 爲玩家添加一個getter到Bean?

謝謝。

回答

2

爲您想要修改的屬性提供訪問者應該就夠了。

務必:

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

和:

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

感謝。所以,這很好? '' –