[PrimeFaces] Backing component ne s'affiche pas
Bonjour, j'essaye de créer dynamiquement des tab sur une tabView, je n'ai aucunes erreurs mon composant est bien créer par contre la vue ne se met à jour qu'après un rechargement de la page.
Voici mon code:
Génération du panel dans privateChatBean
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public Panel getPanel() {
logger.debug("panel privateChatBean " + this );
Application application = FacesContext.getCurrentInstance()
.getApplication();
TabView tabView = (TabView) application
.createComponent("org.primefaces.component.TabView");
FacesContext facesContext = FacesContext.getCurrentInstance();
FaceletContext faceletContext = (FaceletContext) FacesContext
.getCurrentInstance().getAttributes()
.get(FaceletContext.FACELET_CONTEXT_KEY);
Set cles = session.getCalledUserList().keySet();
Iterator it = cles.iterator();
logger.debug("session size " + session.getCalledUserList().size() );
while (it.hasNext()){
String name = (String) it.next();
User userForComponent = (User) session.getCalledUserList().get(name);
logger.debug("session parcours " + name );
CustomTab tab = new CustomTab();
tab.setTitle(userForComponent.getName());
tab.setId(name);
tabView.getChildren().add(tab);
logger.debug("session return " + tabView.getChildren().size() );
panel.getChildren().add(tabView);
return panel;
} |
Le XHTML qui appelle cette méthode:
Code:
1 2 3 4 5
|
<p:commandButton value="Generate" reRender="tabs" ></p:commandButton>
<p:panel binding="#{privateChatBean.panel}" id="tabs" rendered="true" style="height:500px">
</p:panel> |
Mon customTab:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
package org.zambaux.view.component;
import java.io.IOException;
import javax.faces.component.FacesComponent;
import javax.faces.context.FacesContext;
import javax.faces.view.facelets.FaceletContext;
import org.primefaces.component.tabview.Tab;
@FacesComponent(value="customTab")
public class CustomTab extends Tab {
public static final String COMPONENT_TYPE = "com.example.Include";
public static final String COMPONENT_FAMILY = "com.example.Output";
private enum PropertyKeys {
src;
}
@Override
public String getFamily() {
return COMPONENT_FAMILY;
}
@Override
public boolean getRendersChildren() {
return true;
}
@Override
public void encodeChildren(FacesContext context) throws IOException {
getChildren().clear();
FaceletContext faceletContext = ((FaceletContext) context.getAttributes().get(FaceletContext.FACELET_CONTEXT_KEY));
faceletContext.includeFacelet(this, "content/privateChatComponent.xhtml");
super.encodeChildren(context);
}
public String getSrc() {
return (String) getStateHelper().eval(PropertyKeys.src);
}
public void setSrc(String src) {
getStateHelper().put(PropertyKeys.src, src);
}
} |
et le contenu privateCHatComponent.xhtml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:p="http://primefaces.org/ui">
<h:form >
<h:panelGrid columns="1" width="400">
<p:inputTextarea id="allMessages" rows="20" cols="50"
value="#{privateChatComponentBean.allMessages}" ajax="false"
autoResize="false" />
<h:panelGrid columns="2">
<p:inputTextarea id="yourMessage"
value="#{privateChatComponentBean.yourMessage}" rows="5" cols="40"/>
<p:commandButton action="#{privateChatComponentBean.sendMessage()}"
update="allMessages,yourMessage" value="send"/>
</h:panelGrid>
</h:panelGrid>
<p:poll update="allMessages" interval="50"></p:poll>
</h:form>
</html> |
Je pensais que rerender suffisait pour mettre à jour mon panel mais apparemment non.
Merci beaucoup