Sorry,

I said:

Hi, use the old style "selected" in the prefered option tag (a simple test value should work) - i use the related objects in form as option id="entity[Related.id]" and validate with customs validator.

I must said

Hi, use the old style "selected" in the prefered option tag (a simple test value should work) - i use the related objects in form as select id="entity[Related.id]" and validate with a custom validator.

Hope helps.

Hope helps.


Leo Barrientos C. schrieb:
Hi, use the old style "selected" in the prefered option tag (a simple test value should work) - i use the related objects in form as option id="entity[Related.id]" and validate with customs validator.

Hope helps.



MHL schrieb:
Hi all

I am very new to spring MVC and I am having a problem. I have a drop down list in my web form. i am able to create a new entry without any problem.
but when I try to update the value of the form, it doesn't selected the
value from the drop down list.( this is very annoying, so I have to choose
the value again for the drop down list every time).

I have tried to find out what cause it and I couldn't find out why.

here is my code.

in the BidFormController.java
protected Map<String, List<Operator>> referenceData(HttpServletRequest
request){
    List<Operator> list = operatorManager.getAll();
Map<String, List<Operator>> map = new HashMap<String, List<Operator>>();
    map.put("operators", list);
    return map;
}

protected Object formBackingObject(HttpServletRequest request)throws
Exception {
    String id = request.getParameter("id");
    if (id != null && request.getMethod().equalsIgnoreCase("get")){
        Bid bid = bidManager.get(new Long(id));
        return bid;
    }
    return new Bid();
}


public void initBinder(HttpServletRequest request, ServletRequestDataBinder
binder){
    //super.initBinder(request, binder);
    StringToObjectCustomEditor propertyEditor = new
StringToObjectCustomEditor();
    propertyEditor.setGenreicManager(operatorManager);
    binder.registerCustomEditor(Operator.class, propertyEditor);
}

in bidForm.jsp

<form:select path="operator">
    <form:option value="" label="--Please Select" />
    <form:options items="${operators}" itemValue="id" itemLabel="name"/>
</form:select>


in StringToObjectCustomEditor.java

/**
* this class is mainly converting the string(the ID in the string form) to
Object
 * the Object must extends the #link{TanBaseObject}.
 *  */
import java.beans.PropertyEditorSupport;
import com.tantalus.app.model.bid.TanBaseObject;
import com.tantalus.app.service.GenericManager;

/**
 * this class can only convert Object that extends TanBaseObject
 * @author ben.li
 *
 */
public class StringToObjectCustomEditor extends PropertyEditorSupport {


    @SuppressWarnings("unchecked")
    private GenericManager genericManager = null;
    @SuppressWarnings("unchecked")
    public GenericManager getGenericManager(){
        if (genericManager == null ) {
            throw new RuntimeException("Didn't set GenericManager");
        }
        return genericManager;
    }
@SuppressWarnings("unchecked")
    public void setGenreicManager(GenericManager genericManager){
        this.genericManager = genericManager;
    }
    @SuppressWarnings("unchecked")
    public void setAsText(String text){
        if ("".equals(text)){
            setValue(null);
        }else {
            setValue(genericManager.get(new Long(text)));
        }
    }
    public String getAsText(){
        TanBaseObject to = (TanBaseObject) getValue();
        if (to == null || to.getId() == null){
            return null;
        }else {
            TanBaseObject operator = (TanBaseObject) getValue();
            return "" + operator.getId();
        }
    }
    @SuppressWarnings("unchecked")
    protected Object convertElement(Object element){
if ( element != null){
            Long id = new Long((String)element);
TanBaseObject object = (TanBaseObject) genericManager.get(id);
            return object;
        }
        return null;
    }
}

Can someone please help me which part I did wrong?


Thanks in advance.





---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to