我目前有以下JSF:
<p:outputLabel value="#{msg['label.address.province']}"
rendered="#{address.country ne CountryEnum.UNITED_STATES.country}"/>
<p:outputLabel value="#{msg['label.address.province']}"
rendered="#{address.country eq CountryEnum.UNITED_STATES.country}"/>
Run Code Online (Sandbox Code Playgroud)
我的属性文件包含
label.address.province=Province
label.address.state=State
Run Code Online (Sandbox Code Playgroud)
这样做很好,当国家是"美国"时,我的标签输出"州",而对于任何其他国家,它输出"省".
我曾经想过要做的是尝试摆脱两个标签条目,只使用一个,在messages.properties中使用choiceformat.我的第一次尝试看起来像:
<h:outputFormat value="#{msg['label.address.province.choice']}">
<f:param value="#{address.country.id}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
同
label.address.province.choice={0, choice, 1#Province|2#State|3#Province}
Run Code Online (Sandbox Code Playgroud)
在编辑地址时哪个工作正常.但是,根据我的业务规则添加新地址时,所有字段都是空白的.这意味着address.country为null,这意味着我的choiceformat生成'null'作为输出.
然后我想用omnifaces:
<h:outputFormat value="#{msg['label.address.province.choice']}">
<f:param value="#{o.coalesce(address.country.id, '1')}"/>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
但这也产生了空.address是我的托管bean,country是我自己的简单javabean类,id是type的属性java.io.Serializable.
我知道"address.country.id"是由EL评估的,当它遇到null并且没有抛出NPE时它"很好地"停止.但是,合并是否可能不会做同样类型的行为,我传入的内容必须是非EL表达式?对不起,我刚刚开始我的JSF冒险,所以我可能没有使用正确的单词.
我也愿意采用一种完全不同的方法,这仍然会将我的outputLabels减少到某种类型的单个标签.
我正在使用Mojarra 2.1.21,Primefaces 3.5,Omnifaces 1.4.1,Java 7,Tomcat 7
PF 3.5(4.0),Omnifaces 1.6.3,Mojara 2.1.21
是否可以控制将在JSF xhtml页面内发送的http标头?我的意思是:
.xhtml:
<html xmlns:http="a cool name space">
<h:head>
<http:headers header="Cache-Control" value="no-cache, no-store, must-revalidate" />
</h:head>
<h:body> .... </h:body>
</html>
Run Code Online (Sandbox Code Playgroud) 我试图用primefaces自动完成组件在我的项目,以避免编写特定的转换器,每个列表对象,我尝试使用omnifaces作为建议在这里和这里的"BalusC",我试图复制同样的方法处理,但不能能够得到这项工作.如果我在这里遗漏了什么,请查看下面的代码片段和建议吗?
代码[f:selectOneMenu]的第一部分工作正常,没有任何问题
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html"
xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
xmlns:p="http://primefaces.org/ui"
xmlns:f="http://xmlns.jcp.org/jsf/core">
<ui:composition template="WEB-INF/layout/layout.xhtml">
<ui:define name="content">
<h:form>
<h:outputText id="selected_status"
value="#{mybean.objLuStatus.strDescColVal}" />
<!-- h:selectOneMenu Working fine -->
<h:selectOneMenu id="iterator2" value="#{mybean.objLuStatus}"
converter="omnifaces.SelectItemsConverter">
<f:selectItem itemLabel="Choose item" noSelectionOption="true" />
<f:selectItems value="#{mybean.lstStatus}" var="entity"
itemLabel="#{entity.strDescColVal}" itemValue="#{entity}" />
<f:ajax render="selected_status" />
</h:selectOneMenu>
<!-- p:autoComplete is NOT Working -->
<p:autoComplete id="iterator3" value="#{mybean.objLuStatus}"
converter="omnifaces.ListConverter" dropdown="true" var="entity"
itemLabel="#{entity.strDescColVal}"
placeholder="----- Select One -----" itemValue="#{entity}"
completeMethod="#{mybean.completeList}">
<f:ajax render="selected_status" />
</p:autoComplete>
<h:commandButton value="Submit" action="#{mybean.post}" />
</h:form>
</ui:define>
</ui:composition>
</html>
Run Code Online (Sandbox Code Playgroud)
是否有任何JSF实用工具包或PrimeFaces/OmniFaces等库中可用的HTML清理程序或清理方法?
我需要通过p:编辑器清理用户的HTML输入,并使用escape="true"stackexchange样式显示安全的HTML输出.在显示HTML之前,我正在考虑将已清理的输入数据存储到数据库中,以便它可以安全使用,escape="true"并且XSS不是危险的.
给出的问题是传递复杂参数(参见下面的代码示例)在JSF中不起作用.
<h:outputFormat value="Final result is: {0}">
<f:param>
<h:outputFormat value="{0} to {1}">
<f:param value="#{mngr.lowerBound}"/>
<f:param value="#{mngr.upperBound}"/>
</h:outputFormat>
</f:param>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
我不是在寻找使用ManagedBean的解决方案,如下所示:
<h:outputFormat value="Final result is: {0}">
<f:param value="mngr.formattedParams />
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)
但是有一个适用于OmniFaces的解决方案: JSF-2.H:OUTPUTFORMAT.复杂的f:param
我想知道PrimeFaces中是否还有解决方案?
将 EJB 注入多模块 Maven Java EE 7 项目中的 JSF 托管 bean 在 Payara 4.x 和 5.x 以及 Glassfish 4.x 和 5.x 以及 WildFly 11.0.0.Final 上都失败了认为这不是我最初认为的 Payara/Glassfish 错误 [1]。
WAR 模块中的一个简单的 JSF 支持 bean
@Named
@ApplicationScoped
@Eager
public class Init {
@EJB
private InitService initService;
public Init() {
}
@PostConstruct
public void init() {
initService.init();
}
}
Run Code Online (Sandbox Code Playgroud)
在 JAR 模块中带有 EJB 接口
@Local
public interface InitService {
void init();
}
Run Code Online (Sandbox Code Playgroud)
以及在 EJB 模块中的实现
@Stateless
public class DefaultInitService implements InitService {
@PersistenceContext …Run Code Online (Sandbox Code Playgroud) 我一直面临着一个问题Omnifaces 2.1。
我byte[]在我的数据库中存储了一个图像类型,其中包含一个声明 java 类,如下所示:
@Lob
private byte[] image;
Run Code Online (Sandbox Code Playgroud)
在我的 xhtml 文件中,我在一个包含图像的类上有一个循环:
<ui:repeat var="listT" value="#{eventBean.listEvents}">
<o:graphicImage value="#{eventBean.getImage(listT.idEvent)}" dataURI="true" />
</ui:repeat>
Run Code Online (Sandbox Code Playgroud)
现在bean我尝试实现getImage()omnifaces文档中提到的功能:
@ManagedBean
@ViewScoped
public class EventBean implements Serializable {
private static final long serialVersionUID = 1L;
@EJB
private EventServiceLocal eventServiceLocal;
private Event event = new Event();
private List<Event> listEvents;
private List<Event> listEventsval;
private static Event eventSt;
private UploadedFile file;
public byte[] getImage(int eventID) {
return eventServiceLocal.listEventspicture(eventID);
}
Run Code Online (Sandbox Code Playgroud)
当我执行这个时,我没有图像,当我检查元素时,我得到了这个结果:
<o:graphicimage value="[B@1aeef88" datauri="true"></o:graphicimage>
Run Code Online (Sandbox Code Playgroud) 我想在我的JSF 2应用程序中做的是根据浏览器版本设置正确的html样式,这里是示例代码:
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <!--<![endif]-->
Run Code Online (Sandbox Code Playgroud)
如何在JSF 2中做到这一点?什么是最好/最简单的方法?
我在Omnifaces(o:conditionalComment)中发现了一些有趣的东西,但它只允许有条件地加载整个css,这对我来说是无用的......
我正在尝试将一个Web项目(中的所有JAR WEB-INF/lib)迁移到Maven Web项目(中的所有JAR pom.xml)。
该项目使用以下库:
它在TomEE上运行。
TomEE启动时会出现以下错误:
NoClassDefFoundError:javax / faces / component / UIViewAction
但是,TomEE在类路径上提供了JSF2库。
这是我的pom.xml。
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lb</groupId>
<artifactId>XXX</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>XXX</name>
<description>Application XXX</description>
<url>http://XXX.fr</url>
<organization>
<name>XXX</name>
<url>http://XXX.fr</url>
</organization>
<inceptionYear>2016</inceptionYear>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<javase.version>1.7</javase.version>
<javaee.version>7.0</javaee.version>
</properties>
<developers>
<developer>
<id>XXX</id>
<name>YYY</name>
<email>ZZZ@gmail.com</email>
</developer>
</developers>
<build>
<directory>${basedir}/target/${project.artifactId}-${project.version}</directory>
<finalName>XXX</finalName>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.java</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${javase.version}</source>
<target>${javase.version}</target>
<encoding>UTF-8</encoding> …Run Code Online (Sandbox Code Playgroud) 我正在尝试跟踪视图使用情况(达到默认的 15 计数限制),但不太确定从哪里获取此信息。它在 FacesContext 中可用吗?
使用 JSF 2.2、ICEfaces 3.3 和 Omnifaces 2.2。
omnifaces ×10
jsf ×9
jsf-2 ×3
primefaces ×3
autocomplete ×1
el ×1
html ×1
http-headers ×1
jakarta-ee ×1
java ×1
jsf-2.2 ×1
maven ×1
payara ×1
servlets ×1
tomee ×1
tomee-7 ×1
view-scope ×1
wildfly ×1