無論如何都會發布表單,但如果我不將表單放入ui:fragment
中,則只會觸發按鈕操作參數引用的bean方法。我在Tomcat 6.0.41上使用Mojarra 2.2.5。h:commandButton在ui中的作用:片段不會被觸發
(這也恰好如果我使用primefaces' p:commandButton
代替)
view.xhtml?edit=true
:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<f:metadata>
<f:viewParam name="edit" id="edit" />
<ui:param name="editMode" value="#{not empty edit and edit eq 'true' and saveBean.contentEditable}" />
</f:metadata>
<h:head>
<title>Page title</title>
</h:head>
<h:body>
<ui:fragment rendered="#{editMode}">
</ui:fragment>
<h:form id="saveForm">
<h:commandButton
id="btn2"
type="submit"
value="Triggers POST but no action"
action="#{saveBean.saveAllAction}"
/>
</h:form>
</h:body>
</html>
支持bean:
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ManagedBean(name = "saveBean")
@ViewScoped
public class TestBean implements Serializable{
private static final long serialVersionUID = 1L;
private static final Logger log = LoggerFactory.getLogger(TestBean.class);
public String saveAllAction() {
log.info("Received save all command.");
return "success";
}
public TestBean() {}
public String getContentEditable() {
return contentEditable;
}
public void setContentEditable(String contentEditable) {
this.contentEditable = contentEditable;
}
private String contentEditable = "true";
}
如果你把'ui:fragment'放在'h:form'裏面就足夠了嗎? – 2014-10-29 18:01:58