简体   繁体   English

Render属性会再次创建组件还是仅更新模型?

[英]Render attribute will create a component again or update the model only?

I am trying below code 我正在尝试下面的代码

public String collapseTreeById(ActionEvent event) throws IOException {
     String treeId = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("treeId");
     UITree tree = (UITree)event.getComponent().findComponent(treeId);
     tree.getParent().getChildren().clear();

     return null;
 }

Here you can check i already remove all the children of the component and this method called like this 在这里您可以检查我是否已经删除了该组件的所有子组件,并且此方法的调用方式如下:

<a4j:commandLink actionListener="#{inventoriesBean.collapseTreeById}"
                             value="collapse" render="treeServType">
 <f:param value="treeServType" name="treeId" />
 </a4j:commandLink>

and also added render but still i am seeing tree is in same state(No change from previous state) and not created again . 并且还添加了render但我仍然看到tree处于相同状态(与以前的状态没有变化)并且不再创建。 If render not creating a component again and updating model value then even tree state should be change? 如果渲染器没有再次创建组件并更新模型值,那么甚至树状状态都应该更改? Its also not happening. 它也没有发生。

Why? 为什么?

Render generates pieces of HTML and sends them to the client, since you've removed the tree it doesn't send back anything. 渲染生成HTML片段并将其发送给客户端,因为您删除了树,因此它不发送任何东西。 If you want it to work you have to wrap the tree in another component and rerender that component. 如果希望它起作用,则必须将树包装在另一个组件中,然后重新渲染该组件。

On the other hand emptying the list of children doesn't really do anything (and you shouldn't do it), the component tree is recreated with each request. 另一方面,清空子级列表实际上并没有做任何事情(您也不应该这样做),每个请求都将重新创建组件树。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM