[英]How to put p:commandLink with p:graphicImage in a dynamic columns datatable
I've followed the example of <p:datatable>
dynamic columns feature in primefaces showcase , and it works great. 我已经遵循了primefaces展示柜中
<p:datatable>
动态列功能的示例 ,并且效果很好。
Now what i want is to put instead of simple <h:outputText>
columns, i want to put columns with <p:graphicImage>
nested in <p:commanLink>
which serves to show a <p:dialogue>
. 现在,我想放置而不是简单的
<h:outputText>
列,我想放置<p:graphicImage>
嵌套在<p:commanLink>
,该列用于显示<p:dialogue>
。
in other words how can i use this : 换句话说,我该如何使用:
<f:facet name="header">
#{column.header}
</f:facet>
#{car[column.property]}
</p:columns>
to get it to generate something like this : 让它生成这样的东西:
<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>
Just to let you know i can programatically make it like this : 只是为了让您知道,我可以以编程方式使其如下:
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);
*this approach of creating the whole datatable in the backing bean and bind it to the facelet does work with a major problem which is i should click twice on the command link to fire the action.(no nested forms and everything is compliant to BalusC Answer ). *这种在后备bean中创建整个数据表并将其绑定到facelet的方法确实存在一个主要问题,那就是我应该在命令链接上单击两次以触发操作。(无嵌套表格,所有内容均与BalusC兼容) )。
Additional info: Primefaces 4.0. 附加信息: Primefaces 4.0。 JSF 2.2.
JSF 2.2。
This is an alternative using <p:commandButton/>
: 这是使用
<p:commandButton/>
的替代方法:
<p:commandButton id="MRepShowButton" update=":form1:display" onclick="EditorDialog.show();" icon="custom-icon" />
Declare this in your CSS stylesheet (adjust the image path according to your project): 在CSS样式表中声明此内容(根据您的项目调整图像路径):
.custom-icon {
background-image: url("#{facesContext.externalContext.request.contextPath}/resources/img/chart_stock.png") !important;
}
Use name property, not value in p:graphicImage . 使用名称属性,而不是p:graphicImage中的 值 。
p:graphicImage uses name property (and not value ) to match the image in the resources folder. p:graphicImage使用name属性(而不是value )来匹配资源文件夹中的图像。 If name is not provided, the img html element will not be rendered.
如果未提供名称,则不会呈现img html元素。
Example (based on the PrimeFaces columns showcase): 示例(基于PrimeFaces列展示):
<p:graphicImage name="images/#{car.year}.jpg" />
You can also use the library property (same result in this case). 您也可以使用库属性(在这种情况下,结果相同)。
<p:graphicImage library="images" name="#{car.year}.jpg" />
Images and directories must exist in the WebContent/resource
folder in your project. 图像和目录必须存在于项目的
WebContent/resource
文件夹中。
Take also into account my answer here about how to include p:commandLink into ap:columns block. 在这里还要考虑我关于如何将p:commandLink包含到ap:columns块中的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.