Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
sheela mk
Dependent Combo Box
May 28, 2012 12:24 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

hai..Pls..Let me know how to achieve dependent combo box,

Like selecting Country has to populate regions of country..
DarshanKumar N Bhatia
RE: Dependent Combo Box
May 28, 2012 3:02 AM
Answer

DarshanKumar N Bhatia

Rank: Junior Member

Posts: 85

Join Date: March 2, 2010

Recent Posts

Hi...

Check this ...

Using Javascript : Link : http://javascript.about.com/library/bl3drop.htm

Using JQuery : Link : http://www.erichynds.com/examples/jquery-related-selects/

Even u can use any jQuery Plugins .


HTH ...

Mr.D
sheela mk
RE: Dependent Combo Box
May 28, 2012 10:57 PM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai...thanks for the reply de..Pls Let me know by using Ajax, and calling serveResource method of JSR 286..

and also state should be populated from database..

Thanksemoticon
Subhash Shah
RE: Dependent Combo Box
May 28, 2012 11:38 PM
Answer

Subhash Shah

Rank: Junior Member

Posts: 77

Join Date: November 29, 2011

Recent Posts

Hi,

I think following liferay forum post will be helpful
http://www.liferay.com/community/forums/-/message_boards/message/5722974
Amit Doshi
RE: Dependent Combo Box
May 29, 2012 12:16 AM
Answer

Amit Doshi

Rank: Liferay Master

Posts: 544

Join Date: December 29, 2010

Recent Posts

Hi sheela,

The functionality that you are looking for is already present in liferay.
Please find the screen shot for the same.

You can refer jsp file from the path html/portlet/users_admin/common/addressess.jsp

Regards,
Amit Doshi
Attachment

Attachments: address.PNG (27.3k)
sheela mk
RE: Dependent Combo Box
May 29, 2012 4:53 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..Thanks for the reply..de..

I'm using liferay CE..In address page of user...regions are not populating after selecting Country..

So..I'm trying to do using serveResource() as per JSR 286..that uses Ajax, at the same time values shoud be from DB..


Pls let me knw..any solutions...


Let me knw which Edition of liferay you are using..

Thanks,emoticon
sheela mk
RE: Dependent Combo Box
May 29, 2012 5:11 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..That address.jsp is really confusing..can you know me as simple as possible..

ex. defining one to many relationship between Country and Regions in service.xml

so that I do get Collection of regions based on Country Id..

Thanks emoticon
Nagendra Kumar Busam
RE: Dependent Combo Box
May 29, 2012 6:00 AM
Answer

Nagendra Kumar Busam

Rank: Liferay Master

Posts: 637

Join Date: July 7, 2009

Recent Posts

There is no implicit handling for 1 to m relationshiop in service.xml (using service builder tool). Liferay just provides a utitily method if we declare one entity in particular way as column in other entity (we can get list of entities of one entity in another). The 2 entities you are referring to are liferay's OOTB entities - normally we should though those for any changes. The one mentioned by Amit was good start for this use case
sheela mk
RE: Dependent Combo Box
June 22, 2012 2:19 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..Nagendra..Pls..is it possible share any example code for dependent combo box..

I saw your..post.. about..using JSonObject...and populating thr' XUtil.m1();...but..bit not in clear..

It helps me a lot if you eloborate..it..
Emilio Jose Lamas Fraga
RE: Dependent Combo Box
June 22, 2012 3:43 AM
Answer

Emilio Jose Lamas Fraga

Rank: Junior Member

Posts: 50

Join Date: November 29, 2011

Recent Posts

Hi!

I had trouble with dynamic select a time ago, you can take a look to this thread where I put my code (and it works fine) emoticon

Hope it helps

Regards.
sheela mk
RE: Dependent Combo Box
June 22, 2012 4:31 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

hai..this is my..service.xml..
I has to populate capabilityName based on industryId...
Pls..Let me know what code to add into js,jsp,portlet class...

Pls..Also let me know flow also..if possible..



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.database">
<author>sourceone</author>
<namespace>J</namespace>


<entity name="IndustryCategory">
<column name="industryCategoryId" type="long" primary="true" />
<column name="industryName" type="String" />
<column name="getAllCapability" type="Collection" entity="Capability" mapping-key="industryCategoryId"/>

</entity>

<entity name="Capability">
<column name="CapabilityId" type="long" primary="true" />
<column name="capabilityName" type="String" />
<column name="industryCategoryId" type="long"/>
</entity>
</service-builder>
Emilio Jose Lamas Fraga
RE: Dependent Combo Box
June 22, 2012 5:09 AM
Answer

Emilio Jose Lamas Fraga

Rank: Junior Member

Posts: 50

