0
我正在使用JSF 1.1。我有一個JSF從jsp的dataTable訪問「var」屬性值
....
<t:dataTable id="data"
styleClass="scrollerTable"
headerClass="standardTable_Header"
footerClass="standardTable_Header"
columnClasses="col1,col2,col3"
var="product"
value="#{beanProduct.listOfProducts}"
preserveDataModel="false"
rows="10"
>
....
的#{product}
JSP頁面中有一個名爲state
屬性。如果它的值是「待定」,那麼我想顯示一個<h:commandButton>
,否則我什麼也不顯示。
如何在JSP scriptlet代碼中獲得#{product.state}
的值?
我試了下:
....
<h:column>
<f:facet name="header">
<h:outputText value="#{messages['list']}" />
</f:facet>
<%
// ----> In this point, I want know the value of "product.state"
FacesContext context = FacesContext.getCurrentInstance();
Application app = context.getApplication();
ValueBinding binding = app.createValueBinding("#{product.state}");
Object valueOfProduct = binding.getValue(context);
String stateProduct = (String)valueOfProduct;
if (stateProduct.equals("pending")) {
%>
<h:panelGrid>
<h:commandButton value="Send" actionListener="#{beanProduct.Item}" action="#{beanProduct.sending">
<f:attribute name="idProduct" value="#{product.id}" />
</h:commandButton>
</h:panelGrid>
<%
}
else {
%>
// Do nothing.
<%
}
%>
</h:column>
</t:dataTable>
但它不工作。我怎樣才能做到這一點?
您正試圖混合使用兩種完全不同的編程範例。一般來說,你根本不應該使用'<%/ * code * /%>'scriptlets。 – McDowell