标签: facelets

在Facelets中使用include的问题

我有问题,包括facelet模板.我想拆分一些内容,以便我可以在其他地方重用它.

所以我改变了这段代码:

<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/layout/template.xhtml">

    <ui:define name="head">
        <title>Title</title>
    </ui:define>

    <ui:define name="header">
        <h3>Header</h3>
    </ui:define>

    <ui:define name="content">
        <table><tr><td>table</td></tr></table>
    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

对此:

<!DOCTYPE html>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    template="/layout/template.xhtml">

    <ui:define name="head">
        <title>Title</title>
    </ui:define>

    <ui:include src="/admin/admin_generic.xhtml"/>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

在里面admin-generic.xhtml我把代码包装在一个ui:composition中.

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:define name="header">
        <h3>Header</h3>
    </ui:define>

    <ui:define name="content">
        <table><tr><td>table</td></tr></table>
    </ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)

但没有显示任何内容.我只是得到一个空白页面,没有错误.使用不对ui:composition吗?我试过ui:component但但也没有帮助.


更新:根据我的Facelets要点指南,它说:

ui:include标签可用于包括另一Facelets的文件到您的文档.它只包含您指定的任何源文件.您可以包含任何具有ui:componentui:composition标记的 Facelets文件(将内容修剪为自身之外)或仅包含XHTML或XML的片段.

那是怎么回事?包括在内的内容是否已被删除?如何在不修剪内容的情况下包含页面?

jsf facelets include

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

输入String的NumberFormatException

我在JSF支持bean中有以下方法:

public List<Rent> getTopMemebers(){
    return rentDAO.findByMonthAndYear(MonthReport, YearReport);
}
Run Code Online (Sandbox Code Playgroud)

我在数据表中显示:

<p:dataTable value="#{rentController.topMemebers}" var="item">
    <p:column>
        <h:outputText value="#{item.rentid}"/>
    </p:column>
    ...
</p:dataTable>
Run Code Online (Sandbox Code Playgroud)

但我得到以下例外:

SEVERE: Error Rendering View[/admin/index.xhtml]
java.lang.NumberFormatException: For input string: "rentid"
        at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
        at java.lang.Integer.parseInt(Integer.java:449)
        at java.lang.Integer.parseInt(Integer.java:499)
        at javax.el.ArrayELResolver.toInteger(ArrayELResolver.java:375)
        at javax.el.ArrayELResolver.getValue(ArrayELResolver.java:195)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:175)
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:116)
        at com.sun.el.parser.AstValue.getValue(AstValue.java:163)
        at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:219)
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
        at javax.faces.component.UIOutput.getValue(UIOutput.java:168)
        at com.sun.faces.renderkit.html_basic.HtmlBasicInputRenderer.getValue(HtmlBasicInputRenderer.java:205)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getCurrentValue(HtmlBasicRenderer.java:338)
        at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeEnd(HtmlBasicRenderer.java:164)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
        at org.primefaces.component.datatable.DataTableRenderer.encodeRow(DataTableRenderer.java:489)
        at org.primefaces.component.datatable.DataTableRenderer.encodeTbody(DataTableRenderer.java:416)
        at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:164)
        at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:80)
        at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:878)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1620) …
Run Code Online (Sandbox Code Playgroud)

java jsf facelets jsf-2

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

JSF视图在每个ajax请求上进行重建

我的JSF/RichFaces/Facelets ajax请求存在性能问题,而且我可以告诉它,因为整个组件树正在每个ajax请求上重建.即使我使用ajaxSingle = true,在a4j:区域中包装部分,声明单个部分进行重新渲染或根本不进行渲染,也会发生这种情况.我们的页面是一个包含许多嵌套级别的动态页面.该页面可能包含大约800-900个字段(inputText,富日历,selectOneMenus等).初始加载时间是一个问题,但我理解这个问题,它有很多领域.一旦我们有了初始构建/渲染时间,虽然我们已经将所有其他操作设计为ajax并且只需要reRender.从facelets调试日志我在任何ajax调用上看到这样的消息:

