0

私のjsfページ

<h:form>
    <h:dataTable id="btable" value="#{ballController.items}" var="item">
         <h:column>
             <h:outputText value="#{item.id}"/>
         </h:column>
         <h:column>
             <h:outputText value="#{item.bname}"/>
         </h:column>
    </h:dataTable>

    <h:commandButton action="#{ballCOntroller.items}" value="test">
          <f:ajax execute="@form" render="btable" />
    </h:commandButton> 
</h:form>

私のコントローラーでは、このメソッドは ballController.items によって呼び出されます

public DataModel getItems() {
    if (items == null) {
        items = getPagination().createPageDataModel();
    }
    return items;
}

しかし、ボタンをクリックすると、次のようなエラーが表示されます。

serverError: classjavax.faces.el.MethodNotFoundException /app/ball/index.xhtml @40,101 action="#{ballController.items}": メソッドが見つかりません: ballController@a7150b6.items()

私の目標は、コマンド ボタンをクリックすると、ページ全体を更新せずに dataTable をリロードすることです。

*編集済み

私のBeanコード全体

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

    private ball current;
    private DataModel items = null;
    @EJB
    private ballFacade ejbFacade;
    private PaginationHelper pagination;
    private int selectedItemIndex;

    public ballController() {
    }

    public ball getSelected() {
        if (current == null) {
            current = new ball();
            selectedItemIndex = -1;
        }
        return current;
    }

    private ballFacade getFacade() {
        return ejbFacade;
    }

    public PaginationHelper getPagination() {
        if (pagination == null) {
            pagination = new PaginationHelper(10) {
                @Override
                public int getItemsCount() {
                    return getFacade().count();
                }

                @Override
                public DataModel createPageDataModel() {
                    return new ListDataModel(getFacade().findRange(new int[]{getPageFirstItem(), getPageFirstItem() + getPageSize()}));
                }
            };
        }
        return pagination;
    }

    public String prepareList() {
        recreateModel();
        return "List";
    }

    public String prepareView() {
        current = (ball) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "View";
    }

    public String prepareCreate() {
        current = new ball();
        selectedItemIndex = -1;
        return "index";
    }

    public String create() {
        try {

            getFacade().create(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ballCreated"));
            return prepareCreate();
//            return null;
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String prepareEdit() {
        current = (ball) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        return "Edit";
    }

    public String update() {
        try {
            getFacade().edit(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ballUpdated"));
            return "View";
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
            return null;
        }
    }

    public String destroy() {
        current = (ball) getItems().getRowData();
        selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
        performDestroy();
        recreatePagination();
        recreateModel();
        return "List";
    }

    public String destroyAndView() {
        performDestroy();
        recreateModel();
        updateCurrentItem();
        if (selectedItemIndex >= 0) {
            return "View";
        } else {
            // all items were removed - go back to list
            recreateModel();
            return "List";
        }
    }

    private void performDestroy() {
        try {
            getFacade().remove(current);
            JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ballDeleted"));
        } catch (Exception e) {
            JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
        }
    }

    private void updateCurrentItem() {
        int count = getFacade().count();
        if (selectedItemIndex >= count) {
            // selected index cannot be bigger than number of items:
            selectedItemIndex = count - 1;
            // go to previous page if last page disappeared:
            if (pagination.getPageFirstItem() >= count) {
                pagination.previousPage();
            }
        }
        if (selectedItemIndex >= 0) {
            current = getFacade().findRange(new int[]{selectedItemIndex, selectedItemIndex + 1}).get(0);
        }
    }

    public DataModel getItems() {
        if (items == null) {
            items = getPagination().createPageDataModel();
        }
        return items;

    }

    private void recreateModel() {
        items = null;
    }

    private void recreatePagination() {
        pagination = null;
    }

    public String next() {
        getPagination().nextPage();
        recreateModel();
        return "List";
    }

    public String previous() {
        getPagination().previousPage();
        recreateModel();
        return "List";
    }

    public SelectItem[] getItemsAvailableSelectMany() {
        return JsfUtil.getSelectItems(ejbFacade.findAll(), false);
    }

    public SelectItem[] getItemsAvailableSelectOne() {
        return JsfUtil.getSelectItems(ejbFacade.findAll(), true);
    }

    @FacesConverter(forClass = ball.class)
    public static class ballControllerConverter implements Converter {

        public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
            if (value == null || value.length() == 0) {
                return null;
            }
            ballController controller = (ballController) facesContext.getApplication().getELResolver().
                    getValue(facesContext.getELContext(), null, "ballController");
            return controller.ejbFacade.find(getKey(value));
        }

        java.lang.Integer getKey(String value) {
            java.lang.Integer key;
            key = Integer.valueOf(value);
            return key;
        }

        String getStringKey(java.lang.Integer value) {
            StringBuffer sb = new StringBuffer();
            sb.append(value);
            return sb.toString();
        }

        public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
            if (object == null) {
                return null;
            }
            if (object instanceof ball) {
                ball o = (ball) object;
                return getStringKey(o.getId());
            } else {
                throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + ball.class.getName());
            }
        }
    }
}
4

2 に答える 2

2

テーブルをリロードするには、使用するだけです<f:ajax render="btable" />

<h:commandButton value="test">
      <f:ajax render="btable" />
</h:commandButton> 

ただし、テーブルにデータを追加するなどのアクションを実行するには、ボタンを適切なメソッドにポイントする必要があります

<h:commandButton value="test" action="#{ballController.addItem}"">
      <f:ajax render="btable" />
</h:commandButton> 


public void addItem() {
    if (items == null) {
        items = getPagination().createPageDataModel();
    }
    items.getWrappedData().add(/*something like new MyObject("one","two")*/);
}
于 2013-02-21T08:33:26.160 に答える
1
serverError: classjavax.faces.el.MethodNotFoundException /app/ball/index.xhtml @40,101 action="#{ballController.items}": Method not found: ballController@a7150b6.items()

getItems間違った方法で アクセスしようとしているために発生しています。

Beanコードを次のように更新します。

public DataModel items() {
    if (items == null) {
        items = getPagination().createPageDataModel();
    }
    return items;
}

または、ファセットアクションのEL式を。として変更しますaction="#{ballCOntroller.getItems}"

編集

次のように更新できますList

public class DataTableBean implements Serializable {

    List<String> dataModelList = new ArrayList<DataModel>();

    public List<DataModel> getDataModelList() {
        return dataTableList;
    }

    public void setDataModelList(List<String> dataModelList) {
         this.dataTableList = dataTableList;
    }

    public void addItems(){

        List<DataModel> tempList = getPagination().createPageDataModel(); // Returns a list of type `List<DataModel>`.

        dataModelList.addAll(tempList);

    }
}
于 2013-02-21T08:29:38.020 に答える