Join Date: November 29, 2011

Recent Posts

Hi again,

Did you build the WSDD of your service.xml? If you did, you should have a service.js file in your code, which registers the methods generated by the service builder (copy paste from my example):
 1Liferay.Service.register("Liferay.Service.plxmiperfil", "com.plexus.educantabria.miperfilescritorio.service", "mi-perfil-escritorio-portlet");
 2
 3Liferay.Service.registerClass(
 4    Liferay.Service.plxmiperfil, "Localidad",
 5    {
 6        getLocalidadesByMunicipio: true,
 7        getCentrosPorLocalidad: true,
 8        getAulasPorCentro: true
 9    }
10);
11
12Liferay.Service.registerClass(
13    Liferay.Service.plxmiperfil, "Municipio",
14    {
15        getMunicipios: true
16    }
17);


That's the code you need to make your combos work. In my example, I copied this code into the view.jsp file. Then, you can use the Dynamic Select function just like in the adress example above.

Regards
sheela mk
RE: Dependent Combo Box
June 23, 2012 12:09 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..I'm not able understand code syntax itself..

May I know your Mother Tongue..your code not in english i think..I'm understanding...properly...

After building services I got...only this much...
Liferay.Service.register("Liferay.Service.J", "com.database.service", "job-portlet");
in /js/service.js..then what to add in service.js ...What are those..getX:true???



Liferay.Service.registerClass(
Liferay.Service.plxmiperfil, "Localidad",
{
getLocalidadesByMunicipio: true,
getCentrosPorLocalidad: true,
getAulasPorCentro: true
}
);

Liferay.Service.registerClass(
Liferay.Service.plxmiperfil, "Municipio",
{
getMunicipios: true
}
);


As per my table..Let me know
 1Liferay.Service.registerClass(
 2Liferay.Service.J,"IndustryCategory  ",
 3{
 4//what to add here??
 5
 6}
 7);
 8
 9Liferay.Service.registerClass(
10Liferay.Service.J,"Capability  ",
11{
12
13//What to add here??
14}
15);
Attachments: service.xml (2.2k)
Hitoshi Ozawa
RE: Dependent Combo Box
June 23, 2012 11:18 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7990

Join Date: March 23, 2010

Recent Posts

Following is just a general idea on implementing dependent combo box in general. Create 2 entities to fill the combo box.
Create api by generating them by service builder - enable JSON interfaces. Set up to use jQuery to fill these combo boxes.

Some of liferay's portlets were written a long time ago and the codes doesn't seem to be maintained too well. It's easier to just
write from scratch.
Emilio Jose Lamas Fraga
RE: Dependent Combo Box
June 26, 2012 3:34 AM
Answer

Emilio Jose Lamas Fraga

Rank: Junior Member

Posts: 50

Join Date: November 29, 2011

Recent Posts


Liferay.Service.register("Liferay.Service.J", "com.database.service", "job-portlet");
in /js/service.js..then what to add in service.js ...What are those..getX:true???


Those methods, are my own service builder finder methods, implemented on the *ServiceImpl classes. I use them to populate my combo boxes.
sheela mk
RE: Dependent Combo Box
June 26, 2012 5:35 AM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..I tried..out your example..I'm able..to populate for only Country Id of 1..ie canada..But Others are not populating..

And..Also..Not your entities also..not geting populating..

