【问题标题】:Wicket RepeatingView refresh / rerender ? Possibilities? [List items missing]Wicket RepeatingView 刷新/重新渲染?可能性? [缺少列表项]
【发布时间】:2013-05-07 13:06:49
【问题描述】:

我的检票口应用程序有点问题。

问题出在一个名为 OverviewPage 的页面上,这里有一些像 ListPanel 这样的面板,我的 RepeatingView 就在其中。

这个RepeatingView(列表)有一些项目,每个项目都有一个按钮,如果我按下按钮,我将被重定向到另一个页面(RegistrationPage),并且对RepeatingView(列表)进行了一些更改。

如果我现在使用 RepeatingView(列表)导航回 OverviewPage,则列表与之前完全相同。我对列表项进行了更改,但它们不可见。 (我没有按浏览器后退按钮,我点击了我的导航链接)

我知道检票页面的实例会持续到整个会话。我可以告诉 wicket 重新渲染此页面/列表吗?有哪些可能性?任何人都可以吗?

谢谢

编辑:

以下是保存RepeatingView的面板:

/**
 * 
 * Constructor...
 *
 * @param id
 */
public ServiceListPanel(String id) {

    super(id);

    RepeatingView repeating = new RepeatingView("repeating");
    add(repeating);

    int index = 0;

    // add all services to the list

    for (Service service : databaseService.getAllServices()) {

        AbstractItem item = new AbstractItem(repeating.newChildId());

        repeating.add(item);

        item.add(new ActionPanel("actions", new Model<Service>(service)));

        item.add(new Label("name", service.getName()));
        item.add(new Label("description", service.getDescription()));
        item.add(new Label("country", service.getCountry()));

        final int idx = index;
        item.add(AttributeModifier.replace("class", new AbstractReadOnlyModel<String>() {

            private static final long   serialVersionUID    = 1L;

            @Override
            public String getObject() {

                return (idx % 2 == 1) ? "even" : "odd";
            }
        }));

        index++;
    }

}

下一个是发生变化的 ActionPanel:

/**
 * 
 * Constructor...
 *
 * @param id
 * @param model
 */
public ActionPanel(String id, final IModel<Service> model) {

    super(id);

    Link<?> link;

    ContextImage image;

    final ServiceUserDetails user = getSession().getUser();

    final Service service = model.getObject();

    // Check for groups and customize the link to subscribe or unsubscribe

    if (checkUserGroups(user, service)) {

        image = new ContextImage("img", "template/img/unsubscribe.gif");

        link = new Link<Void>("select") {

            /**  */
            private static final long   serialVersionUID    = -2153508505463870485L;

            /**
             * 
             * @see org.apache.wicket.markup.html.link.Link#onClick()
             */
            @Override
            public void onClick() {

                ServiceRequest req = new ServiceRequest(service, user, "DELETE");

                serviceProcessor.handleServiceRequest(req);

                setResponsePage(new RegistrationPage());



            }
        };

    } else { // user is not in group

        image = new ContextImage("img", "template/img/subscribe.gif");

        link = new Link<Void>("select") {

            /**  */
            private static final long   serialVersionUID    = -2153508505463870485L;

            /**
             * 
             * @see org.apache.wicket.markup.html.link.Link#onClick()
             */
            @Override
            public void onClick() {

                ServiceRequest req = new ServiceRequest(service, user, "PUT");

                serviceProcessor.handleServiceRequest(req);

                setResponsePage(new RegistrationPage());


            }
        };

    }

    link.add(image);

    add(link);

}

如您所见,我唯一要更改的是一个图像,一个链接图像。用于订阅或取消订阅服务。列表项保持不变。

我对检票口很陌生,也许这就是我的问题。

希望现在得到更好的解释。

【问题讨论】:

    标签: java wicket


    【解决方案1】:

    为您的actionPanel 提供LoadableDetachableModel 而不是普通的Model。 LDM 总是获取新的新对象,所以这可能会解决您的问题。您可能需要对代码进行相当多的重构。

    上次 a 遇到了与 DataTable 类似的问题,它有所帮助。

    【讨论】:

    【解决方案2】:

    你必须在这里有所不同。页面/组件的结构构建一次,然后要求为每个页面显示(刷新)呈现此组件树。一些转发器会在渲染过程之后保留组件列表,因此无论您对列表做什么(更改其中的元素),它都不会影响渲染输出。

    其他中继器(RefreshingView)在渲染后会丢弃所有组件并为每个渲染进程重新创建组件,因此,如果您更改后备列表,这些更改将反映在渲染输出中。

    此外,在会话之外不会保留任何状态。如果会话关闭,您将无法返回旧页面状态。

    如果没有一些代码,我无法告诉你为什么单击返回链接后会看到旧状态。

    【讨论】:

      【解决方案3】:

      我通常将 ListView 用于几乎所有的中继器,因为它相当简单。要使用 ListView 代替,我将替换您的代码的以下行(注意:我跳过了一些您可以留在原地并打破 databseService.getAllServices() 的行,以便您可以验证它实际上是否已在此时更新):

      RepeatingView repeating = new RepeatingView("repeating");
      for (Service service : databaseService.getAllServices()) {
          AbstractItem item = new AbstractItem(repeating.newChildId());
          repeating.add(item);
          ...
      

      有了这个:

      List<Service> serviceList = databaseService.getAllServices();
      ListView repeating = new ListView("repeating", serviceList) {
          @Override
          protected void populateItem(ListItem item) {
              Service service = (Service) item.getModelObject();
              ...
      

      您应该能够像以前一样使用您的项目和服务变量。此外,此时您可以使用记录器或调试器来验证您的 databaseService.getAllServices 是否返回正确更新的列表。

      【讨论】:

        【解决方案4】:

        现在可以了。

        这是我的错。该列表可以更新,但不是在我的条件下:

        我结合使用了 SpringSecurity 和 Wicket 来实现用户认证。在我的 wicketSession 中通过 ldap 进行身份验证的用户。身份验证包含一个用户对象,其中包含我需要的所有内容(姓名、sn、组、电子邮件等)。

        在我的 RepeatingView 中,更准确地说,在我的 ActionPanel 中,我通过将用户添加到其他组来修改用户的 LDAP 条目。

        现在的问题是:持有用户对象的Authentication,持有OLD未修改的用户对象。 (记住:我改变了用户组。)

        这就是为什么我没有看到我的 ListItems 有任何变化,我的情况就像......

        if (user is in group) {
        
           addUnSubscribeLink(); 
        
        } else {
        
           addSubscribeLink(); 
        
        }
        

        还是谢谢你的帮助。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2021-02-18
          • 1970-01-01
          • 1970-01-01
          • 2020-01-04
          • 2019-06-05
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多