2014-05-08 126 views
1

原來,faces-config.xml重寫了我的Controller類中的inline註釋ViewScoped w/RequestScoped。修正了它,似乎解決了這個問題。未調用Bean方法


這個問題沒有答案在這裏commandButton/commandLink/ajax action/listener method not invoked or input value not updated,如果你想這樣做,請使用primefaces fluidGrid擴展提供一個工作修復/例子。

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

我似乎無法調用profileController.testControl(),如果我把命令按鈕的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("---------------------------------------"); 
    } 
} 
+0

可能重複[h:commandLink/h:commandButton未被調用](http://stackoverflow.com/questions/2118656/hcommandlink-hcommandbutton-is-not-being-invoked) –

+0

@LuiggiMendoza其中之一列出的問題會是? – Fabii

+0

從你的代碼,我不能確定。 –

回答

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; 
    } 
} 

試試上面,看看是否適合你。如果它有效,那麼嘗試在你的實現中使用。

+0

我無法讓它在我的項目中工作,我假設可能是由於組件內部組件的一些問題。我創建了一個準系統項目,並且調用bean方法,因爲它應該是。 – Fabii

0

我有時有問題的渲染和按鈕不被調用。確保您的rendered="#{!showvar.isSeries()}" 工作正確或刪除它,然後再試一次。

+0

我試過去除了渲染=「#{!showvar.isSeries()}」,但仍然是同樣的問題。 – Fabii

0

ü必須更新您的形式,我認爲在你的頁面的按鈕更新=新增 「:Form1的:fluidGrid」如果dosent工作作出真實的AJAX它有助於解決這樣一個問題,我希望這將有助於你