2011-08-24 22:19:03,054 DEBUG [facelets.viewhandler] (http-0.0.0.0-8080-2) Took
24445ms to build view: /oconsole/appfile.xhtml
2011-08-24 22:19:09,377 DEBUG [facelets.viewhandler] (http-0.0.0.0-8080-2) Took
6323ms to render view: /oconsole/appfile.xhtml
Run Code Online (Sandbox Code Playgroud)

我不确定我们正在做的事情是否导致整个组件树的重建,或者facelets是否正在确定由于某种原因(过时的缓存?)所需的这种需求.这是我们的堆栈:JBoss 5.1 JSF 1.2 RichFaces.3.3.3.Final Facelets 1.1.15 Seam 2.1.2

我尝试添加一些上下文参数来查看它们是否有用,但它们什么也没做:facelets.BUILD_BEFORE_RESTORE = false facelets.REFRESH_PERIOD = -1或5(如5分钟)

无论如何要告诉我们的观点是否正确缓存?我们没有delcare一个状态保存方法,所以我认为它默认为服务器端.我们所有的请求都发生在长时间运行的对话中.我不确定这是否会影响因为我认为视图会话缓存在会话级别?非常感谢任何帮助,谢谢.

更多调试后更新:

AjaxViewHandler(具有FaceletsViewHandler的成员变量)具有developmentMode = true set.我不确定这是否会导致facelets不缓存任何视图,因此任何更改都会在开发周期中刷新...?很难找到关于facelets/JSF缓存视图以及行为和控制的任何信息.此外,当我添加配置参数时:

<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>false</param-value>
</context-param>
Run Code Online (Sandbox Code Playgroud)

这没用!在调试器中,我仍然看到真正的设置.由于我们有很多子视图,我还尝试了com.sun.faces.numberOfLogicalViews和com.sun.faces.numberOfViewsInSession从15(默认值)到1000,这没有任何效果.

我也试过改变客户端状态保存没有任何运气.耗尽了想法......希望有人可以提供帮助....

似乎Seam 2.1自动初始化了RichFaces,我不确定它是否与它有关.....

java jsf richfaces facelets

11
推荐指数
1
解决办法
5886
查看次数

如何使用本机JavaScript在HTML DOM事件上调用JSF托管bean?

我需要在HTML DOM load事件期间使用ajax执行JSF托管bean操作方法,类似于jQuery $(document).ready(function() { $.ajax(...) }).我只能在这个项目中使用JSF生成的JavaScript.有没有办法在原生JSF中做到这一点?我可以使用哪个事件或者我可以使用哪个JSF ajax函数?

我正在使用JSF 2.0,Facelets和PrimeFaces.

javascript ajax jsf facelets primefaces

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

primefaces fileupload无效的文件类型doc,docx

我想使用primefaces fileUpload上传doc或docx文件,虽然我指定它显示的 文件类型无效的文件类型

在此输入图像描述

<p:fileUpload cancelLabel="#{contenu.annuler}"
    fileUploadListener="#{utilAdminBean.fileUpload}"
    allowTypes="/(\.|\/)(doc|docx)$/"
    multiple="false" mode="advanced" sizeLimit="52428800"
    showButtons="false" />
Run Code Online (Sandbox Code Playgroud)

jsf file-upload facelets primefaces

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

java.lang.NoClassDefFoundError:javax/servlet/jsp/jstl/core/Config

我正在使用Javascript和JSF为网站开发FB登录应用程序.我在这里发布了我的代码.问题是,当我运行我的应用程序时,它不会显示JSF页面,而是抛出以下异常:

Nov 28, 2013 7:21:46 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/FacebookLogin] threw exception [javax/servlet/jsp/jstl/core/Config] with root cause
java.lang.NoClassDefFoundError: javax/servlet/jsp/jstl/core/Config
    at com.sun.faces.application.view.JspViewHandlingStrategy.executePageToBuildView(JspViewHandlingStrategy.java:344)
    at com.sun.faces.application.view.JspViewHandlingStrategy.buildView(JspViewHandlingStrategy.java:153)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:99)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1023)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Run Code Online (Sandbox Code Playgroud)

