cancel
Showing results for 
Search instead for 
Did you mean: 

How to populate values into list box?

damodar
Champ in-the-making
Champ in-the-making
Hi,

I created one new custom property to the content.  I wanted to make that as list box, by the help of Component Generator Framework I configured it with TextFieldGenerator, just I am getting simple text box.  Can you please give some advice how to make that text box as list box with some custom values?

Thanks in advance..
Damodar
14 REPLIES 14

naveenkumar
Champ in-the-making
Champ in-the-making
I am using my own model.xml to list the values.

here is my code
 
<?xml version="1.0" encoding="UTF-8" ?> 
- <model name="dl:content" xmlns="http://www.alfresco.org/model/dictionary/1.0">
- <!–  Optional meta-data about the model
  –>
  <description>Modele NewsML</description>
  <author>Christophe</author>
  <version>0.1</version>
- <!–  Imports are required to allow references to definitions in other models
  –>
- <imports>
- <!–  Import Alfresco Dictionary Definitions
  –>
  <import uri="http://www.alfresco.org/model/dictionary/1.0" prefix="d" />
- <!–  Import Alfresco Content Domain Model Definitions
  –>
  <import uri="http://www.alfresco.org/model/content/1.0" prefix="cm" />
  </imports>
- <!–  Introduction of new namespaces defined by this model
  –>
- <!–  NOTE: The following namespace my.new.model should be changed to reflect your own namespace
  –>

- <namespaces>
  <namespace uri="com.company.dl.model" prefix="dl" />  
  </namespaces>


- <constraints>
- <constraint name="dl:subject_matter" type="LIST">
- <parameter name="allowedValues">
- <list>
  <value>Sports</value>
  <value>Education</value>
  <value>Entertain</value>   
  </list>
  </parameter>
  </constraint>
- <constraint name="dl:subject_detail" type="LIST">
- <parameter name="allowedValues">
- <list>
  <value>FootBall</value>
  <value>Cricket</value>
  <value>Hockey</value>
  <value>Mathsnews</value>
  <value>Science</value>
  <value>Social</value>
  <value>Movies</value>
  <value>Chatting</value>
  <value>Dating</value>  
  </list>
  </parameter>
  </constraint>
  </constraints>



- <types>
- <type name="dl:content">
  <title>Content</title>
  <parent>cm:content</parent>
- <mandatory-aspects>
  <aspect>dl:categorizable</aspect>
  </mandatory-aspects>
  </type>
- <!–  Definition of new Content Type: Standard Operating Procedure
  –>
- <type name="dl:sportscontent">
  <title>Sportscontent</title>
  <parent>dl:content</parent>
- <properties>
- <property name="dl:Title">
  <type>d:text</type>
  <mandatory>true</mandatory>
  </property>
- <property name="dl:Publish">
  <type>d:date</type>
  <mandatory>true</mandatory>
  </property>
  </properties>
  </type>
-   </types>

- <aspects>
- <aspect name="dl:categorizable">
  <title>Categorizable</title>
- <properties>
- <property name="dl:SubjectMatter">
  <title>SubjectMatter</title>
  <type>d:text</type>
  <mandatory>true</mandatory>
- <constraints>
  <constraint ref="dl:subject_matter" />
  </constraints>
  </property>
- <property name="dl:SubjectDetail">
  <title>SubjectDetail</title>
  <type>d:text</type>
  <mandatory>true</mandatory>
- <constraints>
  <constraint ref="dml:subject_detail" />
  </constraints>
  </property>
-   </properties>
  </aspect>
  </aspects>
  </model>

I am Using Constraints to display the value for the particular field, where i need to add the valueChangeListener?? could u please tell me..
when i click sports in the list ,it will dispaly football,cricket ,hockey in the second drop down…..

Thanks
Naveen

gavinc
Champ in-the-making
Champ in-the-making
OK, I presume then that you are using the built in PropertySheet component to display these properties?

If that is the case unfortunately we do not support what you are trying to do out of the box.

To accomplish this you will need to write a custom component generator. You can just extend our TextFieldGenerator. When the JSF component is created you'll need to add the valueChangeListener I mentioned in the previous post.

Have a look at http://wiki.alfresco.com/wiki/Component_Generator_Framework for some details.

To use your new component generator you'll need to reference it in your property definition, for example:

<show-property name="your:prop" component-generator="YourNewComponentGenerator" />

nahanni
Champ in-the-making
Champ in-the-making
Hi gavin,

Is there any component generator in Alfresco that use a valueChangeListener ?

I would like to read its source code in SDK in order to have a sample.

Thank you

Dom

nahanni
Champ in-the-making
Champ in-the-making
Hi,

I have 2 lists displayed with a custom component generator. List 2 is populated according to value selected in list 1.

I have attached a valuechangelistener to my custom component in the component generator.


MethodBinding mb = FacesContext.getCurrentInstance().getApplication().createMethodBinding("#{TextFieldCategoryListener.processValueChange}",new Class[] { ValueChangeEvent.class });
componentSelectOne.setValueChangeListener(mb);

When a select an item in the list, the onChange event submit the form and the listener bean is called. I can see the new value in the console due to the System.out.println("\n" + event.getNewValue()); call.

public class TextFieldCategoryListener implements ValueChangeListener {
   
      public void processValueChange(ValueChangeEvent event)
       throws AbortProcessingException {
    
       if (null != event.getNewValue()) {

           // Ensure a refresh
          UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();

          System.out.println("\n" + event.getNewValue());

       }
     }
   }

So, the form is refreshed, the listener is called.

No, at refresh time, I would like to populate list 2 with values according to the value selected in list 1.

My lists are populated in the component generator, but the component generator is not called at refresh time.

I have tried this in the listenet bean, but without success.

// Ensure a refresh
UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();


Any suggestion on how continue ?

Thank you

Dom

gavinc
Champ in-the-making
Champ in-the-making
You need to populate your 'list2' dynamically i.e. from a managed bean rather than in the component generator.

If you use a value binding expression on 'list2' for the 'value' then the getter you specify in the expression should get called. You can then return the appropriate set of options.