condition for selectOneMenu not working on edit tab

I'm using the following code to display some drop down lists based on condition , it's working fine when creating a document but when trying to modify the documents , the select doesn't change i keep getting the first value . I'm using Nuxeo 7.10 Here is the code i'm using :

<div xmlns="http://www.w3.org/1999/xhtml"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html"
  xmlns:c="http://java.sun.com/jstl/core"
  xmlns:t="http://myfaces.apache.org/tomahawk"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:nxu="http://nuxeo.org/nxweb/util"
  xmlns:nxd="http://nuxeo.org/nxweb/document"
  xmlns:nxh="http://nuxeo.org/nxweb/html"
  xmlns:nxdir="http://nuxeo.org/nxdirectory"
  xmlns:a4j="https://ajax4jsf.dev.java.net/ajax">
<h:head>

</h:head>
<h:form >


     <h:selectOneMenu id="thekeywords" value="#{field}">
        <f:selectItem itemLabel="Sélectionner une valeur" />
        <f:selectItem itemValue="Techniques de l’entreprise" itemLabel="Techniques de l’entreprise" />
        <f:selectItem itemValue="Développement du dirigeant" itemLabel="Développement du dirigeant" />
        <f:selectItem itemValue="Environnement de l’entreprise" itemLabel="Environnement de l’entreprise" />
        <f:selectItem itemValue="Management" itemLabel="Management" />
        <f:ajax render="tables" />
      </h:selectOneMenu>
      <h:panelGroup id="tables">
      <h:outputLabel for="#{widget.id}_tech" rendered="#{field == 'Techniques de l’entreprise'}" >Nature </h:outputLabel>

     <h:selectOneMenu id="#{widget.id}_tech" value="#{field_1}" rendered="#{field == 'Techniques de l’entreprise'}">
        <f:selectItem itemLabel="Sélectionner une valeur" />
        <f:selectItem itemValue="Stratégie" itemLabel="Stratégie" />
        <f:selectItem itemValue="Ressources Humaines" itemLabel="Ressources Humaines" />
        <f:selectItem itemValue="Marketing" itemLabel="Marketing" />
        <f:selectItem itemValue="Commercial" itemLabel="Commercial" />
        <f:selectItem itemValue="Nouvelles Technologies" itemLabel="Nouvelles Technologies" />
        <f:selectItem itemValue="Finance et Fiscalité" itemLabel="Finance et Fiscalité" />
        <f:selectItem itemValue="Gouvernance" itemLabel="Gouvernance" />
        <f:ajax render="tables" />
      </h:selectOneMenu>

    <h:outputLabel for="#{widget.id}_dev" rendered="#{field == 'Développement du dirigeant'}">Nature </h:outputLabel>

     <h:selectOneMenu id="#{widget.id}_dev" value="#{field_1}" rendered="#{field == 'Développement du dirigeant'}">
        <f:selectItem itemLabel="Sélectionner une valeur" />
        <f:selectItem itemValue="Connaissance de soi" itemLabel="Connaissance de soi" />
        <f:selectItem itemValue="Développer ses savoirs faire" itemLabel="Développer ses savoirs faire" />
        <f:selectItem itemValue="Développer son Équilibre personnel" itemLabel="Développer son Équilibre personnel" />
        <f:ajax render="tables" />
      </h:selectOneMenu>

    <h:outputLabel for="#{widget.id}_env" rendered="#{field == 'Environnement de l’entreprise'}">Nature </h:outputLabel>

      <h:selectOneMenu id="#{widget.id}_env" value="#{field_1}" rendered="#{field == 'Environnement de l’entreprise'}">
        <f:selectItem itemLabel="Sélectionner une valeur" />
        <f:selectItem itemValue="Changement et Transformation" itemLabel="Changement et Transformation" />
        <f:selectItem itemValue="Géopolitique" itemLabel="Géopolitique" />
        <f:selectItem itemValue="Prospective" itemLabel="Prospective" />
        <f:selectItem itemValue="Culture Générale" itemLabel="Culture Générale" />
        <f:selectItem itemValue="Créativité" itemLabel="Créativité" />
        <f:selectItem itemValue="Innovation" itemLabel="Innovation" />
        <f:ajax render="tables" />
      </h:selectOneMenu>

     <h:outputLabel for="#{widget.id}_mng" rendered="#{field == 'Management'}">Nature </h:outputLabel>

    <h:selectOneMenu id="#{widget.id}_mng" value="#{field_1}" rendered="#{field == 'Management'}">
        <f:selectItem itemLabel="Sélectionner une valeur" />
        <f:selectItem itemValue="Comportement" itemLabel="Comportement" />
        <f:selectItem itemValue="Leadership" itemLabel="Leadership" />
        <f:selectItem itemValue="Organisation" itemLabel="Organisation" />
        <f:selectItem itemValue="Négociation" itemLabel="Négociation" />
        <f:selectItem itemValue="Changement" itemLabel="Changement" />
        <f:ajax render="tables" />
      </h:selectOneMenu>
    </h:panelGroup>

 </h:form>














</div>

In the console i'm getting those errors :

