cancel
Showing results for 
Search instead for 
Did you mean: 

How to populate a Drop-Down at runtime ??

friedman30
Champ in-the-making
Champ in-the-making
Hi,

i read this thread (same problems), but lost my way in it…
http://forums.alfresco.com/viewtopic.php?t=2235&postdays=0&postorder=asc&highlight=ready+steady&star...
:shock:    :shock:    :shock:
I have a custom type (lets say a "football team" type),  and one of it's properties is "players" (and i have a custom type of "players" for that).

since the "players" can be added to a space dynamically, and i want to add "players" to a newly added "football team", i need to show a drop-down with all the available "players" when editing the "football team" properties.

for that, i need to get all the "players" at run-time, set them in the drop-down, and show them as a "football team" property.  

:arrow: what should i change in the customModel.xml & web-client-config-custom.cml files?

:arrow: do i have to build a componentGenerator of my own, or there is a way to just modify one of the existing classes?

:arrow: does anyone have a working example for this feature?

:idea:
thanks!!

Dror
8 REPLIES 8

friedman30
Champ in-the-making
Champ in-the-making
I've found the way  Smiley Very Happy

these are the steps:

customModel.xml -
added the 2 new types of content:
<!– Definition of new Content Type: Player –>
     <type name="custom:Player">
            <title>Player</title>
             <parent>cm:content</parent>
             <properties>
                  <property name="custom:PlayerName">
                      <title>Player Name</title>
                      <type>d:text</type>
                  </property>
            </properties>
      </type>
     
       <!– Definition of new Content Type: Team  –>
     <type name="custom:Team">
            <title>Team</title>
             <parent>cm:content</parent>
             <properties>
                  <property name="custom:TeamName">
                      <title>Team Name</title>
                      <type>d:text</type>
                  </property>
                  <property name="custom:Players">
                      <title>Players</title>
                      <type>d:text</type>                   
                  </property>
            </properties>
      </type>

web-client-config-custom.xml -
Added these config evaluators:
    <config evaluator="string-compare" condition="Action Wizards">
         <subtypes>
          <type name="custom:Player" />
       </subtypes>
    </config>
   
    <config evaluator="string-compare" condition="Content Wizards">
         <content-types>
            <type name="custom:Player" />
         </content-types>
    </config>
  
   <config evaluator="node-type" condition="custom:Player">
        <property-sheet>
            <show-property name="custom:PlayerName" />
         </property-sheet>
    </config>–>
   
      <!– Lists the custom aspect in business rules Action wizard –>
    <config evaluator="string-compare" condition="Action Wizards">
         <subtypes>
          <type name="custom:Team"/>
       </subtypes>
    </config>
   
    <config evaluator="string-compare" condition="Content Wizards">
         <content-types>
            <type name="custom:Team" />
         </content-types>
    </config>
  
   <config evaluator="node-type" condition="custom:Team">
        <property-sheet>
            <show-property name="custom:TeamName" />
            <show-property name="custom:Players" component-generator="PlayerSelectorGenerator"/>
         </property-sheet>
    </config>–>
:!: pay attention to this line:
<show-property name="customSmiley Tonguelayers" component-generator="PlayerSelectorGenerator"/>

PlayerSelectiorGenerator is a new class, placed in this package: org.alfresco.web.bean.generator and looks almost like TextFieldGenerator class. (you have to sign it at faces-config-beans.xml or else JSF would not recognize it.) 
this is the only method I've touched:
protected UIComponent createComponent(FacesContext context, UIPropertySheet propertySheet, 
         PropertySheetItem item)
   {
      UIComponent component = null;
     
      if (propertySheet.inEditMode())
      {

            component = context.getApplication().createComponent(
                  UISelectOne.COMPONENT_TYPE);
            FacesHelper.setupComponentId(context, component, item.getName());
           
            // create the list of choices
            UISelectItems itemsComponent = (UISelectItems)context.getApplication().
               createComponent("javax.faces.SelectItems");
           
            List<SelectItem> items = new ArrayList<SelectItem>(3);
            //TODO: set items dynamically
            items.add(new SelectItem("Player1", "Player1"));
            items.add(new SelectItem("Player1", "Player1"));
            items.add(new SelectItem("Player1", "Player1"));

           
            itemsComponent.setValue(items);
           
            component.getChildren().add(itemsComponent);

      }
      else
      {
         // create an output text component in view mode
         component = createOutputTextComponent(context, item.getName());
      }
     
      return component;
   }
