标签: myfaces

服务器重启后的 JSF 问题:找不到保存的视图状态

继续解决这个问题,我已经更换了钻嘴鱼科通过的MyFaces和升级JDK,当我继续工作形式的服务器重新启动后,显示以下错误:

发生错误:

/food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml

Caused by:
javax.faces.application.ViewExpiredException - /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
Run Code Online (Sandbox Code Playgroud)

控制台

SEVERE: Exception loading sessions from persistent storage
java.lang.IllegalStateException: unread block data
    at java.io.ObjectInputStream$BlockDataInputStream.setBlockDataMode(ObjectInputStream.java:2376)
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪:

javax.faces.application.ViewExpiredException: /food.xhtmlNo saved view state could be found for the view identifier: /food.xhtml
    at org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
    at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
    at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:240)
    at …
Run Code Online (Sandbox Code Playgroud)

java jsf myfaces

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

MyFaces JSF impl与Glassfish 3.1无法正常工作

我尝试使用Glassfish使用JSF 2的MyFaces impl,但我无法这样做.我在项目中添加了以下jar:

  • 公地beautils-1.8.3.jar
  • commos编解码器-1.3.jar
  • 公地集合-3.2.jar
  • 公共沼气池-1.8.jar
  • 共享记录-1.1.1.jar
  • MyFaces的-API-2.1.7.jar
  • myfaces-bundle-2.1.7.jar 编辑根据BalusC的回答删除了这个jar
  • MyFaces的-IMPL-2.1.7.jar

我还将文件glassfish-web.xml添加到WEB-INF,其中包含以下内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app error-url="">
  <class-loader delegate="true"/>
  <property name="useBundledJsf" value="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</glassfish-web-app>
Run Code Online (Sandbox Code Playgroud)

编辑
根据BalusC的回答,我删除了myfaces-bundle-2.1.7.jar,现在我得到以下异常:

GRAVE: PWC1305: Exception during cleanup after start failed
org.apache.catalina.LifecycleException: PWC2769: Manager has not yet been started
    at org.apache.catalina.session.StandardManager.stop(StandardManager.java:873)
    at org.apache.catalina.core.StandardContext.stop(StandardContext.java:5571)
    at com.sun.enterprise.web.WebModule.stop(WebModule.java:527)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5384)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:498) …
Run Code Online (Sandbox Code Playgroud)

jsf glassfish myfaces jsf-2

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

t:inputFileUpload 未上传文件

我正在使用 myfaces ExtensionFilter 上传文件,但该文件未设置到我的 bean 中以供进一步处理。

这是代码:

<h:form id="uploadFileForm" enctype="multipart/form-data">
    <tom:inputFileUpload id="file" 
        value="#{paramUpload.uploadFile}">
        <f:valueChangeListener type="com.bosch.de.plcd.plugin.ParamFileUpload" />
    </tom:inputFileUpload>
    <a4j:commandButton value="#{tpMsgs.upload}"
        styleClass="button" action="#{paramUpload.uploadParamFile}"
        onclick="javascript:updateParentScreen();">
    </a4j:commandButton>
</h:form>
Run Code Online (Sandbox Code Playgroud)

web.xml配置如下

<filter>
    <filter-name>Extensions Filter</filter-name>
    <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>Extensions Filter</filter-name>
    <servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
Run Code Online (Sandbox Code Playgroud)

由于UploadFile没有设置为 bean,我也尝试使用 ValueChangeListener,尽管如此,它不是 bean :)

豆码

public class ParamFileUpload implements ValueChangeListener {

    private UploadedFile uploadFile;

    public void uploadParamFile() {
        if(uploadFile != null) {
            LOGGER.info("File type: " + uploadFile.getContentType());
            LOGGER.info("File name: " + uploadFile.getName());
            LOGGER.info("File size: " + uploadFile.getSize() + " bytes");
        } …
Run Code Online (Sandbox Code Playgroud)

jsf file-upload richfaces myfaces tomahawk

3
推荐指数
1
解决办法
7074
查看次数

堆空间中的缓冲响应会导致大文件出现问题

我有一个Web服务器项目,我在尝试下载大文件时遇到异常.该文件通过流读取并写入ServletOutputStream.

示例代码:

private void readFromInput(BufferedInputStream fis,
    ServletOutputStream sout) throws IOException
    {
    byte[] buf = new byte[4096];
    int c = 0;
    while ((c = fis.read(buf)) != -1)
    {
        sout.write(buf, 0, c);    
    }
    fis.close();
}
Run Code Online (Sandbox Code Playgroud)

当我查看回溯时,我看到一些过滤器被执行.

以下是例外的一些部分:

javax.servlet.ServletException: #{DownloaderBean.actionDownload}: 
java.lang.OutOfMemoryError: Java heap space
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)
org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
org.ajax4jsf.framework.ajax.xmlfilter.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:127)
org.ajax4jsf.framework.ajax.xmlfilter.BaseFilter.doFilter(BaseFilter.java:277)
....
....
....

