相关疑难解决方法(0)

在模型视图更新之前,转换器是否始终运行?

例:

<h:form>
    <h:selectOneMenu value="#{bean.timezone}>
        <f:selectItems value="#{bean.availableTimezones} ... >
        <f:ajax render="currenttime" />
    </h:selectOneMenu>
</h:form>

<h:form id="currenttime">
    <h:outputText value="#{bean.currentTime}" >
        <f:convertDateTime dateStyle="short" type="both" timeZone="#{bean.timezone}" />
    </h:outputText>
</h:form>

<!-- bean.currentTime is of type 'Date' -->
Run Code Online (Sandbox Code Playgroud)

在该示例中,更改时区应该使文本currenttime显示在适当的时区.但事实并非如此.

我想这是因为转换器是在"应用请求"阶段计算的,所选时区的值是在"更新模型"阶段更新的.

我对吗?我不应该使用转换器吗?

谢谢!

jsf-2

2
推荐指数
1
解决办法
219
查看次数

UI重复varStatus在CompositeComponent中不起作用

我在WebSphere Application Server 8上使用JSF 2.0(Apache myFaces).

我有一个bean,其中包含一个图表列表(jquery HighCharts的数据).对于每个图表,我需要一些JSF组件+一个写为CompositeCompoent的Highchart Wrapper(在这里查看)

所以我使用jsf 2的ui:repeat函数,如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:hc="http://java.sun.com/jsf/composite/chartComponents"
    template="/template/mytemplate.xhtml">

    <ui:define name="content">


        <ui:repeat value="#{chartCtrl.charts }" var="chart" id="chartrepeat" varStatus="chartStatus">
                #{chartStatus.index }
                <h:form id="chartform_#{chartStatus.index }">

                    <!-- some jsf select stuff-->               
                </h:form>

                    #{chartStatus.index }
                    <hc:Chart title="Statistics" id="hcchart_#{chartStatus.index }"
                    <!-- here's the problem-->

                        <ui:repeat value="#{chart.series }" var="serie">
                            <hc:ChartSeries series="#{serie.data }" />
                        </ui:repeat>
                    </hc:Chart>
                    #{chartStatus.index }
            </p:panel>
        </ui:repeat>


        <h:outputScript library="js" name="highcharts.js" />
        <h:outputScript library="js/modules" name="exporting.js" />
        <h:outputScript library="js" name="jquery-1.9.1.min.js" …
Run Code Online (Sandbox Code Playgroud)

el composite-component jsf-2

2
推荐指数
1
解决办法
9079
查看次数

JSF c:设置评估

<c:set var="product" value="#{productDAO.findByCode('code')}"  />
#{product.name}
#{product.name}
Run Code Online (Sandbox Code Playgroud)

我想从DB中检索一个对象并将其存储到变量中一次.但是,我发现每次访问产品时都会调用DB.在上面的示例中,有两个对DB的调用.

jsf jstl jsf-2

2
推荐指数
1
解决办法
7675
查看次数

迭代h:datatable中的嵌套List属性

    <h:dataTable value="#{SearchingBeans.list}" var="entry">
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Pseudo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.pseudo}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Description</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.description}"></h:outputLabel>
        </h:column>
        <h:column>
            <f:facet name="header">
                <h:outputLabel>Photo</h:outputLabel>
            </f:facet>
            <h:outputLabel value="#{entry.photo[0].path}"></h:outputLabel> <-- this a List
        </h:column>
    </h:dataTable>
Run Code Online (Sandbox Code Playgroud)

我有一个实体成员他的一个属性是一个列表照片与获取/设置属性填充我不知道如何获取该值在jsf我只想要每个成员的第一张照片,因为他们有2-3张照片.它可能吗?任何其他解决方案将不胜感激.

datatable jsf nested

2
推荐指数
1
解决办法
5775
查看次数

在primefaces数据表中迭代List <Map <String,String >>?

我试图通过地图项目的列表进行迭代,即包含HashMap或类似的东西的一个ArrayList,我试图做到这一点在primefaces数据表.这基本上就是我要做的事情:

<body>
    <h:form>
        <p:dataTable value="#{customerBean.list}" var="map">
            <c:forEach items="#{map}" var="entry">
                <p:column headerText="#{entry.key}">
                    #{entry.value}
                </p:column>
            </c:forEach>
        </p:dataTable>
    </h:form>
</body>
Run Code Online (Sandbox Code Playgroud)

在这种情况下,customerBean.listList<Map<String, String>>和条目是一个Map<String, String>.

我想要做的,是营造列的动态量的基础上,在条目数量Map<String, String>使用的标题名称映射条目的键的同时,和值作为输出.c:forEach当我使用硬编码时Map<String, String>,这个东西似乎工作正常,但显然它无法循环通过变量p:dataTable.我假设该程序采取预防措施,以避免必须循环不同大小的地图.那么我怎么能做这项工作呢?如何根据Map中的条目数创建任意数量的列?请注意,我100%肯定每个人Map<String, String>的身材都相同List<Map<String, String>>