the only thing i still have to do, is to add the items dynamically (search for "player" type items and add them to the array).

now, when you'll add a new "Team" content, it will have a "Players" property which is a drop-down.

hope this will help   😎

Dror

miggy4340
Champ in-the-making
Champ in-the-making
Thank you for you post as we were looking for an example with custom-component.

For drop down list we had a diffrent approach we made a custom constraint that work like the list constraint but get the list of allowed values from a database table.

The wiki contains good enough information for this we just found out that we have to put the list tag in the model even if the list is empty and not used.

The standard UI componnet work with this approach. The main advantages is that the allowed value is verified by the repository not the user interface, so it is also verified if the propertie is changed thru javascript, web services,…


When the list is too long the combo component is not a good solution so we need a custom contraint and custom UI component.

Regards

Bertrand

shubhada
Champ in-the-making
Champ in-the-making
Hi,
Did you get it working with custom contraint.. ?
I have a property file placed in companyhome. Reading the value from there and setting the list.

My model says:
<constraints>   
      <constraint name="fd:contentstatus" type="com.rcb.constraints.productListConstraint"/ >
</constraints>
I have a class for reading this value.
I am getting the value as null for the list becz of which server is not getting up.

Error is :
2015-12-16 19:55:30,908  INFO  [management.subsystems.ChildApplicationContextFactory] [localhost-startStop-1] Starting 'Replication' subsystem, ID: [Replication, default]
2015-12-16 19:55:30,934  INFO  [management.subsystems.ChildApplicationContextFactory] [localhost-startStop-1] Startup of 'Replication' subsystem, ID: [Replication, default] complete
2015-12-16 19:55:32,104  ERROR [web.context.ContextLoader] [localhost-startStop-1] Context initialization failed
org.alfresco.service.cmr.dictionary.DictionaryException: 11160017 The list of allowed values is empty
   at org.alfresco.repo.dictionary.constraint.ListOfValuesConstraint.setAllowedValues(ListOfValuesConstraint.java:182)
   at com.skandia.wcm.constraints.ProductListConstraint.getAllowedValues(ProductListConstraint.java:160)
   at org.alfresco.opencmis.dictionary.AbstractTypeDefinitionWrapper.addChoiceList(AbstractTypeDefinitionWrapper.java:765)
   at org.alfresco.opencmis.dictionary.AbstractTypeDefinitionWrapper.createPropertyDefinition(AbstractTypeDefinitionWrapper.java:527)
   at org.alfresco.opencmis.dictionary.AbstractTypeDefinitionWrapper.createOwningPropertyDefinitions(AbstractTypeDefinitionWrapper.java:343)
   at org.alfresco.opencmis.dictionary.PolicyTypeDefintionWrapper.<init>(PolicyTypeDefintionWrapper.java:98)
   at org.alfresco.opencmis.dictionary.CMISStrictDictionaryService.createTypeDef(CMISStrictDictionaryService.java:231)
   at org.alfresco.opencmis.dictionary.CMISStrictDictionaryService.createTypeDefs(CMISStrictDictionaryService.java:250)
   at org.alfresco.opencmis.dictionary.CMISStrictDictionaryService.access$000(CMISStrictDictionaryService.java:49)

Can you please help on this?

friedman30
Champ in-the-making
Champ in-the-making
i've got another problem… (i thought this would be much easier) :?

I want to show all the "players" (all content which is of a "player" type) in the drop down.
for that, i need to search a specific space for all "players".

I looked at the Search API, but couldn't figure out the way to do that (I followed the examples, but the results i get are all null…)

