1. 方法傳遞
在JSF 2.0,可以透過這樣的方法表達參數值 #{bean.method(param)}.
JSF page…
<h:commandButton action="#{user.editAction(delete)}" />
Backing bean…
@ManagedBean(name="user")
@SessionScoped
public class UserBean{
public String editAction(String id) {
//id = "delete"
}
}
2.f:param
透過f:param標籤傳遞參數值,並通過後台bean的接收參數。
JSF page…
<h:commandButton action="#{user.editAction}">
<f:param name="action" value="delete" />
</h:commandButton>
Backing bean…
@ManagedBean(name="user")
@SessionScoped
public class UserBean{
public String editAction() {
Map<String,String> params =
FacesContext.getExternalContext().getRequestParameterMap();
String action = params.get("action");
//...
}
}
3. f:atribute
透過 f:atribute
標籤傳遞參數值,並通過後台bean的接收參數。
JSF page…
<h:commandButton action="#{user.editAction}" actionListener="#{user.attrListener}">
<f:attribute name="action" value="delete" />
</h:commandButton>
Backing bean…
@ManagedBean(name="user")
@SessionScoped
public class UserBean{
String action;
//action listener event
public void attrListener(ActionEvent event){
action = (String)event.getComponent().getAttributes().get("action");
}
public String editAction() {
//...
}
}
4. f:setPropertyActionListener
透過 f:setPropertyActionListener
標籤, 直接將設定值set到您的backing bean的屬性.
JSF page…
<h:commandButton action="#{user.editAction}" >
<f:setPropertyActionListener target="#{user.action}" value="delete" />
</h:commandButton>
Backing bean…
@ManagedBean(name="user")
@SessionScoped
public class UserBean{
public String action;
public void setAction(String action) {
this.action = action;
}
public String editAction() {
//now action property contains "delete"
}
}
留言
張貼留言