java.lang.OutOfMemoryError: Java heap space
java.io.ByteArrayOutputStream.write(Unknown Source)
org.apache.myfaces.webapp.filter.ExtensionsResponseWrapper$MyServletOutputStream.write(ExtensionsResponseWrapper.java:135)
Run Code Online (Sandbox Code Playgroud)

当我查看ExtensionFilter代码时:

http://grepcode.com/file/repo1.maven.org/maven2/org.apache.myfaces.tomahawk/tomahawk12/1.1.7/org/apache/myfaces/webapp/filter/ExtensionsFilter.java

此页面上有一部分内容:

"When the ExtensionsFilter is enabled, and the DefaultAddResources implementation is 
used then there is no way to avoid having the response buffered …
Run Code Online (Sandbox Code Playgroud)

jsf jsp servlets myfaces

3
推荐指数
1
解决办法
1186
查看次数

在每次使用时在复合组件中获取`componentType`的相同实例

嗨有这个奇怪的问题,我使用的Composite Component是我写的,我从之前使用的CC(componentTypebean)的支持bean获取值

我不知道如何更好地描述这个,而不仅仅是显示代码.我将尝试简要介绍并删除多余的部分:这是Composite Component定义:

<cc:interface componentType="dynamicFieldGroupList">
   <cc:attribute name="coupletClass" />
   <cc:attribute name="form" default="@form"/>
   <cc:attribute name="list" type="java.util.List" required="true"/>
   <cc:attribute name="fieldNames" type="java.util.List" required="true" />
</cc:interface>

<cc:implementation>
    <h:dataTable value="#{cc.model}" var="currLine">
        <h:column>
            <h:outputText id="inner_control_component" value="Inner Look at currLine:#{currLine}"/>
        </h:column>
    </h:dataTable>
</cc:implementation>
Run Code Online (Sandbox Code Playgroud)

CC bean定义:

