我有一个ap:selectOneMenu的问题,无论我做什么我都无法让JSF调用JPA实体上的setter.JSF验证失败,显示以下消息:
form:location:验证错误:值无效
我有这个工作在几个相同类型的其他类(即,连接表类),但不能为我的生活让这一个工作.
如果有人可以针对此类问题提出一些故障排除/调试技巧,我们将不胜感激.
使用日志语句我已经验证了以下内容:
Conveter将返回正确的,非null数值.setLocation(Location location)永远不会调用setter .这是我能做的最简单的例子,它根本不起作用:
<h:body>
<h:form id="form">
<p:messages id="messages" autoUpdate="true" />
<p:selectOneMenu id="location" value="#{locationStockList.selected.location}" converter="locationConverter">
<p:ajax event="change" update=":form:lblLocation"/>
<f:selectItems value="#{locationStockList.locationSelection}"/>
</p:selectOneMenu>
</h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
转换器:
@FacesConverter(forClass=Location.class, value="locationConverter")
public class LocationConverter implements Converter, Serializable {
private static final Logger logger = Logger.getLogger(LocationConverter.class.getName());
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value.isEmpty())
return null;
try {
Long id = Long.parseLong(value);
Location location = ((LocationManagedBean) context.getApplication().getELResolver().getValue(context.getELContext(), null, "location")).find(id);
logger.log(Level.SEVERE, …Run Code Online (Sandbox Code Playgroud) 这是在GlassFish 3.1上,使用PrimeFaces而不是Mojarra,并使用MyFaces CODI进行腌制.几乎每个请求都会出现以下消息:
警告:PWC4011:无法从上下文/com.myapp_war_0.1将请求字符编码设置为UTF-8,因为已经读取了请求参数,或者已经调用了ServletRequest.getReader()
自从我开始这个项目以来,这已经发生了 - 到目前为止,我一直忽视它,但现在我已经意识到我浪费了很多时间阅读它.我在这里发现了一个有趣但不完整的工作,但我不明白.
有人可以建议如何在不抑制其他可能的警告消息的情况下压缩此消息吗?
在其中一个项目中,我在表格数据上提供非英语内容(芬兰语).我们正在使用JSF 2.0和PrimeFaces.将数据提交到服务器时遇到问题.提交表单时数据已损坏.只有芬兰人在这方面变得腐败.
有没有人遇到过这个问题并找到了解决方案?
我通常可以写捷克字符串到表单:

但是在验证之后(以及当我将收集的字符串发送到数据库时)字符串在其他一些字符集中:

h:outputTexts(jméno,příjmení)仍然正常显示,h:inputTexts不是.
我应该在哪里寻找问题?
更新: HTTP响应标头:

解:
request.setCharacterEncoding("UTF-8")in 创建过滤器Filter#doFilter() <f:view contentType="text/html" encoding="UTF-8"/>到主xhtml将这些行添加到hibernate.cfg.xml:
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
让我与primefaces 3.1分享我独特的失望,直到现在......我在RichFaces应用程序中使用phew组件,当我意识到问题时,一切都很好,我的母语中的一些字符显示错误,甚至是UTF-8在所有地方宣布的charset我知道它是必需的.
当输入一些特殊字符如"圣保罗"并在页面中提交时,会出现问题.提交后的数据重新显示为"S?£o Paulo"
我已经尝试了下面的解决方法:
1)Eclipse IDE:文本文件enconding选项
2)jsf文件:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
Run Code Online (Sandbox Code Playgroud)
3)JBOSS server.xml:
<Connector protocol="HTTP/1.1" URIEncoding="UTF-8" port="${jboss.web.http.port}" address="0.0.0.0"
redirectPort="${jboss.web.https.port}" />
Run Code Online (Sandbox Code Playgroud)
4)的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
Run Code Online (Sandbox Code Playgroud)
5)jsf文件:
<h:form acceptcharset="UTF-8" enctype="application/form-data">
Run Code Online (Sandbox Code Playgroud)
6)将primefaces版本升级到3.2
谢谢你的帮助!;-)
我正在尝试将Primefaces中的示例实现为WAB包.
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui" >
<h:head>
<ui:insert name="header">
<ui:include src="header.xhtml"/>
</ui:insert>
</h:head>
<h:body>
<h1><img src="resources/css/images/icon.png" alt="NVIDIA.com" /> History Center</h1>
<!-- layer for black background of the buttons -->
<div id="toolbar" style="margin: 0 auto; width:1180px; height:30px; position:relative; background-color:black">
<!-- Include page Navigation -->
<ui:insert name="Navigation">
<ui:include src="Navigation.xhtml"/>
</ui:insert>
</div>
<div id="logodiv" style="position:relative; top:35px; left:0px;">
<h:graphicImage alt="Demo edit form" style="position:relative; top:-20px; left:9px;" value="resources/images/logo_linuxz.png" />
</div> …Run Code Online (Sandbox Code Playgroud) 我有一个非常简单的应用程序,我的索引页面中有一个inputtext和一个转到page2.xhtml的按钮.
<h:body>
<h:form>
<h:inputText value="#{mainBean.testValue}"/>
<p:commandButton update="myoutput" value="ajax call" ajax="false"/>
<p:separator />
<h:commandButton action="#{mainBean.gotoPageTwo}" value="goto Page2"/>
<br/>
<h:outputText value="#{mainBean.testValue}" id="myoutput"/>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
我用PrimeFaces 2.2.1测试了这个应用程序,没有问题.但是在提交了上面的每个按钮之后,我的UTF-8字符会被破坏.我测试过滤器,但它不起作用.它是PrimeFaces 3.x中的一个错误吗?任何人都可以解决这个问题吗?
我有一个PrimeFaces 3.3/JSF应用程序,我部署到JBoss AS 7.1.为了显示我的数据,我使用p:dataTable和一些过滤头.这是代码(缩小源代码后):
<p:outputPanel id="custDataTable">
<p:dataTable var="item" value="#{customerController.items}" rowKey="#{item.id}"
selection="#{customerController.current}" selectionMode="single" id="customersTable">
<p:column headerText="Surname" sortBy="#{item.surname}" filterBy="#{item.surname}" id="surname">
#{item.surname}
</p:column>
<p:column headerText="Age" sortBy="#{item.age}" filterBy="#{item.age}" id="age" styleClass="age">
#{item.age}
</p:column>
<p:column headerText=" ">
<p:spacer width="20" height="0" />
<p:commandButton update=":custForm" ajax="false" action="#{customerController.prepareEdit}" value="edit">
<f:setPropertyActionListener value="#{item}" target="#{customerController.current}" />
</p:commandButton>
</p:column>
</p:dataTable>
</p:outputPanel>
Run Code Online (Sandbox Code Playgroud)
PrimeFaces p:对数字Age列的dataTable过滤始终有效,但在Surname列上会出现奇怪的行为.当backing bean的items实例变量具有姓氏中包含ASCII数据的元素时,过滤工作.但是当存在UTF8数据时,过滤仅部分起作用:
[1]我可以在列标题字段中键入我的语言环境的UTF8字符,结果确实已过滤(这是可行的部分).
[2] backing bean的当前实例变量始终为null.即绑定:
selection="#{customerController.current}"
Run Code Online (Sandbox Code Playgroud)
似乎不起作用.我在CustomerController :: prepareEdit方法中添加了一些日志记录,当按下edit p:commandButton时,该值设置为null .因此,我无法编辑基于 …
在使用JSF和EclipseLink JPA到MySQL数据库的Web应用程序中,我遇到了很大的问题.
当我从数据库中读取数据时,JSF以UTF-8读取和写入我的字符串.但在数据库中字符很糟糕.
fe:输入字符:"żźćółzxcv",写在数据库中:"????? zxcv".但是如果我手动将数据写入数据库,例如:"żźćółzxcv",那么在JSF中读取是完美的.
我从这里尝试了一切:通过PrimeFaces输入组件检索的Unicode输入被破坏
我发现JSF中的编码很好,但问题出在java中,因为如果我手动设置的话
current.setUwagiZ("???ó??????ó???? TE");
getFacade().edit(current);
Run Code Online (Sandbox Code Playgroud)
在数据库记录中是错误的: ???ó??????ó???? TE
我在JDBC Resource中设置了characterEncoding和useUnicode.此外,当NetBeans编码中的某些工具执行命令正常并且MySQL中的数据为UTF-8时,连接似乎很好.
所以问题是java,但我完全不知道如何解决这个问题:(
jsf ×7
jsf-2 ×6
primefaces ×6
java ×3
jpa ×2
utf-8 ×2
converter ×1
glassfish-3 ×1
java-ee ×1
lifecycle ×1
mojarra ×1
validation ×1