We recently migrated our application from spring 3.0.5 to spring 4.1.3 version. In previous version our form rendered without any issues even if we have '[]' (brackets for a map attribute) in the path name. But in spring 4.1.3 we are getting the following exception.
=============================================================
[4/8/15 16:25:30:639 EDT] 0000003c SystemOut O**** start currentCarrier ...23955 _ BCC - obsolete
[4/8/15 16:25:30:657 EDT] 0000003c SystemOut O *** start currentCarrierList ...1
[4/8/15 16:25:30:667 EDT] 0000003c OptionsTag E org.springframework.web.servlet.tags.RequestContextAwareTag doStartTag null
java.lang.NullPointerException
at org.springframework.validation.AbstractPropertyBindingResult.findEditor(AbstractPropertyBindingResult.java:160)
at org.springframework.web.servlet.support.BindStatus.findEditor(BindStatus.java:326)
at org.springframework.web.servlet.tags.form.OptionWriter.getDisplayString(OptionWriter.java:246)
at org.springframework.web.servlet.tags.form.OptionWriter.renderOption(OptionWriter.java:223)
at org.springframework.web.servlet.tags.form.OptionWriter.doRenderFromCollection(OptionWriter.java:211)
at org.springframework.web.servlet.tags.form.OptionWriter.renderFromCollection(OptionWriter.java:180)
at org.springframework.web.servlet.tags.form.OptionWriter.writeOptions(OptionWriter.java:133)
at org.springframework.web.servlet.tags.form.OptionsTag.writeTagContent(OptionsTag.java:157)
at org.springframework.web.servlet.tags.form.AbstractFormTag.doStartTagInternal(AbstractFormTag.java:84)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:80)
at com.ibm._jsp._multiple_2D_quote_2D_experience_2D_inputs._jspx_meth_form_options_0(_multiple_2D_quote_2D_experience_2D_inputs.java:1654)
at
====================================================
CurrentCarrier.java
===================
public class CurrentCarrier implements Serializable{
private String currentCarrier = "";
private long currentCarrierRefId = 0;
// and all setter and getter methods
}
public class MultipleQuoteInputsForm {
private Map currentCarrierMap = new HashMap();
public Object getCurrentCarrierMap(Object key) {
return currentCarrierMap.get(key);
}
public Object setCurrentCarrierMap(Object key, Object value) {
return currentCarrierMap.put(key, value);
}
public Map getCurrentCarrierMap() {
return currentCarrierMap;
}
void setCurrentCarrierMap(Map currentCarrierMap) {
this.currentCarrierMap = currentCarrierMap;
}
}
MyJsp.jsp:
=========
<form:form action="/saveMultipleQuoteInputs.sp" name="MultipleQuoteInputsForm" commandName="multipleQuoteInputsForm" id="MultipleQuoteInputsForm">
<form:select path="currentCarrierMap['23456']"> // here the exception becuase of '[]' in path
<form:options items="${currentCarrierList}" itemLabel="currentCarrier" itemValue="currentCarrierRefId"/>
</form:select>
</form:form>
MyAction Class :
====================
@RequestMapping(value = "/quote/showMultipleQuoteInputsPage.sp", method = {
RequestMethod.POST, RequestMethod.GET })
public ModelAndView execute(
@ModelAttribute("multipleQuoteInputsForm") MultipleQuoteInputsForm multipleQuoteInputsForm,
HttpServletRequest request, HttpServletResponse response) {
multipleQuoteInputsForm.setCurrentCarrierMap("23456", "9999");
List currentCarrierList = referenceTableService.getCurrentCarrier();
multipleQuoteInputsForm.setCurrentCarrierList(currentCarrierList);
return new ModelAndView("/quote/jsp/MyJsp.jsp",
Constants.MESSAGE_UTILITY, messageUtility);
}
I am able to print the ${currentCarrierList} object values using system.out before start of tag.
If i remove '[]' from path the page is rendering, but not selecting the correct select box option.
working but not retaining the selected value
============================================
<form:select path="currentCarrierMap">
<form:options items="${currentCarrierList}" itemLabel="currentCarrier" itemValue="currentCarrierRefId"/>
</form:select>
Not working (because of [] in path). This worked in spring 3.0.5:
=====================================
<form:select path="currentCarrierMap['23456']">
<form:options items="${multipleQuoteInputsForm.currentCarrierList}" itemLabel="currentCarrier" itemValue="currentCarrierRefId" />
</form:select>
When I debug the source code of spring, i see the following difference in BeanWrapper class.
PropertyTokenHolder tokens = getPropertyNameTokens(finalPath);
PropertyDescriptor pd = nestedBw.getCachedIntrospectionResults().getPropertyDescriptor(tokens.actualName);
if (pd != null) {
if (tokens.keys != null) {
if (pd.getReadMethod() != null || pd.getWriteMethod() != null) {
return TypeDescriptor.nested(property(pd), tokens.keys.length);
}
}
}
Don't know how to handle the 'tokens.keys'. I need to have my path in 'xxx[1234]' format. I tried different ways but none of them working.
Please help me. !!!!
Ok. Now I found the solution for this issue. After changing my form attribute to use Generics, solves the issue.
public class MultipleQuoteInputsForm {
private Map<String,String> currentCarrierMap = new HashMap<String,String>();
public Map<String,String> getCurrentCarrierMap(Object key) {
return currentCarrierMap.get(key);
}
public String setCurrentCarrierMap(Object key, Object value) {
return currentCarrierMap.put(key, value);
}
public Map<String,String> getCurrentCarrierMap() {
return currentCarrierMap;
}
void setCurrentCarrierMap(Map<String,String> currentCarrierMap) {
this.currentCarrierMap = currentCarrierMap;
}
}
Now my page is rendering without any issue even if we have '[]' in path attribute.
Aucun commentaire:
Enregistrer un commentaire