JSF 访问“var”来自jsp的dataTable的属性值
我正在使用 JSF 1.1。我有一个 JSP 页面,其中
....
<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}
有一个名为 state
的属性。如果它的值是“pending”,那么我想显示一个
,否则我什么也不显示。
如何在 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>
但它不起作用。我怎样才能实现这个目标?
I'm using JSF 1.1. I have a JSP page with a
....
<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"
>
....
The #{product}
has a attribute named state
. If its value is "pending", then I want to display a <h:commandButton>
, else I display nothing.
How can I get the value of #{product.state}
in JSP scriptlet code?
I tried the next:
....
<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>
But it does not work. How can I achieve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该使用“rendered”属性:
像这样混合 JSF 和 JSP 是行不通的,因为 dataTable var 在执行嵌入代码时不可用。这也不是推荐的做法。
You should use "rendered" attribute instead:
Mixing JSF and JSP like this won't work because dataTable var will not be available at the time your embedded code is executed. Also it is not a recommended practice.