- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 primefaces 4.0、JSF Mojarra 2.2.2这是我的数据表代码:
<p:dataTable id="tabexam"
paginatorPosition="bottom"
var="exam"
value="#{dyna.examViewDataModel}"
widgetVar="examTable"
emptyMessage="aucun résultat trouvé pour votre recherche"
paginator="true"
rows="40"
selection="#{dyna.selectedExamen}"
filteredValue="#{dyna.filteredexams}"
selectionMode="single"
resizableColumns="true"
draggableColumns="true"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="40,80,120">
<p:columns value="#{datatableBean.table}"
var="column"
headerText="#{column.userListname}"
rendered="#{column.visible}"
resizable="#{column.resizable}"
width="#{column.width}"
columnIndexVar="colIndex">
<h:panelGroup>
<p:outputLabel value="#{column.dbname}" styleClass="fonty"/>
</h:panelGroup>
</p:columns>
</p:dataTable>
这是我到目前为止所尝试的,但是我在控制台中得到了 getHeaderText 的空字符串和空宽度,我想知道我错过了什么
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
DataTable tabler = (DataTable) view.findComponent(":form1:tabexam");
List<UIColumn> coler = tabler.getColumns();
for (int i = 0; i < coler.size(); i++) {
System.out.println("/////////////////");
System.out.println(coler.get(i).getValueExpression("headerText").getValue(FacesContext.getCurrentInstance().getELContext()));
System.out.println(coler.get(i).getHeaderText());
System.out.println(coler.get(i).isRendered());
System.out.println(coler.get(i).isResizable());
System.out.println(coler.get(i).getWidth());
System.out.println("/////////////////");
}
System.out.println(coler.size());
请注意,coler.size()
给出了数据表上显示的列数。但 coler.get(i).getHeaderText()
总是给出空字符串。
最佳答案
你弄错了一些东西:
p:column
嵌套在 p:columns
内DataTable.getColumns 未返回您期望的结果:
public List<UIColumn> getColumns() {
if(columns == null) {
columns = new ArrayList<UIColumn>();
FacesContext context = getFacesContext();
char separator = UINamingContainer.getSeparatorChar(context);
for(UIComponent child : this.getChildren()) {
if(child instanceof Column) {
columns.add((UIColumn) child);
}
else if(child instanceof Columns) {
Columns uiColumns = (Columns) child;
String uiColumnsClientId = uiColumns.getClientId(context);
for(int i=0; i < uiColumns.getRowCount(); i++) {
DynamicColumn dynaColumn = new DynamicColumn(i, uiColumns);
dynaColumn.setColumnKey(uiColumnsClientId + separator + i);
columns.add(dynaColumn);
}
}
}
}
return columns;
}
这将返回一个合成模拟:每列仅columnKey
,并且正如您所说,正确的列数。
一般来说,p:columns
是一个组件,当你从 Controller 层访问它时,你必须引用它的DECLARATION(单个组件)而不是它的REPRESENTATION(多列)
#{datatableBean.table}
支持 p:columns
,因此您应该已经拥有尝试从 DataTable 组件获取的所有信息,位于逆向工程时尚。更新
哦,现在我知道你想做什么了。您必须为此使用事件监听器。
来自 PF 展示:
<p:dataTable var="car" value="#{tableBean.carsSmall}" widgetVar="cars" draggableRows="true">
<p:ajax event="colReorder" listener="#{tableBean.onColReorder}" update=":some:component" />
<p:ajax event="colResize" listener="#{tableBean.onColResize}" update=":some:component"/>
<!-- columns here -->
</p:dataTable>
在支持 bean 中监听这些事件并维护这些信息应该可以解决您的问题
更新2
哇,这根本不简单。
由于 Primefaces 的动态列大小调整错误(至少在我的尝试中)和不完整的列重新排序事件实现,结果如下:
<h:form id="form">
<h:panelGroup id="model">
<ui:repeat var="column2" value="#{testBean.columnList2}">
<div>#{column2.title} - #{column2.width}</div>
</ui:repeat>
</h:panelGroup>
<p:dataTable var="elem" value="#{testBean.elementList}" resizableColumns="true" draggableColumns="true">
<p:ajax event="colReorder" listener="#{testBean.onColumnReorder}" update=":form:model" />
<p:ajax event="colResize" listener="#{testBean.onColumnResize}" update=":form:model"/>
<c:forEach var="column" items="#{testBean.columnList}">
<p:column headerText="#{column.title}" rendered="#{column.visible}" width="#{column.width}">
<f:attribute name="myCol" value="#{column}"/>
<span>#{elem[column.property]}</span>
</p:column>
</c:forEach>
</p:dataTable>
</h:form>
还有这个bean:
@ManagedBean
@ViewScoped
public class TestBean implements Serializable
{
private static final long serialVersionUID = 1L;
private List<MyColumn> columnList;
private List<MyColumn> columnList2;
private List<MyElement> elementList;
public class MyColumn
{
private String title;
private String property;
private boolean visible = true;
private boolean resizable = true;
private int width = 100;
public MyColumn(String title, String property, boolean visible, boolean resizable, int width)
{
super();
this.title = title;
this.property = property;
this.visible = visible;
this.resizable = resizable;
this.width = width;
}
// getters and setters
}
public class MyElement
{
private String code;
private String name;
private String type;
public MyElement(String code, String name, String type)
{
super();
this.code = code;
this.name = name;
this.type = type;
}
// getters and setters
}
@PostConstruct
public void init()
{
columnList = new ArrayList<>();
columnList.add(new MyColumn("element code", "code", true, true, 100));
columnList.add(new MyColumn("element name", "name", true, true, 100));
columnList.add(new MyColumn("element type", "type", true, true, 100));
columnList2 = new ArrayList<>(columnList);
elementList = new ArrayList<>();
elementList.add(new MyElement("001", "foo", "normal"));
elementList.add(new MyElement("002", "bar", "strange"));
elementList.add(new MyElement("003", "xyz", "normal"));
elementList.add(new MyElement("004", "abc", "nothing"));
}
public void onColumnResize(ColumnResizeEvent event)
{
UIColumn column = event.getColumn();
int width = event.getWidth();
UIComponent colComponent = (UIComponent) column;
MyColumn myCol = (MyColumn) colComponent.getAttributes().get("myCol");
myCol.setWidth(width);
}
public void onColumnReorder(AjaxBehaviorEvent event)
{
DataTable table = (DataTable) event.getSource();
columnList2.clear();
for(UIColumn column : table.getColumns())
{
UIComponent colComponent = (UIComponent) column;
MyColumn myCol = (MyColumn) colComponent.getAttributes().get("myCol");
columnList2.add(myCol);
}
}
// getters and setters
}
更新了代码,您可以在columnList2
中找到有序列。现在也显示在表格中。现在您可以使用columnList2
将排序器和宽度存储到数据库。
关于jsf-2 - 如何从 ManagedBean 获取 primefaces 数据表列顺序和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21531546/
好的,这是我的 session bean。我总是可以从任何 Servlet 或过滤器中检索 currentUser。那不是问题问题是fileList和currentFile。我已经用简单的 int 和
我觉得 Java EE 6 规范有些困惑。有几组注释。 我们有javax.ejb注释如 @Stateful和 @Stateless用于创建 EJB。 还有一个@javax.annotation.Man
这个问题已经有答案了: Backing beans (@ManagedBean) or CDI Beans (@Named)? (5 个回答) 已关闭 7 年前。 我刚刚创建了一个新的 Maven 项
我正在开发一个复合组件,它必须进行一些计算才能使布局正常工作。对于 EL 来说过于复杂的计算(实际上并不复杂,但我无法通过 EL 执行它们)。我可以专门为该复合组件创建一个 ManagedBean 吗
我在@ManagedBean类中使用Bean管理事务来手动管理事务, @ManagedBean(name = "clients") @ViewScoped @URLMapping(id = "sous
这个问题在这里已经有了答案: How to inject @EJB, @PersistenceContext, @Inject, @Autowired, etc in @FacesConverter
我有一个 jsf View ,它显示了来自表中托管 bean( View 范围)的一些数据,这些数据是远程检索的。 目前,数据是通过使用 primefaces 轮询组件从客户端 View 轮询来更新的
在我的网络应用程序中,当我点击登录链接时,Tomcat 网络服务器抛出以下异常: exception javax.servlet.ServletException: /aluno_jsf.xhtml:
我对应用程序中 ManagedBeans 的使用有疑问。 我有一个页面,其中包含不同的 JSP 组件,如 autoComplete、selectOneMenu、textarea、inputFields
为了获得良好的用户反馈,我在网络应用程序的多个站点上使用消息。 要添加消息,我简单地使用: FacesContext.getCurrentInstance().addMessage(null, new
我一直在为我的 bean 使用注释(我以前没有使用过它们),我发现我必须包含一些依赖项等等,如下所示: com.sun.faces
我是 richfaces 的新手,我想使用注释而不是 xml 配置来支持 bean 类 [就像 JSF 2.0] 我正在使用 richfaces 4.0 并将所有必需的 jar 包含在我的构建路径中。
我目前正在将一个项目从 JBoss 4.2.2 迁移到 JBoss 6.0.0,我还在使用 CDI 添加依赖注入(inject)并从 JSF 1.2 迁移到 JSF 2.0。我向 ejb-packag
可以将无状态 session bean 注入(inject) jsf 托管 bean 中吗? 我有 @ManagedBean(name = "imageUpload") @RequestScoped
我有一个名为 Foo 的类。还有一个名为 FooBean 的 ManagedBean。在页面(Facelet)中,我从用户那里获取新的 Foo 信息并将其插入到数据库中。首次提交数据后,将启用打印按钮
我有fileUpload的managementBean,一旦文件上传,我需要根据从解析器下拉列表中选择的值调用不同的解析器,然后在解析器中创建DetailsClass对象,其中调用该特定类的getDe
我尝试编写一个应用程序来创建 PDF 文件,它使用 JavaServer Faces。当我将文本框的值从 bean 赋予工厂类时,我遇到了一个问题,这些值丢失了。我想知道为什么会发生这种情况,已经尝试
我想知道在两个 ViewScoped bean 之间传递数据(对象)的最佳实践是什么。 由于出色解释的问题,它们需要在 View 范围内here (简而言之:在这两个 View 中,我都在 h:dat
我有 Controller-ManagedBeans 和 Model-ManagedBeans(如 MVC 模式)。 这是我的 Controller : @ManagedBean @Req
这个问题在这里已经有了答案: Identifying and solving javax.el.PropertyNotFoundException: Target Unreachable (18 个回
我是一名优秀的程序员,十分优秀!