Failed to load resource: the server responded with a status of 404 (Introuvable)
'webkitMovementX' is deprecated. Please use 'movementX' instead. :8080/ged/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.5.0.Alpha3/PackedCompressed/org.richfaces/jquery.js:78 
'webkitMovementY' is deprecated. Please use 'movementY' instead. :8080/ged/org.richfaces.resources/javax.faces.resource/org.richfaces.staticResource/4.5.0.Alpha3/PackedCompressed/org.richfaces/jquery.js:78 
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check http://xhr.spec.whatwg.org/. :8080/ged/javax.faces.resource/jsf.js.faces?ln=javax.faces:1 
default.js:6043 Uncaught TypeError: jQuery(...).initTipsy is not a function
(program):3 Uncaught TypeError: jQuery(...).focusFirst is not a function

Update

Here is the code i'm using to display the select widget :

<widget name="rubrique" type="template">
        <labels>
          <label mode="any">
            Rubrique 
          </label>

        </labels>

        <translated>true</translated>
        <fields >
          <field>rens:rubrique</field>
          <field>rens:nature</field>
        </fields>
        <properties mode="any">
          <property name="template">
            /widgets/select_flavor_widget_temp.xhtml
          </property>


        </properties>
      </widget>
0 votes

1 answers

2213 views

ANSWER

Have you tried to display the values of field and field_1? Maybe their value or their type isn't right.
01/17/2016

Hi Greg Drayon my code is working well when creating a document , i mean the second select change based on first select value, but when i have to edit a document , the second select doesn't change.
01/18/2016

Yes. But have you tried to display #{field_1}" and #{field}" in your page in creation AND in edition?
01/18/2016

Greg Drayon Yes they are displayed, i've added the code i'm using in layout to display the select widgets. I think that there is a conflict between my code and the edit one
01/18/2016

You should try to display them directly, without an h:outputLabel, or without the rendered condition. Thus, you could see their value, not "a message displayed if they have a given value". Because maybe the field isn't saved when you create your document. If so, #{field} is null, and nothing can be displayed in your edition form. If nothing is saved, maybe it comes from the creation form, not the edition one.
01/18/2016

Thank you Greg Drayon , h:outputLabel is just a label it has no effect on select widget, the field is saved i can see it on summary and it is searchable. Can you tell me more about how i could dispaly the second select without condition ?
01/18/2016

I would first check the class of the field value (#{field.class} and #{field_1.class}). Then, as it should be a String, according to your example, and if it has one of the values you want it to have (either "Techniques de l’entreprise", "Développement du dirigeant", "Environnement de l’entreprise" or "Management"), I would then try the "eq" operator in my EL instead of "==". No sure it would solve your problem, but maybe worth it.
01/18/2016

Greg Drayon I've read in the following link that "==" and "eq" operator are the same http://stackoverflow.com/questions/10796350/should-i-choose-or-eq-for-comparing-string-in-el , also as i said i've no problem with this while creating a new document so i don't think that this is the problem. I'm not too good on Javascript but i think it has something to do with some JS code i've noticed that in creation useCapture is set to "true" and in Edit it is set to "false" .
01/18/2016

If it is, then if you don't see you dropdown list in your page, you should check the page code source (CRTL + U, if you use Firefox). As the rendition of the page code source is calculated server side, you should appear inside, even if the displayed page itself doesn't show the drop down list. If it doesn't appear in the page code source, then JS is not involved. One again, I would check in the page itself the values and class of field and field_1. Not through a summary layout or any other page, but from the edition form itself. But that's just me.
01/18/2016

Greg Drayon I just want to mention that the dropdown list is displayed but the problem is that it's values don't change when changing the value of the first dropdown list
01/18/2016

OK, I clearly missed the hint. So you want the 2nd dropdown list to change when you change the value of the 1st one, without reloading the page nor saving the document? Like with some Ajax process?
01/18/2016

Greg Drayon Yes i want the second dropdown list to change it's values when changing the value of the first one, with the code above it . refresh the second dropdown list but only when creating a document for the first time. In edit tab both dropdown lists are displayed
01/18/2016

Got it. Yes, it won't do. When you create the document, the "field_1" has no value. Whe you save, the value is registered and you can see the second drop down list in the edition form because it is calculated to be displayed server side. I guess if you set a news value in the first drop down list, then save, then try to edit again, the second drop down list if correctly updated? If so, it's because the new value is not sent to the server before your sabing, and the page is not recalculated. You should check this page to bind two widgets.
01/18/2016

Greg Drayon if you set a new value in the first drop down list, then save, then try to edit again, the second drop down list if correctly updated? Yes it's true. I thought this could be done using Ajax …
01/18/2016

It can. But there is no Ajax in your given code.
01/18/2016

Can you try getting rid of the h:form tag? Seems you have two nested forms, since the edit layout is already surrounded by a h:form tag, and this could produce strange behaviors. The h:head tag should be removed too.
01/18/2016

My bad, I hadn't seen the "f:ajax render="tables" /" part…
01/18/2016

Thank you Greg Drayon and Anahide Tchertchian for your help i finally got it working
01/18/2016

Can you please share what you had to change to make it working?
01/18/2016

Anahide Tchertchian I've followed what you said , can you please move your comment to an answer
01/18/2016



You should get rid of the h:form tag: it seems that you have two nested forms, since the edit layout is already surrounded by a h:form tag, and this could produce strange behaviors. The h:head tag should be removed too.

1 votes