PDA

View Full Version : need some help with multiselect list box to bind.


nismi
May 31st, 2006, 05:44 PM
hi guys,

iam new to this all spring framework, please help me out here.

i have 4 html elements called metals, operator, number, metalcriteria

metals and metalcriteria are multi select list box.
operator is single drop down list box.

when you select metal(s), and operator, and enter value and click add button my java script adds all togeter as option to metalcriteria.

ex:-

metal operator number metalcriteria
FE < 10 FE<10
Pb >= 20 Pb>=20

now here is where iam stuk.

i need to bind metalcriteria to command object and get all its options one by one and split in to metals. operator, and number.

i asked this question mistakely in springwebflow forums and they said i need to register CustomCollectionEditor and overwrite convertElement(Object element) but iam still not getting.

here is my code

jsp:-
-----
<table border="0">
<tr>
<td colspan="4"></td>
<td align="left"><label class="textStyle"><fmt:message key="label.tab.oap.searchby"/></label></td>
</tr>
<tr>
<spring:bind path="queryCriteria.oapQueryCriteria.wearMetalCriteria">
<td valign="top">
<select id="metals" name="${status.expression}" size="5" multiple>
<c:forEach items="${metals}" var="metal">
<option>${metal.code}</option>
</c:forEach>
<c:set var="metal" value="${status.expression}"/>
</select>
</td>
</spring:bind>

<td valign="top">
<select name="operation">
<option>></option>
<option><</option>
<option>>=</option>
<option><=</option>
<option>=</option>
<option><></option>
</select>
</td>

<td valign="top"><input type="text" name="number" value="" size="5"\></td>

<td valign="bottom">
<table>
<tr><td valign="bottom"><input type="button" name="add" value=">>" onClick="addSearchCriteria(this.form);"></td></tr>
<tr><td valign="bottom"><input type="button" name="remove" value="<<" onClick="removeSearchCriteria(this.form);"></td></tr>
</table>
</td>
<spring:bind path="queryCriteria.oapQueryCriteria.wearMetalSearchQuer yCriteria">
<td valign="top">
<select id="searchBy" name="${status.expression}" multiple size="5" style="width:300px"> </select>
</td>

</tr>
<tr>
<td>
<c:forEach items="${status.errorMessages}" var="message">
<span style="color:red;">Error: ${message}</span>
</c:forEach>
</td>
</tr>
</spring:bind>

java:-
-------
public class OapQueryCriteriaForm {

private int flightCount;
private java.util.Date sampleFrom;
private java.util.Date sampleTo;
private java.util.Date sampleBurnFrom;
private java.util.Date sampleBurnTo;
private java.util.Collection<OilType> oilTypes;
private java.util.Collection<WearMetalSearchQueryCriteria> wearMetalSearchQueryCriteria;
private List wearMetalCriteria;

getters and setters...........


in my controller:-
------------------

public class SearchDataFilesController extends AbstractWizardFormController {


-------------some code------------

binder.registerCustomEditor(Set.class, "oapQueryCriteria.wearMetalSearchQueryCriteria", new CustomCollectionEditor(Set.class) {
protected Object convertElement(Object element) {
if(element == null)
{
log.debug("id for wearMetalSearchQueryCriteria is null");
}
else
{
log.debug("id for wearMetalSearchQueryCriteria is not null");
}
if (element != null) {
Long id = new Long((String)element);
log.debug("id for wearMetalSearchQueryCriteria is " + id);

return null;
}
return null;
}
});



right now in my code iam just trying to see if i am getting all option or not,
but doesn't matter how many option i select its not doing anything

my java script works fine and it adds options and iam able to select option when submitting its not giving any exception but also no results, seems it not even recognising as list of strings


any help pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee

thank you in advance for helping me.
nismi.

neerajn
May 31st, 2006, 06:13 PM
Can you show the part of the code where you set the command object? Or please post the code of the formBackingObject(HttpServletRequest request) method.

nismi
May 31st, 2006, 06:36 PM
hi neerajn,

we don't have any formBackingObject method, here is my controller code

protected void initBinder(HttpServletRequest request,
ServletRequestDataBinder binder) throws Exception {
super.initBinder(request, binder);

binder.registerCustomEditor(Set.class, "oapQueryCriteria.wearMetalSearchQueryCriteria", new CustomCollectionEditor(Set.class) {
protected Object convertElement(Object element) {
if(element == null)
{
log.debug("id for wearMetalSearchQueryCriteria is null");
}
else
{
log.debug("id for wearMetalSearchQueryCriteria is not null");
}
if (element != null) {
Long id = new Long((String)element);
log.debug("id for wearMetalSearchQueryCriteria is " + id);

return null;
}
return null;
}
});

}

thats all i have,

as i told before iam not yet setting to anything from metalcriteria but i want to be able to see if its binding properly and getting all options or not and even that is not working i want to know where iam doing wrong.

but here is my wearMetalSearchQueryCriteria class which i want to set to from html select element.

public class WearMetalSearchQueryCriteria {

private int unitNumber;
private String operator;
private String metal;

public WearMetalSearchQueryCriteria(){

}

public String getMetal() {
return metal;
}
public void setMetal(String metal) {
this.metal = metal;
}
public String getOperator() {
return operator;
}
public void setOperator(String operator) {
this.operator = operator;
}
public int getUnitNumber() {
return unitNumber;
}
public void setUnitNumber(int unitNumber) {
this.unitNumber = unitNumber;
}


}

nismi
May 31st, 2006, 06:39 PM
Hi neerajn,

do u know how to bing it to multiselect list box and be able to read all the options from the controller, once i get that part working i can probably figure out way to split it. do u have any code related to it or correct me in my code pleaseeeeeeeeeeeeee

thank you any way, for replying my post. at least you have spent some time looking at my post.

neerajn
May 31st, 2006, 07:22 PM
The discrepancy I see is in the spring bind tags which bind to "queryCriteria.oapQueryCriteria.wearMetalCriteria". I dont see the queryCriteria object anywhere. Only the oapQueryCriteria from your example. If the queryCriteria is not used, you should remove it and it should bind correctly.