How do i search for a specific (custom) type?
Is there a way to specify the space in which i want the search to take place?

Thanks,

Dror

friedman30
Champ in-the-making
Champ in-the-making
found the first answer to the question.  Smiley Very Happy

SearchParameters sp = new SearchParameters();
            sp.addStore(Repository.getStoreRef());
            sp.setLanguage(SearchService.LANGUAGE_LUCENE);
            sp.setQuery("TYPE:\"{custom.model}Player\"");
            ResultSet results = null;

            results = Repository.getServiceRegistry(context).getSearchService().query(sp);
            if(results != null)
            {
                List<SelectItem> items = new ArrayList<SelectItem>(3);
                for(ResultSetRow row : results)
                {
                    String name = row.getQName().getLocalName();
                    if(name != "")
                    {
                       items.add(new SelectItem(name, name));
                    }
                }
                itemsComponent.setValue(items);
                component.getChildren().add(itemsComponent);
                }

:arrow:
:arrow:                             I'm still wondering where (and how) to define the space i want the query to be executed on…   :shock:
:arrow:

Thanks,

Dror

friedman30
Champ in-the-making
Champ in-the-making
what i need to do now, is to generate a UISelectManyListBox instead of the UISelectOne i've used for the DropDown.

i tried setting the component to be a UISelectManyListBox but since the binding for this component needs to be to an arraylist, i get this error:

javax.faces.FacesException: ValueBinding for UISelectMany : {Component-Path : [Class: javax.faces.component.UIViewRoot,ViewId: /jsp/dialog/container.jsp][Class: javax.faces.component.html.HtmlForm,Id: dialog][Class: javax.faces.component.UINamingContainer,Id: dialog-body][Class: org.alfresco.web.ui.repo.component.property.UIPropertySheet,Id: content-props][Class: org.alfresco.web.ui.repo.component.property.UIProperty,Id: prop_custom_Player][Class: javax.faces.component.UISelectMany,Id: custom_Player]} must be of type List or Array

:?:  what (and where) are the changes i need to perform to get this to work??

thanks,

Dror

naveenkumar
Champ in-the-making
Champ in-the-making
hi fried,
For my application i need to include drop down list which populate values based on the content created inside folder.. for ex: user homes folder has 10 content, the values for the list is names of the 10 content.

I saw your posting:
http://forums.alfresco.com/viewtopic.php?t=6840&highlight=populate

I followed but getting some error::
16:02:41,515 ERROR [org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/alfresco]] Error configuring application listener of class org.alfresco.web.app.ContextListener
java.lang.ClassNotFoundException: org.alfresco.web.app.ContextListener
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1355)
   at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1201)
   at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3711)
   at org.apache.catalina.core.StandardContext.start(StandardContext.java:4211)
   at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
   at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
   at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
   at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:809)
   at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:698)
   at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:472)
   at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1122)
   at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:310)
   at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1021)
   at org.apache.catalina.core.StandardHost.start(StandardHost.java:718)
   at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1013)
   at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:442)
   at org.apache.catalina.core.StandardService.start(StandardService.java:450)
   at org.apache.catalina.core.StandardServer.start(StandardServer.java:709)
   at org.apache.catalina.startup.Catalina.start(Catalina.java:551)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   at java.lang.reflect.Method.invoke(Method.java:585)
   at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:294)
   at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:432)
here is my step:

1) i created ListPopulateGenerator.class and made the changes.
2)created new web-client.jar and copied to web-inf/lib folder.

Please help me   :?

Thanks
Naveen

malindabelly
Champ in-the-making
Champ in-the-making
I am trying to change the list item values of a dropdown list based on values of an other dropdown list. The list values of drpAdult range from 0-9 and list values of drpInfant range from 0-(Value of drpAdult selected).

So, for example, if I select 5 in the drpAdult dropdown, the range of list item values of drpInfant will be from 0-5.

I have written the code below, but it is not populating the values in the drpInfant dropdown, which I am trying to insert on drpAdult_SelectedIndexChanged event.
http://examcollection.in/70-488-vce-download.html