在我的.xhtml页面中,我有以下表格:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
template="./../template/CustomerTemplate.xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.prime.com.tr/ui">
<ui:define name="formContent">
<h:form>
<p:dataGrid var="item" value="#{mrBean.items}" columns="3">
<p:column>
<p:panel header="#{item.name}">
<h:panelGrid columns="1" style="width:100%">
...
<h:commandButton value="Add To Cart" actionListener="#{cartBean.addItem(item.id)}" />
...
</h:panelGrid>
</p:panel>
</p:column>
</p:dataGrid>
</h:form>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
CustomerTemplate.xhtml是:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.prime.com.tr/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
... // import css, js files
</h:head>
<h:body>
... // Other things on the page
<div class="grid_9 content">
<ui:insert name="contentTitle"></ui:insert>
<ui:insert name="formContent"></ui:insert>
</div>
...
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的ManagedBean:
@ManagedBean
@ViewScoped
public class MrBean { …Run Code Online (Sandbox Code Playgroud)