我已经阅读了一些关于在JSF 2中编写复合组件甚至关于定义嵌套复合组件的文章,但我没有找到定义可以接受未定义数量的子组件的复合组件的示例.
我希望能够创建一个复合组件,可以使用与此类似的方式:
<special:fieldGroup>
<special:field name="x" value="..."/>
<special:field name="y" value="..."/>
...
</special:fieldGroup>
Run Code Online (Sandbox Code Playgroud)
是否有关于如何使用新的JSF 2语法实现此目的的示例或解释?
谢谢!
对JSF来说很新,当我阅读教程时,我很容易在JSF和Facelets之间混淆......
什么是Facelets?JSF和Facelets是一样的吗?...
Facelets与JSTL有何不同?
我知道我可以使用 ui:param 从构建在模板上的组合中传递字符串
像这样:http : //www.mkyong.com/jsf2/how-to-pass-parameters-to-jsf-2-0-template-file/
然后我可以将 XHTML 中的参数用于模板文件。
你能发送一个数组吗?
IE
<ui:insert name="header" >
<ui:include src="/template/common/commonHeader.xhtml">
<ui:array name="tagArray" values="val1, val2, val3" />
</ui:include>
</ui:insert>
Run Code Online (Sandbox Code Playgroud) 我在Facelet模板中定义了标题,正文和页脚.我想在我的登录页面中隐藏页眉和页脚.我怎样才能做到这一点?
我遇到了自定义标签的问题.
这是问题所在.我创建了一个在我的JSF页面中使用的标记:
<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:t="http://myfaces.apache.org/tomahawk"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:c="http://java.sun.com/jstl/core">
... some stuff ...
<h:inputText id="#{id}" value="#{value}" binding="#{binding}" label="#{label}"/>
... some stuff ...
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
我希望以这种方式在我的页面中使用此组件(我的组件名为gp:inputText):
<gp:inputText value="#{myBean.myValue}" id="myId" label="myLabel" binding="#{myBean.myUiComponent}" />
Run Code Online (Sandbox Code Playgroud)
但我也想使用相同的组件,但没有绑定inputText.我怎样才能做到这一点?我试图只使用我的组件而不指定绑定但它不起作用.例如,绑定值似乎不能像标签值那样为空.
谢谢您的帮助 !
一旦我尝试通过"http://localhost:8080/beginner/faces/index.jsf"打开我的index.xhtml,我将得到以下异常:
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
java.lang.NullPointerException
com.sun.faces.renderkit.RenderKitImpl.createResponseWriter(RenderKitImpl.java:228)
com.sun.faces.application.view.JspViewHandlingStrategy.renderView(JspViewHandlingStrategy.java:214)
com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125)
javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62)
note The full stack trace of the root cause is available in the JBoss Web/7.0.13.Final logs.
Run Code Online (Sandbox Code Playgroud)
在eclipse中,我通过"新Maven项目向导"创建了一个Maven项目并选择了Group Id:"org.jboss.spec.archetypes",Artifact Id"jboss-javaee6-webapp-blank-archetype"version:7.13我正在使用JBoss 7.1.1.FINAL并尝试了JDK 6和JDK7
index.xthml看起来像这样:
<?xml version="1.0" encoding= "UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html">
<h:head>
<title>First JSF</title>
</h:head>
<h:body>
<h1>Hello there</h1>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
我找了几个小时是有原因的,但是找不到任何解决方案,尽管我做了这个研讨会书告诉我要做的每一步.
我有一个主要的 HTML 页面,其中包括detail.xhtml和duo.xhtml。
现在duo.xhtml还包括detail.xhtml,这会导致重复的 ID,当然它不起作用。我能做些什么来解决这个问题?我不想管理冗余代码。
主要的:
<ui:composition ...>
<ui:define name="center">
<ui:insert name="insertDuo">
<ui:include src="/includes/duo.xhtml" />
</ui:insert>
...
<p:dialog header="x" widgetVar="detDialog" id="dlg" modal="true" appendTo="@(body)">
<ui:insert name="insertDetail">
<ui:include src="/includes/detail.xhtml" />
</ui:insert>
Run Code Online (Sandbox Code Playgroud)
二人组:
<ui:composition>
<p:dialog header="y" widgetVar="newDuoDialog" id="newDuoDlg" modal="true" >
<p:layout id="layout">
<p:layoutUnit position="west">
<ui:insert name="insertDetailStmt">
<h:form id="stmtDetailForm">
<ui:include src="/includes/detail.xhtml" />
</h:form>
</ui:insert>
</p:layoutUnit>
Run Code Online (Sandbox Code Playgroud)
细节:
<p:accordionPanel id="accordion">
Run Code Online (Sandbox Code Playgroud)
组件参考:
<p:commandButton value="z" update=":accordion:duoDlgForm2:pickList"/>
Run Code Online (Sandbox Code Playgroud) 是否可以从JavaServer Faces替换标准错误页面,例如
500 Internal Server Error
?
这些信息包括堆栈跟踪等信息.但是对于用户来说,当页面处于生产模式时,我想显示一个更友好的页面,说明请求没有成功.
我把它包含在我的index.jsp JSF文件中:
<%@ taglib prefix="ui" uri="http://java.sun.com/jsf/facelets"%>
Run Code Online (Sandbox Code Playgroud)
和Eclipse强调URL,悬停给出:
Cannot find the tag library descriptor for "http://java.sun.com/jsf/facelets"
Run Code Online (Sandbox Code Playgroud)
部署并尝试使用Tomcat插件启动Tomcat 6会导致:
|STDOUT| 2010-03-03 17:57:29,872 | INFO | [main]: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
|STDOUT| 2010-03-03 17:57:29,904 | INFO | [main]: ServletContext 'C:\Program Files\Apache Software Foundation\Tomcat 6.0\webapps\myapp\' initialized.
|STDOUT| 2010-03-03 17:57:29,904 | INFO | [main]: Checking for plugins:org.apache.myfaces.FACES_INIT_PLUGINS
03-Mar-2010 17:57:29 org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
03-Mar-2010 17:57:29 org.apache.catalina.core.StandardContext start
SEVERE: Context [/myapp] startup failed due to previous errors
Run Code Online (Sandbox Code Playgroud)
...
03-Mar-2010 17:57:30 com.sun.faces.config.ConfigureListener contextDestroyed
SEVERE: Unexpected …Run Code Online (Sandbox Code Playgroud) jsf2 h:outputText标记没有使用MessageFormat格式化h:outputText
我的面孔配置
<application>
<resource-bundle>
<base-name>Messages_pt_BR</base-name>
<var>bundle</var>
</resource-bundle>
</application>
Run Code Online (Sandbox Code Playgroud)
我的资源包:
...
EventPageTitle=Event: {0}
...
Run Code Online (Sandbox Code Playgroud)
我的JSF2 XHTML:
<h:outputText value="#{bundle.EventPageTitle}" >
<f:param value="#{seuTicketEventController.selected.eventName}"/>
</h:outputText>
Run Code Online (Sandbox Code Playgroud)
输出:
Event: {0}
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这个问题?我到处搜索但我无法解决!