我在JSF中完成一项非常简单的任务时遇到了很大的问题.问题:我有一些对象,这些对象具有聚合属性,这些属性的类型可以在不同对象之间变化.根据属性的类型,我想使用一组不同的输入字段.
子类型组件驻留在框架中并按需加载.为此,我使用以下代码:
<h:panelGroup id="zusatzdaten">
<fieldset class="clear">
<legend>#{tickerUI.ticker.tickerDescription.label}
(#{tickerUI.ticker.tickerDescId})
</legend>
<h:panelGroup rendered="#{tickerUI.editComponentName != null}">
<ui:include src="#{tickerUI.editComponentName}"/>
</h:panelGroup>
</fieldset>
</h:panelGroup>
Run Code Online (Sandbox Code Playgroud)
该组件的名称来自TickerUI,它是@SessionScope.现在令人眼花缭乱的一点:首次加载时,会显示正确的子组件.但是,当在导航中使用链接时,应该导致包含不同的组件,内容不会更新!这会导致错误,因为数据现在是不同的子类型,但表单组件仍然来自前一个.
从错误返回并再次单击链接时,将显示正确的组件.我记录了editComponentName的值,并返回了正确的值.这非常令人困惑.当getter将正确的组件名称返回到src属性时,为什么包含错误的内容?
非常感谢.
我需要为JSF中的某些组件生成动态ID来解决我的问题.
看看这个例子:
<h:outputText id="#{bean.id}" value="#{bean.value}" />
Run Code Online (Sandbox Code Playgroud)
我的问题是我收到此错误:
java.lang.IllegalArgumentException: Empty id attribute is not allowed
Run Code Online (Sandbox Code Playgroud)
当我查看生成的HTML输出时,组件的ID为空.这是怎么造成的,我该如何解决?
我正在尝试为一个id分配一个id:在ui中的panelGroup:repeat
像那样
<ui:repeat value="#{bean.columns}" var="column">
<h:panelGroup layout="block" id="column_#{column.id}"
styleClass="#{column.id} dashboard_column">
Run Code Online (Sandbox Code Playgroud)
问题是,id值正在styleClass值中正确放置,但它没有在id属性中设置,所有在id属性中设置的都是由JSF +我的硬编码值"column_"自动生成的id.
如果我删除硬编码"column_"我得到一个例外
java.lang.IllegalArgumentException:组件标识符不能是零长度的String
有任何想法吗?
这是场景(简化):
有一个bean(称之为mrBean)与成员和适当的getter/setter:
private List<String> rootContext;
public void addContextItem() {
rootContext.add("");
}
Run Code Online (Sandbox Code Playgroud)
JSF代码:
<h:form id="a_form">
<ui:repeat value="#{mrBean.stringList}" var="stringItem">
<h:inputText value="#{stringItem}" />
</ui:repeat>
<h:commandButton value="Add" action="#{mrBean.addContextItem}">
<f:ajax render="@form" execute="@form"></f:ajax>
</h:commandButton>
</h:form>
Run Code Online (Sandbox Code Playgroud)
问题是,当单击"添加"按钮时,不会执行<h:inputText/>在表示字符串中的值中输入的值stringList.
实际上,从不调用mrBean.stringListsetter(setStringList(List<String> stringList)).
知道为什么吗?
一些信息 - 我在Tomcat 6上使用MyFaces JSF 2.0.
在JSF中,<ui:repeat/>类似的组件(如PrimeFaces)<p:dataTable/>根据迭代索引为子组件生成动态ID,即:
<p:dataTable id="table" var="item" value="#{itemList}">
<h:outputText id="name" value="#{item.name}"/>
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)
会生成这样的东西:
<table id="table">
<span id="table:0:name">name0</span>
<span id="table:1:name">name1</span>
<span id="table:2:name">name2</span>
...
<span id="table:n:name">nameN</span>
</table>
Run Code Online (Sandbox Code Playgroud)
所以所有元素显然都有明确的客户ID.我故意跳过了<tr/>,<td/>等
因此,<p:ajax ... update=":table:name"/>引用表中的所有名称并且它工作正常,<p:ajax ... update=":table:#{someDesiredIndex}:name"/>失败并显示类似于SEVERE: javax.faces.FacesException: Cannot find component with identifier ":table:0:name" in view.事件的消息,但我可以确认该组件存在于标记中.是不是可以这样做?
我正在运行GlassFish 3.1.2和Mojarra 2.1.6,以防它相关.
我想根据bean值设置一个ui:param,我想用c:if是个好主意.所以我在我的页面中输入以下代码:
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:wai="http://www.id.ethz.ch/wai/jsf"
template="/view/listView.xhtml">
<c:if test="#{subscriptionListController.model.listViewName eq 'mySubscriptions'}">
<ui:param name="title" value="#{msg.subscriptionTitleMySubscriptions}"/>
</c:if>
<c:if test="#{subscriptionListController.model.listViewName eq 'paidSubscriptions'}">
<ui:param name="title" value="#{msg.subscriptionTitlePaidSubscriptions}"/>
</c:if>
<c:if test="#{subscriptionListController.model.listViewName eq 'allSubscriptions'}">
<ui:param name="title" value="#{msg.subscriptionTitleAllSubscriptions}"/>
</c:if>
....
Run Code Online (Sandbox Code Playgroud)
但参数未设置...
如果我打印出来的值,#{subscriptionListController.model.listViewName eq 'mySubscriptions'}我会在相应的情况下得到真值,而在其他两种情况下则为假.
一开始我只有两种可能性并用三元运算符解决了它:
<ui:param name="title" value="#{subscriptionListController.model.listViewName eq 'mySubscriptions' ? msg.subscriptionTitleMySubscriptions : msg.subscriptionTitlePaidSubscriptions}"/>
Run Code Online (Sandbox Code Playgroud)
它起作用了.但现在我有更多的可能性......
我究竟做错了什么?
当数字数据列在<p:dataTable>(或<h:dataTable>)中时,是否有任何方法可以在表的页脚中的摘要行中获取总和而不在辅助bean中计算它并再次将其作为另一个bean属性提供?
我使用<h:outputLink>如下.
<c:set var="cid" value="1"/>
<c:set var="sid" value="2"/>
<h:outputLink value="Test.jsf">
<h:outputText value="Link"/>
<f:param name="cid" value="#{cid}"/>
<f:param name="sid" value="#{sid}"/>
</h:outputLink>
Run Code Online (Sandbox Code Playgroud)
这只是一个例子.两个查询字符串参数都是动态的.因此,<c:set>这里使用的只是为了演示.
在任何时候,可以存在一个,两个或不存在任何参数.在这种情况下,如果只有一个或不存在,则参数/ s被不必要地附加到不应发生的URL.防止将不必要的查询字符串参数附加到URL需要条件呈现<f:param>.
JSTL <c:if>如下
<c:if test="${not empty cid}">
<f:param name="cid" value="#{cid}"/>
</c:if>
Run Code Online (Sandbox Code Playgroud)
不工作.
怎么能有条件地渲染<f:param>内部<h:outputLink>?
我想测量JSF应用程序的渲染时间.由于我的权力原因,应用程序无法填充日志.
因此,我的问题是,在使用任何浏览器执行包含后端(服务器)调用的特定操作之后,有什么方法可以衡量应用程序的呈现时间?
到目前为止,在使用Chrome开发者工具后,我发现了以下内容.在"网络"选项卡上,每个请求都显示"时间".此外,在选择某个条目后,在"定时"选项卡上,将显示更详细的可视化.现在,我可以从中了解到,"Waiting"表示它在这里捕获到服务器的往返,但是实际的渲染时间呢.
假设整个请求耗时1秒,等待部分耗时500毫秒,我能否推断渲染时间是1秒-500毫秒?我不这么认为,这就是我问这个问题的原因.
简而言之,我需要从浏览器中了解服务器处理需要多长时间以及实际UI渲染时间.
任何提示将非常感谢.谢谢.
我想只有在满足某些条件时才允许用户编辑数据表中的单元格.
最初我试图<choose>实现这个目标:
<p:dataTable var="item" value="${bean.items}" editable="true" editMode="cell">
<p:column headerText="column A">
<c:choose>
<c:when test="${item.isEditable}">
<p:cellEditor id="title">
<f:facet name="output">
<h:outputText value="#{item.title}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.title}"/>
</f:facet>
</p:cellEditor>
</c:when>
<c:otherwise>
<h:outputText value="#{item.title}"/>
</c:otherwise>
</c:choose>
</p:column>
...
Run Code Online (Sandbox Code Playgroud)
但它不起作用.另一种方法是使用rendered属性:
<p:column headerText="column A">
<p:cellEditor rendered="${item.isEditable}">
<f:facet name="output">
<h:outputText value="#{item.title}"/>
</f:facet>
<f:facet name="input">
<p:inputText value="#{item.title}"/>
</f:facet>
</p:cellEditor>
<h:outputText value="#{item.title}" rendered="#{!item.isEditable}"/>
</p:column>
Run Code Online (Sandbox Code Playgroud)
工作正常 - 用户只能编辑允许的单元格.
但即使单元格不可编辑,它仍然具有ui-cell-editing类,并且看起来像用户的可编辑单元格.
将条件应用于单元格编辑的正确方法是什么?
谢谢!