相关疑难解决方法(0)

非JSF组件的条件呈现(普通的HTML和模板文本)

我试图有条件地渲染一个<tr>因此我不能使用<h:panelGroup>,因为它将渲染<span> or <div>

我目前的(工作)方法如下:

<h:outputFormat rendered="#{negotiator.maySend}">
    <tr> my tr stuff </tr>
</h:outputFormat>
Run Code Online (Sandbox Code Playgroud)

这是有效的,但我不确定这是否是滥用的方式<h:outputFormat>- 在我使用之前,<h:outputLabel>但这是<label>在IE 中呈现的.

我也已经阅读了这个问题的答案,但如上所述,它们不会对我有用,因为<tr>:如何不在JSF中渲染整个块?

html jsf conditional-rendering

11
推荐指数
1
解决办法
9671
查看次数

即使ManagedBean已经被实例化(例如,在AJAX调用上),也会调用@PostConstruct方法

我有一个@ViewScope ManagedBean和一个@PostConstruct初始化方法.创建新实例时会调用此方法,但也会在每次调用ajax时调用此方法.为什么会这样?

在AJAX调用中,调用并执行init-Method,但不会看到任何更改.例如,如果我在init-Method中更改属性,则仅在实例化时可见,而不是在AJAX调用中可见.对于AJAX调用,值更改在@ViewScoped Bean中不是持久的.

任何人都可以告诉为什么会这样吗?我怎么能改变这个?

ajax jsf postconstruct jsf-2 view-scope

10
推荐指数
1
解决办法
9848
查看次数

使用JSF 2.2时,在每个回发请求上重新创建@ViewScoped bean

我有一个类似于这篇文章的问题和来自@BalusC的3个解决方案的答案,但是:

  • 我没有使用上面提到的EL表达式
  • 我不想再使用第二种解决方案(这对我来说足够复杂)
  • 和部分状态保存设置为false.

我的代码如下:

index.xhtml:

<?xml version="1.0" encoding="windows-1256" ?>
<!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"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.org/ui"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Insert title here</title>
    </h:head>
    <h:body>
        <h:form>
            <p:panelMenu id="westMenu">
                <p:submenu id="sub1" label="System Monitor">
                    <p:menuitem id="menu1" value="live monitoring" 
                            action="#{menusBean.activateMenu('sub1_menu1')}" 
                            update=":centerPane,westMenu" 
                            disabled="#{menusBean.active['sub1_menu1']}" />
                    <p:menuitem id="menu2" value="reports" 
                            action="#{menusBean.activateMenu('sub1_menu2')}"
                            update=":centerPane,westMenu" 
                            disabled="#{menusBean.active['sub1_menu2']}" />
                </p:submenu>
                <p:submenu id="sub2" label="Charging System Nodes" />
                <p:submenu id="sub3" label="Additional Nodes" />
            </p:panelMenu>
        </h:form>
        <h:panelGroup id="centerPane">
            ...
        </h:panelGroup>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

MenusBean.java:

package menus;

import …
Run Code Online (Sandbox Code Playgroud)

jsf postback primefaces view-scope jsf-2.2

8
推荐指数
1
解决办法
9891
查看次数

JSF 2.0:为什么我的ViewScope Bean重新创建,即使它仍然在同一个View上

在我的.xhtml页面中,我有以下表格:

<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
            template="./../template/CustomerTemplate.xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:define name="formContent">
        <h:form> 
            <p:dataGrid var="item" value="#{mrBean.items}" columns="3">
                <p:column>
                    <p:panel header="#{item.name}">
                        <h:panelGrid columns="1" style="width:100%">
                            ...
                            <h:commandButton value="Add To Cart" actionListener="#{cartBean.addItem(item.id)}" />
                            ...
                        </h:panelGrid>
                    </p:panel>
                </p:column>
            </p:dataGrid> 
        </h:form> 
    </ui:define>

</ui:composition>
Run Code Online (Sandbox Code Playgroud)

CustomerTemplate.xhtml是:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:p="http://primefaces.prime.com.tr/ui">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        ... // import css, js files
    </h:head>

    <h:body>
        ... // Other things on the page
        <div class="grid_9 content">
            <ui:insert name="contentTitle"></ui:insert>
            <ui:insert name="formContent"></ui:insert>
        </div>
        ...
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

这是我的ManagedBean:

