DhtmlxCombo : Form integration with struts2

Hi,
I have started implementing dhtmlxcombo with struts2. Earlier I had the <s:select> combos which were working based on the auto-wiring mechanism that struts provide. Now I am converting them into dhtmlxcombo using the initialization method dhtmlXComboFromSelect. The combo initialization works perfect and I can see the combos loaded on the UI. I have chosen the opt_type=“checkbox” to allow multiple selection. Here’s the point where I am stuck and seeking answers:

Q1. When the combo is loaded using dhtmlXComboFromSelect, the first element is visible in the combo. I do not want any value visible when the combo loads. I need an empty box and on click the drop down should be visible with all the combo values. This is the same behavior when the combo is initialized using new dhtmlXCombo(). How shall I achieve this?

Q2. Is there any way that the values selected on the combos are auto-wired to the action attributes as it does in struts 2?

Q3. How shall I do the form integration in case of opt_type=“checkbox”. How do I retrieve all the values in my action class when the form is submitted?

Q4. How does a normal single select dhtmlxcombo work in terms of form integration?

Q5. Is there any sample which involves struts2 integration with dhtmlxcombo?

Any help on this is highly appreciated.

Thanks,
Sunil

his is the same behavior when the combo is initialized using new dhtmlXCombo(). How shall I achieve this?

Problem confirmed.
Fix will be released as part of next update, please inform if you need it ASAP

there any way that the values selected on the combos are auto-wired to the action attributes
Not quite sure what do you mean - but when initialized from select control , combo will take initial value from the source select and will use select’s name for data sending - so any functionality which works for native select can be used with combo as well.

How shall I do the form integration in case of opt_type=“checkbox”
Values of checkboxes accessible only through API, combo will not serialize them to the form

How does a normal single select dhtmlxcombo work in terms of form integration?
Each time when combo selection changes, the input with defined name ( name of select used, in case of select-to-combo conversion ) set with new combo value.

Is there any sample which involves struts2 integration with dhtmlxcombo?
Unfortunately we have not any special samples for struts2

Hi,
Firstly thanks for the reply…I have put in my comments inline starting with [Sunil]…

his is the same behavior when the combo is initialized using new dhtmlXCombo(). How shall I achieve this?

Problem confirmed.
Fix will be released as part of next update, please inform if you need it ASAP
[Sunil] Yes I need it for my current implementation. Can you please help me in this?

there any way that the values selected on the combos are auto-wired to the action attributes
Not quite sure what do you mean - but when initialized from select control , combo will take initial value from the source select and will use select’s name for data sending - so any functionality which works for native select can be used with combo as well.
[Sunil] Struts 2 has the feature of autowiring the object from JSP to action classes. So if I have a select with name “broker” on the JSP, I need not pass it as request parameters to my action class. Neither do I have to declare any hidden variables on the JSP. I just need to create class variable with its getters and setters in my action class and the values are propagated automatically. This functionality, however is not working after the introduction of dhtmlxcombo. Hence I have to declare the for the all the selects that I had on my page and then call the following javascript method like this to get the values in my action class:
function getMultipleSelectedComboValues(){
if(brokerCombo.getChecked().length > 0) {
document.getElementById(“broker”).value = brokerCombo.getChecked();
}
if(secTypeCombo.getChecked().length > 0) {
document.getElementById(“secType”).value = secTypeCombo.getChecked();
}
if(bbYellowKeyCombo.getChecked().length > 0) {
document.getElementById(“bbYellowKey”).value = bbYellowKeyCombo.getChecked();
}
if(mtgeTickerCombo.getChecked().length > 0) {
document.getElementById(“mtgeTicker”).value = mtgeTickerCombo.getChecked();
}
Please suggest if there is any other suitable way to do this?

How shall I do the form integration in case of opt_type=“checkbox”
Values of checkboxes accessible only through API, combo will not serialize them to the form
[Sunil]Through API you mean the getChecked() method of the combo?

How does a normal single select dhtmlxcombo work in terms of form integration?
Each time when combo selection changes, the input with defined name ( name of select used, in case of select-to-combo conversion ) set with new combo value.

Is there any sample which involves struts2 integration with dhtmlxcombo?
Unfortunately we have not any special samples for struts2

Attached

[Sunil] Struts 2 has the feature of autowiring the object from JSP to action classes.

If you are using combo with checkboxes - yes you will need to use custom code and hidden inputs. Native form integration will work only for default combo use-case ( singleselection )

The next code can be used as part of combo, but I’m not quite sure , that it will work as necesary in your case

combo.attachEvent("onChange", function(){ this.DOMelem_hidden_input.value = this.getChecked(); });

[Sunil]Through API you mean the getChecked() method of the combo?

Yes
dhtmlxcombo_su.zip (9.7 KB)

Hi,
The js that you sent didn’t work. It was complaining about _isChrome variable and many other such issues. Hence I compared the changes and took relevant changes related to the issue. Thank you for the same.

The code that you mentioned didn’t work in my case:
combo.attachEvent(“onChange”, function(){
this.DOMelem_hidden_input.value = this.getChecked();
});
I am continuing with the hidden input approach. However one thing that I noticed was that when the form is submitted, I see a blank value appended along with the options selected. For Eg: if I select opt1 and opt2 from combo, the method getChecked() gives me the correct values viz. opt1,opt2. However when the form is submitted, the values received on the server are ,opt1,opt2. If you notice there is an extra blank value. I had to do extra handling for this. Can you figure out what might be the issue? Is it dhtmlxcombo or struts autowiring issue?
The same thing happens with the single select combo. Eg: op1 => op1,

I have another issue related to the combo values. How shall i set the values back to the combos. I have a search implementation where the user is allowed to save his search criteria. Now when the user loads his saved search, how shall I get the combos reflect the values from saved search as pre-selected.

Lastly, I have a validation js where i am validating the inputs received from the these combos. The multi-select combos are working fine. I am doing something like this below:
var brokerVal = form.elements[‘broker’].value; // broker is the hidden input for multi-select
However this doesn’t work for single select combos. This isn’t accessible unless I declare a hidden input for this combo. They aren’t even accessible through document.getElementById().
Below code has spMin as single select combo.
var spMinVal = form.elements[‘spMin’].value;
Once I declare the hidden input for this I get the spMinVal always a blank value. Then I thought of assigning the value explicitly to it by doing
if(spMinCombo.getSelectedText().length > 0) {
document.getElementById(“spMin”).value = spMinCombo.getSelectedText();
}
I am able to get the value in validation js. However this gives me duplicate values in my action class i.e. op1,op1
Please suggest…