开发者

JSF UIRepeat and PostBack

开发者 https://www.devze.com 2023-04-10 14:05 出处:网络
I have a simple page where a I use <ui:repeat> and it gets the value from a backing bean. The initial request will give it an empty list. The postback then will invoke an action that will chang

I have a simple page where a I use <ui:repeat> and it gets the value from a backing bean.

The initial request will give it an empty list. The postback then will invoke an action that will change the model behind the <ui:repeat> but it is not rendered?!

I debugged through it and I saw that the <ui:repeat> evaluates the value at restore view phase but thats it. When it reaches render respon开发者_开发知识库se it does not use the latest value from my bean. Is that the expected behavior?

How can I make that work? Do I have to write my own repeat tag?


I can't really tell what could be the problem without some of your code, but these are the basics:

Backing bean:

public class ObjectService{

private DataModel objectDataModel;
private List<Object> objectList;
private Pagination paginationHelper;
private ObjectDao objectDao = new ObjectDao();
private String queryOption;

public void setQueryOption(String queryOption){
    this.queryOption = queryOption;
}

public String getQueryOption(){
    return this.queryOption;
}

public <E> PaginationHelper getPagination(final List<E> list) {
    pagination = new PaginationHelper(10) {

        @Override
        public int getItemsCount() {
            return list.size();
        }

        @Override
        public DataModel createPageDataModel() {
            return new ListDataModel(list);
        }
    };

    return pagination;
}

public void setPagination(PaginationHelper pagination) {
    this.pagination = pagination;
}

public List<Object> getObjectList(){
    this.objectList = objectDao.readObjectsWhere(queryOption);

    return this.objectList;
}

public void setObjectList(List<Object> objectList){
    this.objectList = objectList;
}

public DataModel getObjectDataModel(){
     if (objectDataModel == null) {
        objectDataModel = getPagination(getObjectList()).createPageDataModel();
    }

    return objectDataModel;
}

public void setObjectDataModel(DataModel objectDataModel){
    this.objectDataModel = objectDataModel
}

public String changeModel(){
    objectDataModel = null;     
    return null;
}

}

XHTML page:

    ...
<h:form>


    <fieldset>                   
        <label>
        <span>Option:</span>
        <h:inputText value="#{objectService.queryOption}" />
        </label>

        <h:commandButton action="#{objectService.changeModel}" value="request data" />
    </fieldset>

    <ui:repeat value="#{objectService.objectDataModel}" var="objectVar">

        <h:outputLabel value="#{objectVar.property1}" />
        <h:outputLabel value="#{objectVar.property2}" />
        <h:outputLabel value="#{objectVar.property3}" />

    </ui:repeat>

</h:form>
...
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号