I ve uploaded my jsp and service.xml ..Pls see where went wrong..is there any file to share..regarding this example..


  1
  2
  3<%@ taglib uri="http://alloy.liferay.com/tld/aui" prefix="aui" %>
  4<%-- <%@page import="database.service.ConcellosServiceUtil"%>
  5<%@ page import="com.liferay.portal.kernel.exception.SystemException" %> --%>
  6<%-- <%@ page import="database.model.Concellos" %>
  7<%@ page import="database.model.Localidade" %>
  8<%@ page import="database.service.ConcellosLocalServiceUtil" %>
  9<%@ page import="database.service.LocalidadeLocalServiceUtil" %>
 10<%@ page import="java.util.List" %> --%>
 11<%@ page import="com.liferay.portal.theme.ThemeDisplay" %>
 12<%@ page import="com.liferay.portal.kernel.util.WebKeys" %>
 13<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 14
 15//What is inside..jQuery file???
 16<!-- <script src="/js/liferay/service.js" type="text/javascript"></script>
 17<script src="/html/js/jquery/jquery.js" type="text/javascript"></script> -->
 18
 19
 20<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
 21
 22<portlet:defineObjects />
 23
 24<%
 25ThemeDisplay themeDisplay = (ThemeDisplay)renderRequest.getAttribute(WebKeys.THEME_DISPLAY);
 26themeDisplay.setIncludeServiceJs(true);
 27%>
 28
 29<script type="text/javascript">
 30Liferay.Service.register("Liferay.Service.D", "database.service", "double-portlet");
 31
 32Liferay.Service.registerClass(
 33    Liferay.Service.D, "Concellos",
 34    {
 35        getConcellos: true             //But..Where this method 'l be present..in generated code??
 36    }
 37);
 38
 39Liferay.Service.registerClass(
 40    Liferay.Service.D, "Localidade",
 41    {
 42        localidadesPorMunicipio: true   //Where this method 'l be present..in generated code??
 43    }
 44);
 45
 46
 47</script>
 48
 49<script type="text/javascript">
 50Liferay.Localizaciones = {
 51      
 52        getMunis: function(callback) {
 53            Liferay.Service.D.Concellos.getConcellos(
 54                {
 55                },
 56                callback
 57            );
 58        },
 59        getLocs: function(callback, selectKey) {
 60            Liferay.Service.D.Localidade.localidadesPorMunicipio(
 61                {
 62                    municipioId:Number(selectKey)
 63                },
 64                callback
 65            );
 66        }
 67    };
 68</script>
 69
 70<%
 71
 72
 73
 74
 75/*
 76//TESTING THE METHODS FROM SERVICE BUILDER
 77List<Localidade> locs = LocalidadeLocalServiceUtil.localidadesPorMunicipio(1);
 78for (int i = 0; i < locs.size(); i++){
 79    System.out.println("LOC: "+locs.get(i).getNombreloc());
 80}
 81System.out.println("OK");
 82
 83List<Concellos> concellos = ConcellosServiceUtil.getConcellos();
 84for (int i = 0; i < concellos.size(); i++){
 85    System.out.println("LOC: "+concellos.get(i).getNombre());
 86}
 87*/
 88
 89%>
 90
 91        <aui:select label="Municipio" name="Municipio" />
 92       
 93        <aui:select label="Localidad" name="Localidad" />
 94       
 95            <aui:script use="liferay-dynamic-select">
 96            new Liferay.DynamicSelect(
 97                [
 98                    {
 99                        select: '<portlet:namespace />Municipio',
100                        selectData: Liferay.Localizaciones.getMunis,
101                        selectDesc: 'nombre',
102                        selectId: 'municipioId',
103                        selectVal: '<%= 1 %>'
104                    },                    {
105                        select: '<portlet:namespace />Localidad',
106                        selectData: Liferay.Localizaciones.getLocs,
107                        selectDesc: 'nombreloc',
108                        selectId: 'localidadId',
109                        selectVal: '<%= 1 %>'
110                    }
111                ]
112            );
113        </aui:script>
114       
115        <aui:select label="country" name="addressCountryId"/>
116
117        <aui:select label="region" name="addressRegionId" />
118                   
119                <aui:script use="liferay-dynamic-select">
120            new Liferay.DynamicSelect(
121                [
122                    {
123                        select: '<portlet:namespace />addressCountryId',
124                        selectData: Liferay.Address.getCountries,
125                        selectDesc: 'name',
126                        selectId: 'countryId',
127                        selectVal: '<%= 1 %>'
128                    },
129                    {
130                        select: '<portlet:namespace />addressRegionId',
131                        selectData: Liferay.Address.getRegions,
132                        selectDesc: 'name',
133                        selectId: 'regionId',
134                        selectVal: '<%= 1 %>'
135                    }
136                ]
137            );
138        </aui:script>


 1
 2<?xml version="1.0" encoding="UTF-8"?>
 3<!DOCTYPE service-builder PUBLIC "-//Liferay//DTD Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
 4<service-builder package-path="database">
 5    <author>sourceone</author>
 6    <namespace>D</namespace>
 7<entity name="Concellos" local-service="true" remote-service="true">
 8
 9        <!-- PK fields -->
10
11        <column name="municipioId" type="long" primary="true" />
12
13        <!-- Audit fields -->
14
15        <column name="nombre" type="String" />
16
17
18        <!-- Order -->
19
20        <order by="asc">
21            <order-column name="nombre" />
22        </order>
23
24        <!-- Finder methods -->
25
26        <finder name="Nombre" return-type="Collection">
27            <finder-column name="nombre" />
28        </finder>
29    </entity>
30            <entity name="Localidade" local-service="true" remote-service="true">
31
32        <!-- PK fields -->
33
34        <column name="localidadId" type="long" primary="true" />
35        <column name="municipioId" type="long" />
36
37        <!-- Audit fields -->
38
39        <column name="nombreloc" type="String" />
40
41
42        <!-- Order -->
43
44        <order by="asc">
45            <order-column name="nombreloc" />
46        </order>
47
48        <!-- Finder methods -->
49        <finder name="Concello" return-type="Collection">
50            <finder-column name="municipioId" />
51        </finder>
52    </entity>
53</service-builder>



