[英]How to put p:commandLink with p:graphicImage in a dynamic columns datatable
我已经遵循了primefaces展示柜中<p:datatable>
动态列功能的示例 ,并且效果很好。
现在,我想放置而不是简单的<h:outputText>
列,我想放置<p:graphicImage>
嵌套在<p:commanLink>
,该列用于显示<p:dialogue>
。
换句话说,我该如何使用:
<f:facet name="header">
#{column.header}
</f:facet>
#{car[column.property]}
</p:columns>
让它生成这样的东西:
<p:column headerText="R"
style=" text-align: center;"
width="10"
rendered="true">
<p:commandLink id="MRepShowButton" update=":form1:display" onclick="EditorDialog.show();" title="Editer le compte rendu">
<f:setPropertyActionListener value="#{exam}" target="#{dyna.selectedExamen}" />
<p:graphicImage id="img1" value="/images/study_Report_icons/Text/0.png" rendered="#{exam.examen.rapport.rapportWrittenState == null}"/>
<p:graphicImage id="img2" value="/images/study_Report_icons/Text/#{exam.examen.rapport.rapportWrittenState}.png" rendered="#{exam.examen.rapport.rapportWrittenState != null}"/>
</p:commandLink>
</p:column>
只是为了让您知道,我可以以编程方式使其如下:
column.setWidth(String.valueOf(columnmodel.get(i).getWidth() - widthOptimizer));
CommandLink rapstatelink = (CommandLink) application.createComponent(CommandLink.COMPONENT_TYPE);
rapstatelink.setId("MRepShowButton");
rapstatelink.setTitle("Editer le rapport du patient");
rapstatelink.setUpdate(":formero");
rapstatelink.setOnclick("EditorDialog.show();");
ValueExpression value = ef.createValueExpression(elc, "#{exam}", Cotation.class);
ValueExpression target = ef.createValueExpression(elc, "#{dyna.selectedExamen}", Cotation.class);
rapstatelink.addActionListener(new SetPropertyActionListenerImpl(target, value));
ValueExpression value1 = ef.createValueExpression(elc, "#{dyna.toHTML(dyna.selectedExamen.examen.rapport.rapportWrittenFile)}", String.class);
ValueExpression target1 = ef.createValueExpression(elc, "#{dyna.html}", String.class);
rapstatelink.addActionListener(new SetPropertyActionListenerImpl(target1, value1));
GraphicImage rapstateimage = (GraphicImage) application.createComponent(GraphicImage.COMPONENT_TYPE);
rapstateimage.setId("img1");
ValueExpression show1 = ef.createValueExpression(elc, "#{exam.examen.rapport.rapportWrittenState == null}", Boolean.class);
rapstateimage.setValueExpression("rendered", show1);
rapstateimage.setValue("/images/study_Report_icons/Text/0.png");
rapstatelink.getChildren().add(rapstateimage);
GraphicImage rapstateimage2 = (GraphicImage) application.createComponent(GraphicImage.COMPONENT_TYPE);
rapstateimage2.setId("img2");
ValueExpression patsategraphExp = ef.createValueExpression(elc, "/images/study_Report_icons/Text/#{exam.examen.rapport.rapportWrittenState}.png", Object.class);
rapstateimage2.setValueExpression("value", patsategraphExp);
ValueExpression show2 = ef.createValueExpression(elc, "#{exam.examen.rapport.rapportWrittenState != null}", Boolean.class);
rapstateimage2.setValueExpression("rendered", show2);
column.setStyleClass("imagero");
rapstatelink.getChildren().add(rapstateimage2);
column.getChildren().add(rapstatelink);
table.getChildren().add(column);
*这种在后备bean中创建整个数据表并将其绑定到facelet的方法确实存在一个主要问题,那就是我应该在命令链接上单击两次以触发操作。(无嵌套表格,所有内容均与BalusC兼容) )。
附加信息: Primefaces 4.0。 JSF 2.2。
这是使用<p:commandButton/>
的替代方法:
<p:commandButton id="MRepShowButton" update=":form1:display" onclick="EditorDialog.show();" icon="custom-icon" />
在CSS样式表中声明此内容(根据您的项目调整图像路径):
.custom-icon {
background-image: url("#{facesContext.externalContext.request.contextPath}/resources/img/chart_stock.png") !important;
}
使用名称属性,而不是p:graphicImage中的 值 。
p:graphicImage使用name属性(而不是value )来匹配资源文件夹中的图像。 如果未提供名称,则不会呈现img html元素。
示例(基于PrimeFaces列展示):
<p:graphicImage name="images/#{car.year}.jpg" />
您也可以使用库属性(在这种情况下,结果相同)。
<p:graphicImage library="images" name="#{car.year}.jpg" />
图像和目录必须存在于项目的WebContent/resource
文件夹中。
在这里还要考虑我关于如何将p:commandLink包含到ap:columns块中的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.