@ManagedBean
@ViewScoped
public class MrBean { …
Run Code Online (Sandbox Code Playgroud)

java scope exception jsf-2

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

每次请求都会调用@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
查看次数

JSF Backing Bean构造函数多次调用

我正在尝试使用JSF 2.0(过去几个月使用ICEfaces 1.8之后),我试图找出为什么在JSF 2.0中我的支持bean构造函数被多次调用.

bean应该在创建时实例化一次,但每当我单击commandButton时,就会显示"Bean Initialized"文本,指示一个新的Bean对象被实例化.

facelet页面:

    <?xml version='1.0' encoding='UTF-8' ?>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html">

    <h:body>
        <div id="content">
            <h:form id="form">
                <h:commandButton value="Toggle" action="#{bean.toggleShowMe}"/>
            </h:form>


            <h:panelGrid rendered="#{bean.showMe}">
                <h:outputText value="Show me!"/>
            </h:panelGrid>
        </div>
    </h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

支持bean:

@ManagedBean
@RequestScoped
public class Bean {
    private boolean showMe = false;

    public boolean isShowMe() {
        return showMe;
    }

    public void setShowMe(boolean showMe) {
        this.showMe = showMe;
    }

    public void toggleShowMe(){
        System.out.println(showMe);
        if(showMe==true){
            showMe=false;
        }else{
            showMe=true;
        }
    }
    /** Creates a new instance of Bean */
    public Bean() …
Run Code Online (Sandbox Code Playgroud)

jsf icefaces jsf-2

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

PrimeFaces 对话框延迟加载 (dynamic="true") 不起作用?

我最近把我所有的豆子从RequestScoped改为ViewScoped。突然间,对话框的延迟加载不起作用了。我正在使用PrimeFacesJSF 库。

<html>
<h:body>
<f:view>    
    <h:form>
        <p:commandButton id="addId" value="Add" title="Add" type="button" onclick="dlgMultiFileSelect.show();"/>
        ...
    </h:form>    
    <p:dialog header="Dialog" widgetVar="dlgMultiFileSelect" modal="true" resizable="true" dynamic="true"> 
        <ui:include src="/dialogs/media_browser.xhtml"/>
    </p:dialog>
</f:view>   
</h:body>
</html>
Run Code Online (Sandbox Code Playgroud)

似乎dynamic="true"不起作用,因为支持 beanmedia_browser.xhtml会立即初始化,而不是在单击按钮时初始化。

难道我做错了什么?

使用 PrimeFaces 3.5.0。

jsf jstl lazy-loading primefaces jsf-2

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

@ViewScoped在每次回发时创建新实例

我有以下托管bean.但每次我回到同一个bean的帖子,即在调用updateFileList时.我得到了一个新的FileDAO实例.

我怎么能阻止这个?在托管bean中使用DAO是否安全,如果没有,我可以做出哪些更改来改善它.

@ManagedBean(name = "file")
@ViewScoped
public class FileController implements Serializable {

    private static final long serialVersionUID = 1L;

    private List<LoadFileLog> fileList = null;
    private Date selectedDate;
    FileDAO fileDAO;

    public FileController() {

        System.out.println(" In file Controller constructor");
        ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
        ApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
        fileDAO = (FileDAO) context.getBean("FileDAO");


    }


    public FileDAO getFileDAO() {
        return fileDAO;
    }





    public void setFileDAO(FileDAO fileDAO) {
        this.fileDAO = fileDAO;
    }





    public List<LoadFileLog> getFileList() {

        return fileList;

    }

    public Date getSelectedDate() {
        return selectedDate; …

jsf postback jsf-2 view-scope

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

JSF查看多次重建的Scoped Bean

我以为@ViewScoped当用户在同一页面上时,我认为应该阻止bean被重建...那么为什么我的@ViewScopedJSf控制器bean甚至在操作处理程序导致浏览器离开该视图之前被多次创建?

任何人都能指出我在正确的方向吗?

这是我的代码:

视图(domain/edit.xhtml)

<h:form prependId="false">
    <h:inputText id="descriptionField" value="#{domainEdit.domain.description}" />
    <h:commandButton id="saveButton" value="save" action="#{domainEdit.save}" />
</h:form>
Run Code Online (Sandbox Code Playgroud)

ViewScoped控制器(DomainEdit.java)

@Named("domainEdit")
@ViewScoped
public class DomainEdit implements Serializable {

    private static final long serialVersionUID = 1L;


    protected DomainEdit() {
    }

    @PostConstruct
    protected void init() {
        System.out.println("post construct called.");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("pre destroy called.");
    }

    public DomainEntity getDomain() {
        System.out.println("displaying domain...");

        // some code to return the domain
        return domain;
    }

    public String save() {
        System.out.println("saving...");

        // …
Run Code Online (Sandbox Code Playgroud)

jsf ejb java-ee view-scope

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