相关疑难解决方法(0)

如何选择合适的bean范围?

我注意到有不同的bean范围,如:

@RequestScoped
@ViewScoped
@FlowScoped
@SessionScoped
@ApplicationScoped
Run Code Online (Sandbox Code Playgroud)

每个人的目的是什么?如何为我的bean选择合适的范围?

jsf scope jsf-2 managed-bean

372
推荐指数
2
解决办法
20万
查看次数

commandButton/commandLink/ajax动作/侦听器方法未调用或输入值未设置/更新

有时,使用时<h:commandLink>,<h:commandButton>或者<f:ajax>,在action,actionListenerlistener与标签相关的方法根本不被调用.或者,bean属性不会使用提交的UIInput值进行更新.

有什么可能的原因和解决方案?

jsf action commandlink jsf-2 commandbutton

332
推荐指数
5
解决办法
20万
查看次数

什么是非范围bean以及何时使用它?

有人可以解释什么是无范围和目的吗?

假设我有一个豆子

request scope as r1

session scope as s1

application scope a1
Run Code Online (Sandbox Code Playgroud)

并且说我没有将范围bean n1注入到上述每个范围中,然后我发现当实例化其父bean [r1/s1/a1]时,n1将被实例化为每个父bean.

a1中的无范围bean在a1中始终可用,因为a1是appl范围.s1中的无范围bean仅在s1未被销毁之后才可用,并且当再次创建s1时,n1将被实例化并且可用于它.

这是对的吗?

和使用它的目的是什么?只是为了避免创造这样的豆我们自己?

非常感谢

java jsf scope

13
推荐指数
2
解决办法
7073
查看次数

@SessionScoped bean会丢失范围并一直重新创建,字段变为null

我在JSF 2.0项目中使用SessionScoped bean时遇到了一个非常奇怪的问题.使用Netbeans 6.9.1,Glassfish 3服务器和PrimeFaces 3作为JSF组件库.

这是一些代码:

package com.hia.jsf;

import com.hia.netlabel.jpa.Genre;
import com.hia.netlabel.jpa.Label;
import java.io.Serializable;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;

@ManagedBean
@SessionScoped
public class LabelDetailJSF implements Serializable{

@ManagedProperty("#{genreLabelListJSF}")
private GenreLabelListJSF genreLabelListJSF;
private List<Genre> DetailLabelGenreList;
private Label DetailLabel;
/** Creates a new instance of LabelDetailJSF */
public LabelDetailJSF() {
}
@PostConstruct
public void init(){
           System.out.print("Running init LabelDetailJSF");
           if(genreLabelListJSF.getSelectedLabel()!=null)
           {
                System.out.print("genreLabelListJSF was not null");
                this.DetailLabelGenreList=genreLabelListJSF.getSelectedLabel().getGenreList();
                this.DetailLabel= (genreLabelListJSF.getSelectedLabel());
           }
           if(this.DetailLabelGenreList==null){
               System.out.println("Bloody thing became null");

           }
}






/**
 * …
Run Code Online (Sandbox Code Playgroud)

jsf postconstruct primefaces

7
推荐指数
1
解决办法
8910
查看次数

每次请求都会调用@ViewScoped的@PostConstruct

我在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)

jsf postconstruct view-scope

5
推荐指数
1
解决办法
5029
查看次数