setPropertyActionListenervsattributeとvsの違いは何paramですか?
いつ使用しsetPropertyActionListenerますか?
1. f:setPropertyActionListener:
このタグを使用すると、バッキングBeanにプロパティを直接設定できます。例:
xhtml:
<h:commandButton action="page.xhtml" value="OK">
<f:setPropertyActionListener target="#{myBean.name}" value="myname"/>
</h:commandButton>
バッキングビーン:
@ManagedBean
@SessionScoped
public class MyBean{
public String name;
public void setName(String name) {
this.name= name;
}
}
これnameにより、バッキングBeanのプロパティが値mynameに設定されます。
2. f:param:
このタグは単純にリクエストパラメータを設定します。例:
xhtml:
<h:commandButton action="page.xhtml">
<f:param name="myparam" value="myvalue" />
</h:commandButton>
したがって、バッキングBeanでこのパラメータを取得できます。
FacesContext.getExternalContext().getRequestParameterMap().get("myparam")
3. f:属性:
このタグを使用すると、属性を渡すことができるため、バッキングBeanのアクションリスナーメソッドからその属性を取得できます。
xhtml:
<h:commandButton action="page.xhtml" actionListener="#{myBean.doSomething}">
<f:attribute name="myattribute" value="myvalue" />
</h:commandButton>
したがって、アクションリスナーメソッドからこの属性を取得できます。
public void doSomething(ActionEvent event){
String myattr = (String)event.getComponent().getAttributes().get("myattribute");
}
f:setPropertyActionListenerバッキングBeanのプロパティを設定するときはいつでも使用する必要があります。バッキングBeanにパラメータを渡したい場合は、とを検討f:paramしてf:attributeください。また、値をf:param渡すだけで、オブジェクトを渡すことができることを知っておくことが重要です。Stringf:attribute