1

结果是 faces-config.xml 覆盖了带有 RequestScoped 的 Controller 类中的内联注释 ViewScoped。修复了它,这似乎解决了问题。


这个问题在这里没有答案 commandButton/commandLink/ajax action/listener 方法没有被调用或输入值没有更新,如果你认为是这样,请提供一个使用 primefaces fluidGrid 扩展的工作修复/示例。

我正在使用 primefaces ui exension fluidGrid:http ://fractalsoft.net/primeext-showcase-mojarra/sections/fluidgrid/dynamic.jsf

我似乎无法调用 profileController.testControl() ,如果我将 commandButton 放在 fluidGrid 之外,它工作正常,但不在网格内。有任何想法吗?

我已经通过将我的 bean 更改为 @ViewScoped 进行了测试,没有嵌套表单等。

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:a4j="http://richfaces.org/a4j"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:p="http://primefaces.org/ui"
    xmlns:pe="http://primefaces.org/ui/extensions"
    xmlns:composite="http://java.sun.com/jsf/composite">

<composite:interface>
    <composite:attribute name="resultList" />
</composite:interface>

<composite:implementation>

<h:form id="form1" rendered="true">

    <!-- Grid -->
    <pe:fluidGrid value="#{resultList}" var="showvar" hGutter="20" rowKeyVar="rowKey" fitWidth="true" hasImages="true" rendered="true" >        
        <pe:fluidGridItem rendered="true" >
          <p:panel id="seriesPanel"  rendered="#{showvar.isSeries()}"></p:panel>                    
          <p:panel id="episodePanel" rendered="#{!showvar.isSeries()}" >

           <p:commandButton value="click me" action="#{profileController.testControl()}"/>

           <!-- another button attempt that doesn't work -->
           <p:commandButton process="fluidGrid" value="click me again" ajax="false" actionListener="#{profileController.testControlEvent()}" />

          </p:panel>                             
        </pe:fluidGridItem>         
    </pe:fluidGrid>

</h:form>

</composite:implementation>
</html>

//Tried with  @ViewScoped as well
@Model
public class ProfileController {
    public void testControl(){
        log.info("---------------------------------------");
        log.info("TEST CONTROL CLICKED");
        log.info("---------------------------------------");
    }

    public void testControlEvent(ActionEvent actionEvent){
        log.info("---------------------------------------");
        log.info("TEST CONTROL CLICKED");
        log.info("---------------------------------------");
    }
}
4

3 回答 3

1

我已经尝试过在fluidGrid 中有命令按钮的简单示例,它在这里工作。

XHTML 文件

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:pe="http://primefaces.org/ui/extensions"
    xmlns:p="http://primefaces.org/ui">

<h:head>

</h:head>

<h:body>


    <h:form id="login">
        <pe:fluidGrid value="#{tBean.images}" var="showvar" hGutter="20"
            rowKeyVar="rowKey" fitWidth="true" hasImages="true" rendered="true">
            <pe:fluidGridItem rendered="true">


                <p:commandButton value="click me" action="#{tBean.doAction}" />

            </pe:fluidGridItem>
        </pe:fluidGrid>
    </h:form>

</h:body>
</html>

ManagedBean 代码

package bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.primefaces.extensions.model.fluidgrid.FluidGridItem;

@ManagedBean(name = "tBean")
@ViewScoped
public class TestBean implements Serializable{

    private List<FluidGridItem> images;

    @PostConstruct
    protected void initialize() {
        images = new ArrayList<FluidGridItem>();

        for (int j = 0; j < 3; j++) {
            for (int i = 1; i <= 10; i++) {
                images.add(new FluidGridItem("i" + 1));
            }
        }
    }

    public void doAction() {

        System.out.println("Im doing action");
    }

    public List<FluidGridItem> getImages() {
        return images;
    }
}

试试上面,看看是否适合你。如果它有效,那么尝试在您的实现中使用。

于 2014-05-17T12:06:51.007 回答
0

我有时会遇到渲染和按钮未被调用的问题。确保您的rendered="#{!showvar.isSeries()}" 作品正确或将其删除,然后重试。

于 2014-05-12T11:24:16.503 回答
0

你必须更新你的表单我认为在你的页面中添加按钮 update=":form1:fluidGrid" 如果 dosent 工作使 ajax 成为真的它有助于解决这样的问题我希望它会帮助你

于 2014-05-16T17:07:41.027 回答