我在ViewScope模式下有一个Managed Bean.因此,当我从此Managed Bean调用某个操作时,我的页面不会更新.我看到我的动作被很好地调用并返回null(viewscope工作流程正常).
那么,我做错了什么?
如果我使用Ajax重新渲染页面,它可以正常工作.
编辑:
我的版本是:
JSF 2.1.14与Primefaces 3.4.1
我的代码:
@ManagedBean(name = "test")
@ViewScoped
public class TestMB implements Serializable {
private String status;
public String getStatus() { return this.status; }
public void setStatus(String status) { this.status = status; }
public String changeStatus() {
this.status = "ViewScope Works!";
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
我的页面:
<!DOCTYPE HTML>
<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:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui"
template="/template/ui.xhtml">
<ui:define name="head">
</ui:define>
<ui:define id="teste" name="content">
<h:form id="form">
<h:outputText id="status" value="OK?: #{test.status}" />
<p:commandButton id="myAction" value="Do it!" action="#{test.changeStatus}" …Run Code Online (Sandbox Code Playgroud) <h:form ...
<p:dataTable value="#{myBean.list}" var="data" ...
<p:column ...
<h:commandButton action="#{controller.method(data.id)}" />
</p:column>
</p:dataTable>
</h:form>
Run Code Online (Sandbox Code Playgroud)
@ApplicationScoped
public class Controller {
public String method(final Long dataId) {
/* Do business */
return URL_WITH_REDIRECT;
}
}
Run Code Online (Sandbox Code Playgroud)
(使用此处@ViewScoped描述的CDI注释)
@ApplicationScoped
public class Producer {
@Named @ViewScoped @Producer
public MyBean getMyBean() {
final MyBean bean = new MyBean();
bean.list = new ArrayList<Data>(); // where Data has a Long id field
/* Do business and populate list */
return bean;
} …Run Code Online (Sandbox Code Playgroud) 如果我@ViewScoped在JSF中使用,则会发生以下异常:
java.io.NotSerializableException: com.solv.basics.Basics
java.io.ObjectOutputStream.writeObject0(Unknown Source)
java.io.ObjectOutputStream.writeObject(Unknown Source)
java.util.HashMap.writeObject(Unknown Source)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
java.io.ObjectOutputStream.writeSerialData(Unknown Source)
java.io.ObjectOutputStream.writeOrdinaryObject(Unknown Source)
Run Code Online (Sandbox Code Playgroud)
我可以通过让bean实现来解决它Serializable.但是,我不理解这个推理.为什么仅对视图范围而不是其他范围发生此异常?
我在JSF 2.2.7和Primefaces 5中打开对话框时遇到问题.我有按钮打开一个对话框,每次单击按钮@PostConstruct方法时都会出现问题.为什么?
我只想调用@PostConstruct一次,但我不想将范围更改为Session(使用@SessionScope注释它完美地工作).
这是我的观点:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:c="http://java.sun.com/jstl/core"
xmlns:p="http://primefaces.org/ui">
<h:head>
</h:head>
<h:body>
<h:form id="f1">
<p:dialog widgetVar="trainingDialog2" id="d1">
<h:outputText value="#{userViewBean.errorMessage}" />
</p:dialog>
<br />
<p:dataTable id="dt1" value="#{userViewBean.infoList}" var="item">
<p:column>
<p:commandButton id="btn" update=":f1:d1"
oncomplete="PF('trainingDialog2').show()"
styleClass="ui-icon ui-icon-calendar">
<f:setPropertyActionListener value="#{item.id}"
target="#{userViewBean.errorMessage}" />
</p:commandButton>
</p:column>
</p:dataTable>
</h:form>
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是我的豆子:
package pl.jrola.java.www.vigym.viewcontroller.beans.userview;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.view.ViewScoped;
@ManagedBean(name = "userViewBean")
@ViewScoped
public class UserViewBean implements Serializable {
private static final long serialVersionUID = …Run Code Online (Sandbox Code Playgroud) 首先抱歉我的英语.我在JSF2中有两个页面,一个用于列出乘客,另一个用于创建/更新乘客.我还有两个@ViewScoped bean,一个带有乘客列表,另一个用于在pageB中保留所选乘客.我看到了通过viewParam或@ManagedProperty传递乘客的方法,但我不想写一个转换器.
我想知道是否有办法将对象从pageA传递给pageB而不传递乘客的id并写入转换器或没有传递id然后转到DB来检索乘客.我的工作和工作如下.我通过setPropertyActionListener在flash范围内设置所选对象并导航到pageB,在viewScopedBean的@PostConstruct中我获取flashScope并检索该对象.正如我所说,这有效,但我不知道它是否正确.这是代码页面A:
<p:column width="10" style="text-align: center;">
<p:commandButton icon="ui-icon-pencil" action="editClientes?faces-redirect=true">
<f:setPropertyActionListener target="#{flash.pax}" value="#{row}"/>
</p:commandButton>
</p:column>
Run Code Online (Sandbox Code Playgroud)
pageB bean的@PostConstruct
@PostConstruct
private void initBean(){
this.pax = (Passenger) JSFUtils.getFlashScope().get("pax");
if(this.pax == null){
this.pax = new Passenger();
}
}
Run Code Online (Sandbox Code Playgroud)
这是正确的,还是正确的方法是编写转换器?谢谢.
我有一个JSF,CDI项目的问题.我做了很多研究,我发现在CDI中没有@ViewedScoped注释.我用对话框解决了基于ajax的页面的问题.我想从datatable传递变量到对话框.为此,我不能使用@RequestedScopedbean,因为在请求结束后丢弃值.任何人都可以帮我解决吗?我不能用,@SessionScoped但这是一个不好的做法恕我直言.或者也许只将这一个变量保存到知道的会话中.你们能给我任何提示如何优雅地解决这个问题吗?
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class ServiceBean implements Serializable {
...
Run Code Online (Sandbox Code Playgroud)
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
@ManagedBean
@ViewScoped
public class SomeBean {
@Inject
ServiceBean serviceBean;
@Postconstruct ...
Run Code Online (Sandbox Code Playgroud)
这是错误消息:
com.sun.faces.mgbean.ManagedBeanCreationException: An error occurred performing resource injection on managed bean warDetailBean
Run Code Online (Sandbox Code Playgroud) 在Java EE 6、CDI 1.1.x、Seam 3 等环境中,我们需要查找当前视图的所有 CDI beans ( @ViewScoped)。到目前为止我所尝试的是使用:
@Named
@ViewScoped
public class ViewHelper
{
@Inject
private BeanManager beanManager;
public doSomethingWithTheBeanInstances()
{
Set<Bean<?>> beans = this.getBeanManager().getBeans(
Object.class, new AnnotationLiteral<Any>(){}
);
// do something
...
}
}
Run Code Online (Sandbox Code Playgroud)
但是,这会返回它管理的所有bean。
我只需要找到当前视图范围内的那些,并且 - 这将是理想的 - 只找到那些实现特定接口(在多个层次结构级别上继承)的接口。
有什么方法可以做到呢?
请注意,由于 CDI 没有视图范围,因此我们使用Seam 3来注释所有视图范围的 bean,例如:
@Named
@ViewScoped
public class ResultManagerColumnHandler extends BaseColumnHandler
{
....
}
Run Code Online (Sandbox Code Playgroud)
上面是一个需要寻找的实例(它@ViewScoped是 Seam 3 的 CDI 替代品)。
如何做呢?
我已经使用 JSF 很多年了,在下一个项目中,我们的目标是使 Web 层尽可能无状态。我正在探索的一种可能性是去除@ViewScoped豆子以支持@RequestScoped(@SessionScoped根据需要加上一两个豆子)。这对于带有 AJAX、数据表和条件渲染的复杂页面来说很麻烦。我的问题是:JSF(和 PrimeFaces)与无状态 Web bean 的工作情况如何?这是我应该继续探索的东西,还是@ViewScope现在如此基本以至于不值得付出努力?
我很感激在我写这个问题时它可能会被关闭为“主要基于意见”,但我希望它不是,我对@ViewScope解决的具体问题感兴趣,以及我必须重新解决哪些历史性的解决方法-通过忽略引入@ViewScoped。
我正在尝试使用richfaces fileupload组件上传文件.我的豆子在景观中.
我的代码是从展示中提取的.
<rich:fileUpload id="upload" immediateUpload="true" fileUploadListener="#{analyse.listener}" acceptedTypes="png" ontyperejected="alert('Seulement les fichiers avec l'extension bam et pdf sont acceptés.');" maxFilesQuantity="3">
<a4j:ajax event="uploadcomplete" execute="@none" />
</rich:fileUpload>
Run Code Online (Sandbox Code Playgroud)
bean函数叫:
public void listener(FileUploadEvent event) throws Exception {
System.out.println("Listenner");
UploadedFile item = event.getUploadedFile();
System.out.println(item.getName());
System.out.println(item.getSize());
System.out.println(item.getContentType()) ;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试添加上传文件时,我收到一个漂亮的错误:-(欢迎提供帮助.
6 nov. 2013 19:00:43 org.richfaces.request.MultipartRequest25 parseIfNecessary GRAVE: Exception parsing multipart request: Request prolog cannot be read org.richfaces.exception.FileUploadException: Exception parsing multipart request: Request prolog cannot be read at org.richfaces.request.MultipartRequestParser.parse(MultipartRequestParser.java:156) at org.richfaces.request.MultipartRequest25.parseIfNecessary(MultipartRequest25.java:77) at org.richfaces.request.MultipartRequest25.getParameter(MultipartRequest25.java:114) at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:75) at com.sun.faces.context.RequestParameterMap.get(RequestParameterMap.java:56) at …
在应用程序中,我需要知道viewScope变量是否已初始化.创建viewScope变量时,该值可能为null.所以viewScope.isEmpty("SomeName")并没有告诉我它已被初始化并且答案为null或者尚未初始化.viewScope属性似乎都没有回答"viewScope存在剂量"的问题.
view-scope ×10
jsf ×7
jsf-2 ×4
cdi ×3
file-upload ×1
glassfish ×1
jakarta-ee ×1
java ×1
jsf-2.2 ×1
primefaces ×1
redirect ×1
richfaces ×1
seam3 ×1
tomcat7 ×1
xpages ×1