从DynamoDB填充数据表

时间:2012-05-13 10:33:09

标签: jsf iterator amazon-dynamodb

我试图用我从DynamoDB表(亚马逊NoSQL数据库)检索的数据填充JSF数据表。目前一切正常,直到scanResults上的迭代。调试器显示我的scanResult有一个所有帐户的列表,但当我尝试迭代这些结果以构建我的列表似乎没有任何东西似乎被添加到allUserSummary列表,我最终得到一个nullpointer异常。

基本用户POJO:

public class User {

private String uuid;

   public User(String uuid) {
       this.uuid = uuid;
   }
}

托管bean:

private List<User> allUserSummary;
private List<String> uuid;
private User selectedUser;

public List<User> getAllUserSummary() throws Exception {
    populateData();
    return allUserSummary;
}

private void populateData() throws Exception {

    // Create a new AmazonDynamoDBClient and mapper
    AmazonDynamoDBClient client = dynamoClient.getDynamoClient();
    DynamoDBMapper mapper = new DynamoDBMapper(client);


    try {
        // Create a new scan expression and filter to find the required data from the db
        DynamoDBScanExpression scanExpression = new DynamoDBScanExpression();
        Map<String, Condition> scanFilter = new HashMap<String, Condition>();
        Condition scanCondition = new Condition().withComparisonOperator(ComparisonOperator.NOT_NULL);
        scanFilter.put("uuid", scanCondition);
        scanExpression.setScanFilter(scanFilter);

        // Run the scan
        List scanResults = mapper.scan(UserAccounts.class, scanExpression);

        // Iterate over the scanned results and add the required data to a new User
        for (Iterator it = scanResults.iterator(); it.hasNext();) {
            allUserSummary.add(new User(scanResults.get(1).toString()));
        }

    } catch (Exception e) {
        // TODO
    }

}

数据表(我使用的是primefaces,但问题与标准的JSF DT相同):

            <h:form>



                <pou:dataTable id="users" 
                               var="user" 
                               value="#{accountManager.allUserSummary}" 
                               paginator="true" 
                               rows="10"
                               selection="#{accountManager.selectedUser}">  

                    <f:facet name="header">  
                        UUID  
                    </f:facet>  

                    <pou:column selectionMode="multiple" />  

                    <pou:column headerText="Uuid">  
                        #{user.uuid}  
                    </pou:column>  

                    <f:facet name="footer">  
                        <pou:commandButton id="multiViewButton" 
                                           value="View" 
                                           icon="ui-icon-search"
                                           update="" 
                                           oncomplete=""/>  
                    </f:facet>  
                </pou:dataTable>  

            </h:form>

STACK TRACE:

java.lang.IllegalArgumentException: ""
    at javax.faces.component.UIComponentBase.findComponent(UIComponentBase.java:570)
    at org.primefaces.util.ComponentUtils.findClientIds(ComponentUtils.java:244)
    at org.primefaces.renderkit.CoreRenderer.buildAjaxRequest(CoreRenderer.java:222)
    at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeMarkup(CommandButtonRenderer.java:81)
    at org.primefaces.component.commandbutton.CommandButtonRenderer.encodeEnd(CommandButtonRenderer.java:53)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at org.primefaces.component.datatable.DataTableRenderer.encodeFacet(DataTableRenderer.java:839)
    at org.primefaces.component.datatable.DataTableRenderer.encodeTFoot(DataTableRenderer.java:823)
    at org.primefaces.component.datatable.DataTableRenderer.encodeRegularTable(DataTableRenderer.java:247)
    at org.primefaces.component.datatable.DataTableRenderer.encodeMarkup(DataTableRenderer.java:224)
    at org.primefaces.component.datatable.DataTableRenderer.encodeEnd(DataTableRenderer.java:108)
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1764)
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1757)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1542)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:61)
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    at org.apache.shiro.web.servlet.AdviceFilter.executeChain(AdviceFilter.java:108)
    at org.apache.shiro.web.servlet.AdviceFilter.doFilterInternal(AdviceFilter.java:137)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.shiro.web.servlet.ProxiedFilterChain.doFilter(ProxiedFilterChain.java:66)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.executeChain(AbstractShiroFilter.java:449)
    at org.apache.shiro.web.servlet.AbstractShiroFilter$1.call(AbstractShiroFilter.java:365)
    at org.apache.shiro.subject.support.SubjectCallable.doCall(SubjectCallable.java:90)
    at org.apache.shiro.subject.support.SubjectCallable.call(SubjectCallable.java:83)
    at org.apache.shiro.subject.support.DelegatingSubject.execute(DelegatingSubject.java:380)
    at org.apache.shiro.web.servlet.AbstractShiroFilter.doFilterInternal(AbstractShiroFilter.java:362)
    at org.apache.shiro.web.servlet.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:125)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:217)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:279)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:849)
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:746)
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1045)
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:228)
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
    at java.lang.Thread.run(Thread.java:680)

1 个答案:

答案 0 :(得分:2)

你去......

将值设置为update=""oncomplete=""或将其从按钮中删除...

                    <pou:commandButton id="multiViewButton" 
                                       value="View" 
                                       icon="ui-icon-search"
                                       update="" 
                                       oncomplete=""/>  

修改

尝试以下更改:

private List<User> allUserSummary = new ArrayList<User>();

。 。

@PostConstruct
public void populateData() throws Exception {

。 。 。

public List<User> getAllUserSummary() throws Exception {
    return allUserSummary;
}