关于检索UIComponent ID的JSF NullPointerException?

时间:2014-11-28 11:31:01

标签: java jsf exception jsf-2 jsf-2.2

更新:
在HTML文件末尾添加CommandButton代码。

Html代码就像:

<div class="wrapperlist pad1">
                <h:dataTable id='table' value='#{reservation.flightList}' var='item' class="imagetable">                    
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="From" />
                    </f:facet>
                    <h:outputText value="#{item.fromPlace}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="TO" />
                    </f:facet>
                    <h:outputText value="#{item.toPlace}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Outbound Date" />
                    </f:facet>
                    <h:outputText value="#{item.outbound}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Returned" />
                    </f:facet>
                    <h:outputText value="#{item.returned}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Availiable Seats" />
                    </f:facet>
                    <h:outputText id="seatsNum" value="#{item.seats}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Flight Class" />
                    </f:facet>
                    <h:outputText value="#{item.tripClass}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Airlines" />
                    </f:facet>
                    <h:outputText value="#{item.airline}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Flight Type" />
                    </f:facet>
                    <h:outputText value="#{item.tripType}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Price/Adult" />
                    </f:facet>
                    <h:outputText value="#{item.priceForAdult}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Price/Child" />
                    </f:facet>
                    <h:outputText value="#{item.priceForChild}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Total Adults Payment" />
                    </f:facet>
                    <h:outputText value="#{item.priceForAdult * reservation.adults}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Total Childs Payment" />
                    </f:facet>
                    <h:outputText value="#{item.priceForChild * reservation.children}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Total Payment" />
                    </f:facet>
                    <h:outputText value="#{(item.priceForChild * reservation.children) + (item.priceForAdult * reservation.adults)}" />
                </h:column>
                <h:column>
                    <f:facet name="header" class="imagetable th">
                        <h:outputText value="Select" />
                    </f:facet>
                    <h:selectBooleanCheckbox id="selected" ></h:selectBooleanCheckbox>
                </h:column>
            </h:dataTable>
            </div>
            <h:form>
            <h:commandButton value="Confirm" action="#{flights.processOrder()}" class="button1     left relative"></h:commandButton> 
           </h:form>

这是一个典型的数据表,它的工作正常 我的支持bean代码是:

@Named
@RequestScoped
public class Flights {

public Flights() {
    System.out.println("intialization");
}

public void processOrder()
{        
    UIViewRoot viewRoot = FacesContext.getCurrentInstance().getViewRoot();
    UIComponent component = viewRoot.findComponent("table:1:selected");
    System.out.println("component.getValueExpression(); " + component.getId());

}   
}  

我在尝试打印 component.getId()时遇到异常,我尝试了 SessionScoped ,但仍然有相同的例外。
我的目标是访问数据表中的 复选框 以检索其值。

0 个答案:

没有答案