Bonjour,
J'aimerais faire un composite component composé dans champ autocomplete permettant de sélectionner un bean de mon système et d'un link permettant d'ouvrir un explorateur windows avec un chemin spécifié dans mon bean.
Ca fonctionne pas trop mal sauf que :
- l'attribut disabled de mon autocomplete prend une valeur fournie en paramètre (readOnly) : le problème est que cette valeur peut charger et je ne vois comment faire pour la transmettre à nouveau
- une fois qu'un bean a été sélectionné, la méthode completeMandat() de mon composant n'est plus appelée et il n'est plus possible de sélectionner un autre bean
- il faut mettre à jour des champs de la page utilisatrice quand la valeur du champs modifiée
Voici mon composant :
L'appel de mon composant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
51
52
53
54
55 <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:p="http://primefaces.org/ui" xmlns:composite="http://xmlns.jcp.org/jsf/composite"> <composite:interface componentType="mandatSelectionComponent"> <composite:attribute name="value" required="true" type="ch.application.beans.mandat.Mandat" /> <composite:attribute name="readOnly" default="false" type="java.lang.Boolean" /> </composite:interface> <composite:implementation> <p:panelGrid styleClass="ui-panelgrid-blank tableNoBorder"> <p:row> <p:column> <p:autoComplete id="key" binding="#{cc.key}" disabled="#{cc.attrs.readOnly}" completeMethod="#{cc.completeMandat}" var="mandat" itemLabel="#{mandat.numero}" minQueryLength="3" queryDelay="500" itemValue="#{mandat}" converter="MandatConverter" forceSelection="false" placeholder="@#{msg['Mandat']}"> <p:ajax event="itemSelect" listener="#{cc.updateValue}" update="btn"/> <p:ajax event="itemUnselect" listener="#{cc.updateValue}" update="btn"/> <p:ajax event="change" listener="#{cc.updateValue}" update="btn"/> <p:column> <p:outputLabel value="#{mandat.numero}"/> </p:column> <p:column> <p:outputLabel value="#{mandat.listMandatIdentiteToString}"/> </p:column> <p:column> <p:outputLabel value="#{mandat.objet}"/> </p:column> </p:autoComplete> </p:column> <p:column> <p:link id="btn" target="_blank" href="#{cc.attrs.value.cheminServeurConverti}" disabled="#{cc.attrs.value eq null or cc.attrs.value.cheminServeur eq null}"> <p:tooltip for="btn" value="#{msg['OuvrirLeMandatSurLeServeur']}"/> <i class="fa fa-folder-open"></i> </p:link> </p:column> </p:row> </p:panelGrid> </composite:implementation> <composite:interface> <composite:attribute name="value"></composite:attribute> <composite:attribute name="readOnly"></composite:attribute> </composite:interface> <composite:interface> <composite:attribute name="value"></composite:attribute> <composite:attribute name="readOnly"></composite:attribute> </composite:interface> </html>
La classe abstraite de mes composants :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2 <my_cc:cmpMandatSelector id="cmpMandat" value="#{gestionFactDebiteursProvisoireForm.mandat}" readOnly="#{gestionFactDebiteursProvisoireForm.selectedFacture eq null or gestionFactDebiteursProvisoireForm.selectedFacture.factureDebiteur ne null}"/>
Et la classe du composant en question :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public abstract class AbstractBeanSelectionComponent extends UIInput implements NamingContainer { public final Logger logger = Logger.getLogger(getClass().getSimpleName()); protected UIInput key; public abstract void formatValue(); public abstract void updateValue(AjaxBehaviorEvent event); @Override public String getFamily() { return UINamingContainer.COMPONENT_FAMILY; } /** * Début de l'encodage du composant */ @Override public void encodeBegin(FacesContext facesContext) throws IOException { logger.log(Level.FINEST, "encodeBegin(FacesContext)"); formatValue(); super.encodeBegin(facesContext); } /** * Envoyer un message d'application * @param target * @param message */ public void sendFacesMessage(String target, FacesMessage message) { if (message != null) { FacesContext facesContext = FacesContext.getCurrentInstance(); facesContext.getExternalContext().getFlash().setKeepMessages(true); facesContext.addMessage(target, message); } } /** * Validation (si nécessaire) */ @Override public void validate(FacesContext facesContext) { logger.log(Level.FINEST, "validate(FacesContext)"); /* * On traite tous les validators enregistrés */ for (Validator validator : getValidators()) { try { validator.validate(facesContext, this, getValue()); } catch (ValidatorException e) { invalidValue(); sendFacesMessage(null, e.getFacesMessage()); } } } /** * Valeur incorrecte */ public void invalidValue() { logger.log(Level.FINEST, "invalidValue()"); if (getKey().getValue() != null) { setValid(false); key.setValid(false); } } public UIInput getKey() { return key; } public void setKey(UIInput key) { this.key = key; } }
Qqun peut-il m'aider à résoudre ces 2 problèmes ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
51
52
53
54
55
56
57
58
59
60
61 @FacesComponent("mandatSelectionComponent") public class MandatSelectionComponent extends AbstractBeanSelectionComponent { @EJB private MandatService m_mandatService; /** * La valeur change, mise à jour des composants * @param event */ @Override public void updateValue(AjaxBehaviorEvent event) { try { logger.log(Level.FINEST, "updateValue(AjaxBehaviorEvent) "); if (event instanceof SelectEvent) { Mandat mandat = (Mandat) ((SelectEvent) event).getObject(); setValue(mandat); RequestContext.getCurrentInstance().execute("callChangeFunction('" + key.getClientId() + "')"); } else { if (key.getValue() != null && key.getValue().toString().trim().length() > 0) { String keyValue = (String) key.getValue(); Mandat mandat = m_mandatService.getMandat(keyValue); setValue(mandat); } else { super.setValue(null); updateModel(FacesContext.getCurrentInstance()); formatValue(); } } } catch (Exception e) { logger.log(Level.SEVERE, e.toString()); } } /** * Formattage de la valeur */ @Override public void formatValue() { Mandat mandat = null; if (getValue() instanceof Mandat) { mandat = (Mandat)getValue(); } if (mandat != null) { key.setValue(mandat.getNumero()); } else { key.setValue(null); } } public List<Mandat> completeMandat(String query) { String texte = query.startsWith("*") ? "" : query; return m_mandatService.getMandatList(texte, true); } }
merci pour votre aide
Partager