Facelets是否具有更整洁或更易读的国际化用户界面文本标签的任何功能,否则您可以使用JSF执行哪些操作?
例如,使用普通的JSF,使用h:outputFormat是一种在消息中插入变量的非常详细的方法.
澄清:我知道我可以添加一个消息文件条目,如下所示:
label.widget.count = You have a total of {0} widgets.
Run Code Online (Sandbox Code Playgroud)
并显示此(如果我使用Seam):
<h:outputFormat value="#{messages['label.widget.count']}">
<f:param value="#{widgetCount}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
但输出一个句子很麻烦 - 只是给JSF一个坏名字的东西.
我正在使用icefaces选择菜单从用户列表中选择一个用户,我想为每个用户重复selectItem这里是我尝试的:
<ice:selectOneMenu id="users">
<ui:repeat value="#{user.getUserList()}" var="user">
<f:selectItem itemLabel="#{user.name}" itemValue="#{user.id}"/>
</ui:repeat>
</ice:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
的UserBean:
@Component("user")
@Scope("view")
Public class UserBean{
Public List<User> getUserList() throws Exception {
return userService.getAllUsers();
}
}
Run Code Online (Sandbox Code Playgroud)
注意: UserBean不包含属性id,它们存在于用户实体中的名称.请指教,谢谢.
如何设置p:面板组件的标题样式?我想设置panel_header div的高度.
<p:panel id="panel"
toggleSpeed="500" toggleable="true">
<f:facet name="header" >
<p:outputPanel style="float:left;">
<p:commandButton process="@this" id="new"
oncomplete="dialog.show();" icon="ui-icon-plus" />
<p:spacer width="15px;" />
</p:outputPanel>
<h:outputLabel value="Title" />
</f:facet>
</p:panel>
Run Code Online (Sandbox Code Playgroud) 我有一个名为test.xhtml的文件我试图在Facelets中使用foreach访问哈希映射,但它没有显示键值对,我的代码如下所示.这是怎么造成的,我该如何解决?
<html xmlns:c="http://java.sun.com/jstl/core" xmlns:ui="http://java.sun.com/jsf/facelets">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<h:body>
<f:view>
<c:forEach var="nameMap" items="${specificationAutogege.details}">
<p> ${nameMap.key}</p>
</c:forEach>
</f:view>
</h:body>
Run Code Online (Sandbox Code Playgroud)
是否可以在Facelets中使用JSTL?
HTML输出呈现如下:
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:c="http://java.sun.com/jstl/core">
<head>
<title>JSTL Simple Conditional Execution Example</title>
</head>
<body>
<c:forEach var="nameMap" items="{Versnellingsk=A very long text come here, Kleur=ZWART Two, Model=3008, Carrosiere=5 deures MPV, A very long text come here=Date Here, BrandShoert=E, Type=3008 Hybrid4 2.0 HDi, Merk=Peugeot, Bowjaar=2011 Shortgate}" varstatus="true">
<p/>
</c:forEach>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我正在尝试以编程方式使用Mojarra JSF 2编译器,以检查任何页面的xhtml的正确性。
到目前为止,我已经了解了,但是编译器不会针对特定标签库中不存在的标签进行错误处理。它会执行标准的XML名称空间检查,但是如果显示rich:spacer,则应该出错(在Richfaces 4.x中已将其删除)。在运行时会进行检查。
有什么想法吗?这是我的代码:
@RunWith( PowerMockRunner.class )
@PrepareForTest( { WebConfiguration.class, FacesContext.class } )
public class XhtmlValidatorTest
{
@Test
public void test() throws IOException
{
WebConfiguration webConfiguration = PowerMock.createMock( WebConfiguration.class );
PowerMock.mockStatic( WebConfiguration.class );
WebConfiguration.getInstance();
PowerMock.expectLastCall().andReturn( webConfiguration ).anyTimes();
FaceletsConfiguration faceletsConfiguration = PowerMock.createMock( FaceletsConfiguration.class );
webConfiguration.getFaceletsConfiguration();
PowerMock.expectLastCall().andReturn( faceletsConfiguration ).anyTimes();
faceletsConfiguration.isProcessCurrentDocumentAsFaceletsXhtml(EasyMock.isA( String.class ) );
PowerMock.expectLastCall().andReturn(true).anyTimes();
faceletsConfiguration.isConsumeComments( EasyMock.isA( String.class) );
PowerMock.expectLastCall().andReturn(false).anyTimes();
faceletsConfiguration.isConsumeCDATA( EasyMock.isA( String.class ) );
PowerMock.expectLastCall().andReturn(false).anyTimes();
webConfiguration.isOptionEnabled(BooleanWebContextInitParameter.EnableMissingResourceLibraryDetection);
PowerMock.expectLastCall().andReturn( false ).anyTimes();
webConfiguration.isOptionEnabled(BooleanWebContextInitParameter.EnableCoreTagLibraryValidator );
PowerMock.expectLastCall().andReturn( true ).anyTimes();
FacesContext facesContext = PowerMock.createMock( FacesContext.class ); …Run Code Online (Sandbox Code Playgroud) 是否有关于如何覆盖模板定义的规则<ui:define>用<ui:insert>.
模板A:
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets">
template A content<br/>
<ui:insert name="content"/>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
模板B:
<ui:composition template="/resources/templates/A.xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets">
<ui:define name="content">
template B content<br/>
<ui:insert name="content"/>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
网站1:
<ui:composition template="/resources/templates/B.xhtml">
Site 1<br/>
<ui:define name="content">
site content<br/>
</ui:define>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
输出:
Site 1
site content
Run Code Online (Sandbox Code Playgroud)
该内容<ui:define>取自站点1,不会呈现模板的内容.
网站2:
<ui:composition template="/resources/templates/B.xhtml">
Site 2<br/>
</ui:composition>
Run Code Online (Sandbox Code Playgroud)
输出:
Site 2
template B content
template A content
Run Code Online (Sandbox Code Playgroud)
其内容<ui:define>取自模板B和模板A,其中奇怪的是模板B内容在模板A的内容之前呈现.
是否可以使用相同的名称覆盖<ui:define>新的<ui:insert>?
为嵌套创建新名称<ui:insert>是一种可能性,但很难跟踪层次结构以及插件的使用位置.
我正在尝试创建一个页面,允许用户登录系统,然后导航到主页.我已经设法让它做一个或另一个,但无法弄清楚如何让它做两件事.我已遍历所有网站,无法找到合适的答案.请帮忙.我的代码如下:XHTML:
<h:form>
<p:growl id="growl" showDetail="true" life="3000" />
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="username" value="Username: " />
<p:inputText value="#{login.username}" id="username" required="true"
label="username" />
<h:outputLabel for="password" value="Password: " />
<h:inputSecret value="#{login.password}" id="password" required="true"
label="password" />
<p:commandButton ajax="false" id="loginButton" value="Login"
update="growl" actionListener="#{login.login}" />
</h:panelGrid>
</h:form>
Run Code Online (Sandbox Code Playgroud)
Java类:
@ViewScoped
@ManagedBean
@SessionScoped
public class Login implements Serializable
{
private static final long serialVersionUID = 1L;
private String username;
private String password;
public String login(ActionEvent actionEvent)
{
RequestContext context = RequestContext.getCurrentInstance();
FacesMessage msg = null;
boolean loggedIn = …Run Code Online (Sandbox Code Playgroud)
当涉及到JSF视图技术时,我并不是百分之百地说明了JSP和Facelets之间的区别.
我在谷歌搜索,每个人都以同样的方式解释差异(一些只是复制其他人).
我想知道如果我有一个JSP页面(文档样式,使用jsp:root,所以没有scriptlet)或Facelets页面,当reuqest进入时,以及在RenderResponse 中执行每个JSF标记时有什么区别.ui:include和jsp:include
之间的区别是什么?我理解JSP/Servlet非常好,但JSF内部并不是那么多.
谢谢,我希望你不会像所有其他JSP vs Facelets问题一样看到这个问题.
ps:我发现的一小部分响应是Facelets没有在Java Servlet Class中转换,就像JSP一样(这使得它更快),而是使用SAX解析器,我不明白它在它的作用回调方法.
我在我的公司"继承"了一个JSF 2(JSF 2.2.7)应用程序并面临java.lang.IllegalStateException,因为两个组件似乎具有相同的ID.
视图的结构如下(为了说明目的,我提取了相关代码,它可能包含一些拼写错误/无效语法,因为我更改了一些名称):
<p:commandButton id="editButton"
action="#{controller.prepareItem()}"
update=":itemEditDlg" oncomplete="PF('itemtEditDlg').show()" />
<comp:editItemDlg id="itemEditDlg" />
<p:dialog id="anotherDlg" >
<h:form id="anotherForm">
<c:forEach items="#{controller.allArgs}" var="arg" >
<!-- next line is the problem -->
<comp:mycomponent arg="#{arg}" />
</c:forEach>
</h:form>
</p:dialog>
Run Code Online (Sandbox Code Playgroud)
mycomponent.xhtml如下所示:
<cc:interface>
<cc:attribute name="arg" required="true" />
</cc:interface>
<cc:implementation>
<p:inputText id="argValue" value="#{cc.attrs.arg}" />
<p:message id="argValueMessage" for="argValue" />
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)
重要:mycomponent组件也在editItemDlg中使用(与"anotherDlg"中的方式相同),即在对话框和forEach循环中)
如果我点击editButton,我得到:
java.lang.IllegalArgumentException: Component ID anotherForm:j_idt192:argValue
has already been found in the view.
Run Code Online (Sandbox Code Playgroud)
它相当奇怪,因为"anotherDlg"在这种情况下并不是开放的,但显然已经渲染了.
我在StackTrace中获得以下信息(仅显示相关部分):
+id: j_idt192
type: javax.faces.component.UINamingContainer@399bd0dc
+id: j_id2
type: javax.faces.component.UIPanel@24ad3910
+id: argValue <===============
type: org.primefaces.component.inputtext.InputText@687d5c3f …Run Code Online (Sandbox Code Playgroud) 这个问题是从Mac生成的:JSF:为什么开发阶段的JSF Web应用程序并不总是能够捕获复合组件的变化?.如果我可以在这里回答这个问题,我会有一个蛮力的策略来解决其他报告的问题,但这个问题有一个独立的目的.
问:如何在运行的Web应用程序中以编程方式强制清除Facelets内存缓存(以便我可以创建从[Clear Facelets Cache]按钮调用的侦听器)?
我正在使用NetBeans8.1beta和Glassfish4.1,并在NetBeans项目的/ build/web上进行部署.