编辑:

这是我的豆源.代码工作正常,一切,问题只是循环不愿意通过我的地图:

@ManagedBean
@SessionScoped
public class CustomerBean {

    private List<Map<String, String>> list = new ArrayList<Map<String, String>>();
    private Mapper mapper = new Mapper();

    public CustomerBean() {
        list = mapper.all(); //gets data from database
    }

    public List<Map<String, String>> getList() { …
Run Code Online (Sandbox Code Playgroud)

datatable jsf loops map primefaces

2
推荐指数
1
解决办法
1万
查看次数

c:forEach总是运行相同数量的循环

嗨,我试图在JSF中显示树结构

为了打算我想插入

<span class="intendWidth" />
Run Code Online (Sandbox Code Playgroud)

这是我的jsf代码

<ui:repeat value="#{myHandler.entityTree}" var="entityDepthHolder">
    <p:commandLink action="#{myHandler.toggle(entityDepthHolder.entity)}">
        <div>
            <c:forEach begin="0" end="#{entityDepthHolder.depth}">
                <span class="intendWidth" />
            </c:forEach>
            #{entityDepthHolder.depth} #{entityDepthHolder.entity.title}
        </div>
    </p:commandLink>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)

但由于某种原因,c:forEach总是运行一次,虽然只有一个entityDepthHolder.depth是1,其他所有都是0

任何想法如何在没有c:forEach的情况下插入标签n次?

jsf jstl

2
推荐指数
1
解决办法
279
查看次数

如何遍历List <T>并渲染JSF Facelets中的每个项目

我想知道如何List<T>在Facelet中显示如下所示:

public List<T> searchByString(String string) {
    return getEntityManager().createNamedQuery("Userdetails.findByUsername").setParameter("username", "%" + string + "%").getResultList();
}
Run Code Online (Sandbox Code Playgroud)

<h:dataTable>是一个合适的方式吗?

jsf list facelets data-presentation

2
推荐指数
1
解决办法
5191
查看次数

在JSF中从支持bean设置ID

这合法吗?

<h:form id="status${a.myID}" >
// ...
</h:form>
Run Code Online (Sandbox Code Playgroud)

其中“ a”是备用bean中的对象。似乎有些工作,但是当我查看呈现的HTML时,我看到的id为::0:status例如,而不是:status0我期望的那样。我的主要问题是尝试引用中的ID <f:ajax render=...。我几乎可以想到的每个组合都包含“包含未知ID ...”。是否可以可靠地使用来自支持bean的值来设置id?

jsf

2
推荐指数
1
解决办法
1400
查看次数

如何在循环中将<p:tab>动态添加到<p:wizard>

我想在循环中动态地向<p:tab>组件添加组件<p:wizard>.

我尝试使用<ui:repeat>内部和外部<p:wizard>组件.

<p:wizard>
    <ui:repeat value="#{tabBean.tabs}" var="tab">
        <p:tab title="#{tab.tabname}">
    </ui:repeat>
</p:wizard>
Run Code Online (Sandbox Code Playgroud)
<ui:repeat value="#{tabBean.tabs}" var="tab">
    <p:wizard>
        <p:tab title="#{tab.tabname}">
    </p:wizard>
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)

两种尝试均无效.我怎样才能达到我的要求?

jsf tabs dynamic wizard primefaces

2
推荐指数
1
解决办法
1751
查看次数

如何在 panelGrid 中插入条件行,同时保持行简洁?

我有h:panelGrid两列和多行:

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" value="#{viewBean.attr1}" />
    <p:outputLabel for="attr2" value="#{messages.attr2}" />
    <p:inputText id="attr2" value="#{viewBean.attr2}">
    <p:outputLabel for="attr3" value="#{messages.attr3}" />
    <p:inputText id="attr3" value="#{viewBean.attr3}" />
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)

现在,某些行只能有条件地出现。在示例中,这可能是 attr2 和 attr3。当我围绕它们构建一个<ui:fragment />条件渲染时(见下文),但是 jsf 尝试将整个块放入一个<td />表格单元格元素中。

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" value="#{viewBean.attr1}" />
    <ui:fragment rendered="#{viewBean.myCondition}">
        <p:outputLabel for="attr2" value="#{messages.attr2}" />
        <p:inputText id="attr2" value="#{viewBean.attr2}">
        <p:outputLabel for="attr3" value="#{messages.attr3}" />
        <p:inputText id="attr3" value="#{viewBean.attr3}" />
    </ui:fragment>
</h:panelGrid>
Run Code Online (Sandbox Code Playgroud)

另一种选择是创建两个 panelGrid。一个用于第一个块,一个用于第二个块:

<h:panelGrid columns="2">
    <p:outputLabel for="attr1" value="#{messages.attr1}" />
    <p:inputText id="attr1" …
Run Code Online (Sandbox Code Playgroud)

jsf

2
推荐指数
1
解决办法
1489
查看次数