Jakarta ee JSF列表<;类别>;提交时,列表为空

Jakarta ee JSF列表<;类别>;提交时,列表为空,jakarta-ee,jsf-2,richfaces,form-submit,Jakarta Ee,Jsf 2,Richfaces,Form Submit,好的,标题不是很好,但是我找不到更好的 在爪哇 我有一个有一些属性的类型化类和另一个类型的列表 在HTML中,我有一个表,其中每一行都是上面列表的一个元素,我可以成功地获得每一行的属性,但是当我提交表单时,列表是空的/空的 这是我的密码: TESTATA package rip; import java.util.ArrayList; import java.util.Date; import java.util.List; import javax.faces.application.Fa

好的,标题不是很好,但是我找不到更好的

在爪哇

我有一个有一些属性的类型化类和另一个类型的列表

在HTML中,我有一个表,其中每一行都是上面列表的一个元素,我可以成功地获得每一行的属性,但是当我提交表单时,列表是空的/空的

这是我的密码:

TESTATA

package rip;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;

@ManagedBean
public class Testata {
    private String codice = "asd"; // set up for test
    private String descrizione = "descrizione"; // set up for test
    private Date data_inizio = new Date(); // set up for test
    private Date data_fine = new Date(); // set up for teset

    private List<Righe> righe;


    public Testata()
    {  // set up righe for test
            righe = new ArrayList<Righe>();
            righe.add(new Righe("001", "descrizione riga 1", "G", true));
            righe.add(new Righe("002", "descrizione riga 2", "G", false));
            righe.add(new Righe("003", "descrizione riga 3", "P", false));
    }

       // base setter/getter
     public List<Righe> getRighe() {
        return (righe);
    }
    public void setRighe(List<Righe> righe) {
        System.out.println("Set Righe"); // used for debug, in my tests 
                                             // it was never printed
        this.righe = righe;
    }

    public String validateSecond()
    {
        if (righe != null)
        {
            for (int i = 0 ; i < righe.size() ; i++)
            {
                System.out.println(righe.get(i).getCodice());
            }
        }
        else
        {
            System.out.println("Righe is null"); // usually submitting the 
                                        // form I got this message in console
        }
        return null;
    }
righe.xhtml

<h:form id="form_righe">                        
    <h:dataTable var="righe"  styleClass="table_dettaglio"
        rowClasses="table_dettaglio_row"            
            value="#{testata.righe}"            
            columnClasses="column_generic,column_generic,tipo_column,column_generic,column_generic"             
            >               
                <h:column>
                    <f:facet name="header">Codice</f:facet>                                         
                    <rich:select id="codice" enableManualInput="false" value="#{righe.codice}">
                            <f:selectItems value="#{righe.codiceLists}" />
                            <a4j:ajax event="selectitem" render="@form" execute="@this"/>
                </rich:select>                      
                </h:column>         
                <h:column>
                    <f:facet name="header">Descrizione</f:facet>                        
                    <rich:select enableManualInput="true"   id="descrizione"                        
                            defaultLabel="#{righe.descrizione}">
                            <f:selectItems value="#{righe.descrizioneLists}" />
                </rich:select>
                </h:column>     
                <h:column>
                <h:outputStylesheet>
                    .mySelectStyle input{
                    width: 100px;
                }</h:outputStylesheet>
                    <f:facet name="header">Tipo</f:facet>                       
                    <rich:select enableManualInput="false"                                  
                        styleClass="mySelectStyle"                          
                    defaultLabel="#{righe.tipo}">
                    <f:selectItems value="#{righe.tipoLists}" />
                    </rich:select>
                </h:column>         
                <h:column>
                    <f:facet name="header">Valore</f:facet>
                    <h:inputText value="#{rige.valore}" style="width: 150px;"/>                     
                </h:column>

                <h:column>
                    <f:facet name="header">YesNo?</f:facet>
                    <h:selectOneRadio id="flag_medico" value="#{righe.flag_medico}" layout="pageDirection"                                  
                                styleClass="radio_check"/> 