@FacesComponent(value = "dynamicFieldGroupList")
// To be specified in componentType attribute.
@SuppressWarnings({ "rawtypes", "unchecked" })
// We don't care about the actual model item type anyway.
public class DynamicFieldGroupList extends UIComponentBase implements
        NamingContainer
{

    private transient DataModel …
Run Code Online (Sandbox Code Playgroud)

jsf myfaces composite-component jsf-2

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

在JSF中登录,注销和存储会话属性的最佳方式

我是JSF的新手,我对管理用户登录的最佳实践感到困惑.有许多答案浮出水面,但它们需要JSF和Java EE的知识,而我似乎并不知道.

使用经典JSP项目时,我以非常简单的方式处理登录.当用户成功登录时,会创建一个值为true的会话属性"isLoggedIn".当用户注销时,会话无效.如果"isLoggedIn"属性为false或缺失,则要求您登录的页面将重定向到登录屏幕.

如何在JSF中完成这类工作?我应该在HttpSession或托管会话bean中存储登录状态,用户名和用户角色等内容吗?

我发现很多答案都说你应该使用request.getRemoteUser()来管理登录,但是不做任何进一步的解释.根据我能够收集的内容,如果您使用域凭据登录应用程序,此方法很有用.如果我在数据库中存储用户凭据(用户名+ salted和哈希密码),那么它有用吗?

如果有人能告诉我如何使用以下两页的网站,那将非常有用:

  1. 一个登录页面,可以输入用户名和密码,然后按"登录"按钮.
  2. 包含"登录成功"消息的页面和注销按钮.按下注销按钮后,用户将注销并进入登录页面.

如果用户在未登录时尝试转到第二页,则会将其重定向到第一页.

就像我之前说过的,我是JSF的新手,我根本找不到一个如何处理这类事情的好教程.因此,任何您认为有用的链接将不胜感激.

如果重要,我正在使用MyFaces实现和PrimeFaces组件库.

session jsf login myfaces

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

将空数转换为null

是否有可能告诉我的JSF实现将空数转换为null.到目前为止,我总是得到0(相应的复杂类型).
对于空字符串有javax.faces.INTERPRET_EMPTY_STRING_SUBMITTED_VALUES_AS_NULL,但我无法找到任何数字.顺便说一下:不,我不能使用vm-argument:-Dorg.apache.el.parser.COERCE_TO_ZERO = false

自定义数字转换器是我唯一的可能吗?

jsf tomcat el myfaces

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

JSF 2.0动态控制哪些值基于CSS返回

我有这个表单,有170个单独的文本框,在会话范围的bean中有值.需要仅在组件具有特定CSS类时提交值.

我最初接近这个的方法是在UPDATE_MODEL_VALUES创建一个PhaseListener并在那里测试CSS类.如果该类是受影响的类,我将组件的值设置为null.然后在前端,我使用通用JavaScript方法切换焦点类.这意味着每个组件的更改我只需要添加:

... styleClass="examfieldgrey" onfocus="whiteField(this);"
Run Code Online (Sandbox Code Playgroud)

鉴于我需要改变多少组件,这是一种很好的方式.

这工作正常,直到我重新考虑我的电子表格以使用多个h表格标签.现在CSSclass正在切换前端,但是没有保存此更改.阶段监听器正在获得旧班级.

我认为这显然与我在jQuery/javascript中切换类有关.我想知道的是:

  1. 有没有更好的方式来做到这一点?一个最好意味着我不必修改170多个组件?
  2. 如果我必须继续使用Javascript切换类,有没有办法可以从javascript发回更改?

很抱歉,如果这是一个显而易见的问题,我对JSF生命周期仍然有点青睐.

我正在使用JSF 2.0 MyFaces

这里的参考是我的表单上需要过滤的组件的示例:

<h:inputTextarea 
  id="inputVal" 
  styleClass="midTextArea examfieldgrey"
  onfocus="whiteField(this);"
  value="#{bean.form.val}"/>
Run Code Online (Sandbox Code Playgroud)

其中"examfieldgrey"是我在确定是否要阻止组件时测试的类.

和whiteField方法:

function whiteField(field){
    if(! jQuery(field).hasClass("examfieldgrey")){
        return;
    }
    jQuery(field).removeClass("examfieldgrey");
    jQuery(field).addClass("examfieldwhite");
}
Run Code Online (Sandbox Code Playgroud)

我的阶段监听器在阶段方法之前我过滤:

// TODO: make whatever mode allows ghosting to be configurable outside of
// the system (perhaps in the config file)
/**
 * Before the model is updated, test each component's CSS on the form.  If the 
 * CSS style is 'examfieldgrey' set the value to null so …
Run Code Online (Sandbox Code Playgroud)

css myfaces filter jsf-2 phaselistener

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

javax.faces.context.FacesContext.getAttributes(FacesContext.java:64)中的java.lang.StackOverflowError

当我点击应用程序URL(http://localhost:9082/pages/upload.jsf)时,我在浏览器上只显示"错误:500 StackOverflowError".从我在这个问题上的基础工作,我可以看出这可能是由于一些递归问题.

部署我的应用程序的服务器是WAS 8

有人请帮助我如何处理这个问题.我知道这很模糊,如果我需要分享任何内容,请告诉我.(例如,控制台和东西上的错误消息)

at javax.faces.context.FacesContext.getAttributes(FacesContext.java:64)
at javax.faces.context.FacesContext.getAttributes(FacesContext.java:64)
    [the same line repeated many times]
at javax.faces.context.FacesContext.getAttributes(FacesContext.java:64)
at javax.faces.context.FacesContext.getAttributes(FacesContext.java:64)
at org.apache.myfaces.application.ResourceHandlerImpl.isResourceRequest(ResourceHandlerImpl.java:416)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:180)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1188)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:763)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:454)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.java:125)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:92)
at com.lmig.putt.customComponents.UploadFilter.doFilter(UploadFilter.java:61)
at com.ibm.ws.webcontainer.filter.FilterInstanceWrapper.doFilter(FilterInstanceWrapper.java:192)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.doFilter(WebAppFilterChain.java:89)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.doFilter(WebAppFilterManager.java:919)
at com.ibm.ws.webcontainer.filter.WebAppFilterManager.invokeFilters(WebAppFilterManager.java:1016)
at com.ibm.ws.webcontainer.webapp.WebApp.handleRequest(WebApp.java:3703)
at com.ibm.ws.webcontainer.webapp.WebGroup.handleRequest(WebGroup.java:304)
at com.ibm.ws.webcontainer.WebContainer.handleRequest(WebContainer.java:962)
at com.ibm.ws.webcontainer.WSWebContainer.handleRequest(WSWebContainer.java:1662)
at com.ibm.ws.webcontainer.channel.WCChannelLink.ready(WCChannelLink.java:195)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleDiscrimination(HttpInboundLink.java:452)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.handleNewRequest(HttpInboundLink.java:511)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.processRequest(HttpInboundLink.java:305)
at com.ibm.ws.http.channel.inbound.impl.HttpInboundLink.ready(HttpInboundLink.java:276)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.sendToDiscriminators(NewConnectionInitialReadCallback.java:214)
at com.ibm.ws.tcp.channel.impl.NewConnectionInitialReadCallback.complete(NewConnectionInitialReadCallback.java:113)
at com.ibm.ws.tcp.channel.impl.AioReadCompletionListener.futureCompleted(AioReadCompletionListener.java:165)
at com.ibm.io.async.AbstractAsyncFuture.invokeCallback(AbstractAsyncFuture.java:217)
at com.ibm.io.async.AsyncChannelFuture$1.run(AsyncChannelFuture.java:205)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:1659)
Run Code Online (Sandbox Code Playgroud)

`这是我点击URL后在控制台上找到的错误消息.请帮助我,因为我发现它是全新的并且难以破解

在web.xml

<?xml …
Run Code Online (Sandbox Code Playgroud)

websphere jsf myfaces

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

java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault 不能转换为 org.apache.xml.dtm.DTMManager

我想在我的应用程序中使用 Primefaces 和 Myfaces。然而,有一个例外。

00:31:01,292 SEVERE [org.primefaces.config.ConfigContainer] (http--0.0.0.0-8081-1) Could not load or parse web.xml: java.lang.ClassCastException: org.apache.xml.dtm.ref.DTMManagerDefault cannot be cast to org.apache.xml.dtm.DTMManager
    at org.apache.xml.dtm.DTMManager.newInstance(DTMManager.java:137) [xalan.jar:4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)]
    at org.apache.xpath.XPathContext.<init>(XPathContext.java:102) [xalan.jar:4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)]
    at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:115)
    at org.apache.xpath.jaxp.XPathExpressionImpl.eval(XPathExpressionImpl.java:99)
    at org.apache.xpath.jaxp.XPathExpressionImpl.evaluate(XPathExpressionImpl.java:184)
    at org.primefaces.config.ConfigContainer.initErrorPages(ConfigContainer.java:314) [primefaces-5.2.jar:5.2]
    at org.primefaces.config.ConfigContainer.initConfigFromWebXml(ConfigContainer.java:291) [primefaces-5.2.jar:5.2]
    at org.primefaces.config.ConfigContainer.<init>(ConfigContainer.java:88) [primefaces-5.2.jar:5.2]
    at org.primefaces.context.DefaultApplicationContext.<init>(DefaultApplicationContext.java:35) [primefaces-5.2.jar:5.2]
    at org.primefaces.context.DefaultRequestContext.getApplicationContext(DefaultRequestContext.java:227) [primefaces-5.2.jar:5.2]
    at org.primefaces.metadata.transformer.MetadataTransformerExecutor.processEvent(MetadataTransformerExecutor.java:50) [primefaces-5.2.jar:5.2]
    at javax.faces.event.SystemEvent.processListener(SystemEvent.java:43) [myfaces-api-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl._traverseListenerList(ApplicationImpl.java:2471) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.access$000(ApplicationImpl.java:120) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl$SystemListenerEntry.publish(ApplicationImpl.java:2662) [myfaces-bundle-2.1.12.jar:2.1.12]
    at org.apache.myfaces.application.ApplicationImpl.publishEvent(ApplicationImpl.java:601) [myfaces-bundle-2.1.12.jar:2.1.12]
    at javax.faces.component.UIComponentBase._publishPostAddToViewEvent(UIComponentBase.java:235) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component.UIComponentBase.setParent(UIComponentBase.java:215) [myfaces-api-2.1.12.jar:2.1.12]
    at javax.faces.component._ComponentFacetMap.setNewParent(_ComponentFacetMap.java:178) …
Run Code Online (Sandbox Code Playgroud)

jsf web.xml myfaces primefaces

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