JSF:向动态生成的HTMLInputText添加AjaxBehavior

JSF:向动态生成的HTMLInputText添加AjaxBehavior,ajax,jsf,listener,Ajax,Jsf,Listener,我想动态创建具有AjaxBehavior的UIComponents,并将其添加到HTMLPanelGrid中。将调用ajax方法,但之前没有值绑定,之后也没有呈现。请帮帮我!非常感谢你!下面是一些代码: Ajax功能: public void ajax(AjaxBehaviorEvent event) { HtmlPanelGrid grid = (HtmlPanelGrid) event.getComponent().getParent(); HashMap<String

我想动态创建具有AjaxBehavior的UIComponents,并将其添加到HTMLPanelGrid中。将调用ajax方法,但之前没有值绑定,之后也没有呈现。请帮帮我!非常感谢你!下面是一些代码:

Ajax功能:

public void ajax(AjaxBehaviorEvent event) {
    HtmlPanelGrid grid = (HtmlPanelGrid) event.getComponent().getParent();
    HashMap<String, Object> params;

    try {
        ajaxSet(grid);
        params = collect();
    } catch (Exception e) {
        e.printStackTrace();
        throw new RuntimeException(e);
    }

    SearchComponent search = (SearchComponent) ComponentRegistry.instance()
            .getComponent(IComponentConstants.SEARCH);
    this.score = Integer.toString(search.getSystemsCount(params));
}
根据包含所需字段信息和侦听器的列表创建字段的功能:

public void createSearchFields(UIComponent parent) {
    String beanname = Utilities.lookupManagedBeanName(this);
    GUIHelper helper = GUIHelper.instance();

    for (Searchfield searchfield : shown) {
        helper.label(searchfield.id, searchfield.displayname, parent);
        for (Field f : searchdto.getClass().getDeclaredFields()) {
            GUISearchField gsf = f.getAnnotation(GUISearchField.class);
            if (gsf == null)
                continue;
            if (gsf.id().equals(searchfield.id)) {
                String expression = "#{" + beanname + ".searchdto."
                        + f.getName() + "}";
                helper.inputText(searchfield.id, expression, parent, this);
            }
        }
    }
}

@Override
public void processAjaxBehavior(AjaxBehaviorEvent event)
        throws AbortProcessingException {
    ajax(event);
}

public abstract void ajax(AjaxBehaviorEvent event);
xhtml部分:

<h:form id="searchform" styleClass="ibm-column-form ibm-styled-form">
                <h:panelGrid columns="2" binding="#{systemsearchable.searchfields}">
                </h:panelGrid>
                <h:commandButton value="Search" action="#{systemsearchable.search}">
                    <f:ajax execute="@form" render="results"></f:ajax>
                </h:commandButton>
            </h:form>

如果您需要更多信息,请让我知道:

为什么不使用或通过XHTML创建/声明组件?对于创建/声明组件而言,XHTML比所有那些冗长、混乱和容易出错的Java代码更适合、更清晰、更自我记录。在XHTML上使用ui:repeat编写代码可能是一个更好的主意。是的,这是一个好主意……谢谢!
<h:form id="searchform" styleClass="ibm-column-form ibm-styled-form">
                <h:panelGrid columns="2" binding="#{systemsearchable.searchfields}">
                </h:panelGrid>
                <h:commandButton value="Search" action="#{systemsearchable.search}">
                    <f:ajax execute="@form" render="results"></f:ajax>
                </h:commandButton>
            </h:form>