                </h:column>
            </h:dataTable>                          
      <h:commandButton class="button btn btn-warining btn-large" action="#{testata.validateSecond}"
                                       value="Salva" />
       <h:commandButton type="reset" class="button btn btn-warining btn-large" value="Pulisci"/>
  </div>
</h:form>

鳕鱼
描述
.mySelectStyle输入{
宽度:100px;
}
蒂波
瓦洛雷
是吗?
打开页面,所有行都正确显示,每个字段的值都正确。。在
validateSecond
方法中提交后,我得到了一个空的
列表
我错过了什么


谢谢

尝试将
@ViewScoped
@SessionScoped
(取决于您的需要)添加到托管bean中,因为如果没有该注释,默认值将是
@NoneScoped

使用数据表时,通常至少使用
@ViewScoped


看看这个尝试将
@ViewScoped
@SessionScoped
(取决于您的需要)添加到托管bean中,因为如果没有该注释,默认值将是
@NoneScoped

使用数据表时,通常至少使用
@ViewScoped


看看这个

尝试将
@ViewScoped
或`@SessionScoped`(取决于您的需要)添加到托管bean中,因为如果没有该注释,默认值将是
@RequestScoped
谢谢<代码>@SessionScoped工作正常。。我是JSF新手。。。如果您发布了一个答案,我会将其标记为已接受:)欢迎您,例如,看看另一个关于请求范围和数据表的问题会话范围不是正确的选择。使用视图范围。请参阅尝试将
@ViewScoped
或`@SessionScoped`(取决于您的需要)添加到托管bean,因为如果没有该注释,默认值将是
@RequestScoped
谢谢<代码>@SessionScoped工作正常。。我是JSF新手。。。如果您发布了一个答案,我会将其标记为已接受:)欢迎您,例如,看看另一个关于请求范围和数据表的问题会话范围不是正确的选择。使用视图范围。另见
<h:form id="form_righe">                        
    <h:dataTable var="righe"  styleClass="table_dettaglio"
        rowClasses="table_dettaglio_row"            
            value="#{testata.righe}"            
            columnClasses="column_generic,column_generic,tipo_column,column_generic,column_generic"             
            >               
                <h:column>
                    <f:facet name="header">Codice</f:facet>                                         
                    <rich:select id="codice" enableManualInput="false" value="#{righe.codice}">
                            <f:selectItems value="#{righe.codiceLists}" />
                            <a4j:ajax event="selectitem" render="@form" execute="@this"/>
                </rich:select>                      
                </h:column>         
                <h:column>
                    <f:facet name="header">Descrizione</f:facet>                        
                    <rich:select enableManualInput="true"   id="descrizione"                        
                            defaultLabel="#{righe.descrizione}">
                            <f:selectItems value="#{righe.descrizioneLists}" />
                </rich:select>
                </h:column>     
                <h:column>
                <h:outputStylesheet>
                    .mySelectStyle input{
                    width: 100px;
                }</h:outputStylesheet>
                    <f:facet name="header">Tipo</f:facet>                       
                    <rich:select enableManualInput="false"                                  
                        styleClass="mySelectStyle"                          
                    defaultLabel="#{righe.tipo}">
                    <f:selectItems value="#{righe.tipoLists}" />
                    </rich:select>
                </h:column>         
                <h:column>
                    <f:facet name="header">Valore</f:facet>
                    <h:inputText value="#{rige.valore}" style="width: 150px;"/>                     
                </h:column>

                <h:column>
                    <f:facet name="header">YesNo?</f:facet>
                    <h:selectOneRadio id="flag_medico" value="#{righe.flag_medico}" layout="pageDirection"                                  
                                styleClass="radio_check"/> 

                </h:column>
            </h:dataTable>                          
      <h:commandButton class="button btn btn-warining btn-large" action="#{testata.validateSecond}"
                                       value="Salva" />
       <h:commandButton type="reset" class="button btn btn-warining btn-large" value="Pulisci"/>
  </div>
</h:form>