Pls Let me know ..What I'm missing..Whare I should ..see for getting correctness..
Attachment

Attachments: Screenshot-2.png (11.3k)
Emilio Jose Lamas Fraga
RE: Dependent Combo Box
June 26, 2012 9:15 AM
Answer

Emilio Jose Lamas Fraga

Rank: Junior Member

Posts: 50

Join Date: November 29, 2011

Recent Posts

Ok, first of all, sorry for the language details in my code. "Concello" stands for County, -not exactly the same, but enough for understanding, and "Localidad" stands for village, or something like that. emoticon

So, you pick a "Concello" and, then, you pick one of the "localidades" that belong to the selected one...

You need, then, a method that retrieves all the concellos (it would be just something like concelloPersistence.findAll() ), and a method that retrieves all the localidades for a particular one concello (localidadPersistence.findByConcello(concelloId), -maybe the name are not exactly the same, just remembering... )

If you run the previous service.xml, you will get all the model and service classes for both entities, you can then implement the methods you need on their respective *ServiceImpl classes.

Finally, you call the methods you've created in the RegisterClass:

 1
 2Liferay.Service.registerClass(
 3    Liferay.Service.D, "Concellos",
 4    {
 5        getConcellos: true      
 6    }
 7);
 8
 9Liferay.Service.registerClass(
10    Liferay.Service.D, "Localidade",
11    {
12        localidadesPorMunicipio: true 
13    }
14);


Remember to build WSDD in ServiceBuilder or it won't work!

and, as far as I know, that should do the trick emoticon

Of course, you have to populate the database tables with some "concellos" and "localidades" with the right IDs to get it work!

Hope it helps

Good luck!
sheela mk
RE: Dependent Combo Box
June 26, 2012 11:18 PM
Answer

sheela mk

Rank: Regular Member

Posts: 112

Join Date: February 16, 2012

Recent Posts

Hai..Thanks for reply..

I'm getting..these error in console..even if doing WSDD..

My ConcellosServiceImpl
 1
 2public class ConcellosServiceImpl extends ConcellosServiceBaseImpl {
 3    /*
 4     * NOTE FOR DEVELOPERS:
 5     *
 6     * Never reference this interface directly. Always use {@link database.service.ConcellosServiceUtil} to access the concellos remote service.
 7     */
 8    List<Concellos> getConcellos() throws SystemException
 9    {
10       
11        List<Concellos> concellos=concellosPersistence.findAll();
12        return concellos;
13       
14    }
15}



My LocalidadeServiceImpl
 1
 2public class LocalidadeServiceImpl extends LocalidadeServiceBaseImpl {
 3    /*
 4     * NOTE FOR DEVELOPERS:
 5     *
 6     * Never reference this interface directly. Always use {@link database.service.LocalidadeServiceUtil} to access the localidade remote service.
 7     */
 8    List<Localidade> localidadesPorMunicipio(long muncipoiId) throws SystemException
 9    {
10        List<Localidade> alllocali=localidadePersistence.findByConcello(muncipoiId);
11        return alllocali;
12    }
13}


1
206:13:06,718 ERROR [JSONServiceAction:471] No method found for class class database.service.ConcellosServiceUtil, method getConcellos, and parameters
306:13:06,720 ERROR [JSONServiceAction:471] No method found for class class database.service.LocalidadeServiceUtil, method localidadesPorMunicipio, and parameters municipioId


Pls..Let me know..What i left..
Priyanka Dhingra
RE: Dependent Combo Box
June 27, 2012 12:32 AM
Answer

Priyanka Dhingra

Rank: Liferay Master

Posts: 501

Join Date: December 19, 2011

Recent Posts

Hi,
check this out...if it helps you
http://www.liferay.com/community/forums/-/message_boards/message/14575500
Priyanka Dhingra
RE: Dependent Combo Box
July 15, 2012 12:25 PM
Answer

Priyanka Dhingra

Rank: Liferay Master

Posts: 501

Join Date: December 19, 2011

Recent Posts

Hi,
If still there are some doubts, follow the following link
http://michi-path.blogspot.in/2012/07/three-dynamic-dropdowns-in-liferay.html
Bhavik Kama
RE: Dependent Combo Box
October 8, 2012 11:48 PM
Answer

Bhavik Kama

Rank: Junior Member

Posts: 55

Join Date: September 23, 2012

Recent Posts

Can any one guide me about this this drop down list box not showing value fetched from database..here goes my problem link..http://www.liferay.com/community/forums/-/message_boards/message/16983953