这里有什么问题,我该如何解决?

jsf jstl facelets noclassdeffounderror

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

类org.springframework.web.jsf.el.SpringBeanFacesELResolver必须扩展类型javax.el.E​​LResolver

我试图将Spring集成到JSF应用程序中.

faces-config.xml,我已经包括这个:

<application>       
  <el-resolver>org.springframework.web.jsf.el.SpringBeanFacesELResolver</el-resolver>
  <view-handler>com.sun.facelets.FaceletViewHandler</view-handler>
</application>
Run Code Online (Sandbox Code Playgroud)

但它显示了一个我无法摆脱的奇怪警告:

Class org.springframework.web.jsf.el.SpringBeanFacesELResolver must extend the type javax.el.ELResolver
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

jsf spring facelets el

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

如何在JSF数据表中获取选定的行索引?

我在index.xhtml上有一个数据库

<h:dataTable style="border: solid 2px black;"
    value="#{IndexBean.bookList}" var="item"
    binding="#{IndexBean.datatableBooks}">

    <h:column>
        <h:commandButton value="Edit" actionListener="#{IndexBean.editBook}">
            <f:param name="index" value="#{IndexBean.datatableBooks.rowIndex}"/>
        </h:commandButton>
    </h:column>
</h:dataTable>
Run Code Online (Sandbox Code Playgroud)

我的豆子:

@ManagedBean(name="IndexBean")
@ViewScoped
public class IndexBean implements Serializable {
    private HtmlDataTable datatableBooks;

    public HtmlDataTable getDatatableBooks() {
        return datatableBooks;
    }

    public void setDatatableBooks(HtmlDataTable datatableBooks) {
        this.datatableBooks = datatableBooks;
    }

    public void editBook() throws IOException{
        int index = Integer.parseInt(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("index").toString());
        System.out.println(index);
    }
}
Run Code Online (Sandbox Code Playgroud)

我的问题是,即使单击不同的编辑按钮,我总是在服务器日志中获得相同的索引.想象一下,有一个集合提供给数据表.我没有在bean中表明过.

如果我将范围从ViewScope更改为RequestScope,它可以正常工作.可能是什么问题@ViewScoped?提前致谢 :)

编辑:

<h:column>
    <h:commandButton value="Edit" actionListener="#{IndexBean.editBook}" />
</h:column>
Run Code Online (Sandbox Code Playgroud)
public void editBook(ActionEvent ev) throws IOException{
    if (ev.getSource() != …
Run Code Online (Sandbox Code Playgroud)

java jsf facelets

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

将参数传递给从资源包到**以外的组件的消息:outputFormat**

是否有一种方便的方法将参数传递给从资源包到除h:outputFormat以外的组件的消息?

例如,这是合法的:

<h:outputFormat value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)

但我需要一个按钮,像这样(这将无法工作):

<h:commandButton value="#{myBundle['parametricMessage']}">
    <f:param value="#{myBundle['someParameterValue']}"/>
</h:commandButton>
Run Code Online (Sandbox Code Playgroud)

当然,我可以使用链接而不是按钮,我可以通过托管bean中的属性来实现,但在这个问题中,我正在寻找一种方便的方式来使用按钮...

我正在使用RichFaces 3.3.3,JSF2,facelets.

jsf resourcebundle richfaces facelets jsf-2

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

PrimeFaces DataTable CellEdit获取实体/对象

我有一个数据表,它显示基于List <>的各种实体.当我选择一个单元格进行编辑时,我希望能够以某种方式获取实体以便更新它.当然有event.getRowIndex,然后我可以使用List <>,但这并不总是方便的.是否有另一种方法可以从CellEditEvent获取实体?

jsf facelets primefaces

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