Hi All,
i've been following a tutoriel and once entered this Java Code public static String processMultiForm (HttpServletRequest request, HttpServletResponse response){ Collection parsed = UtilHttp.parseMultiFormData (UtilHttp.getParameterMap(request)); List combined = new ArrayList(); Iterator parsedItr = parsed.iterator(); while (parsedItr.hasNext()) { Map record = (Map)parsedItr.next(); combined.add(record.get("firstName") + " " + record.get("lastName")); } request.setAttribute("combined", combined); request.setAttribute("allParams", UtilHttp.getParameterMap(request)); request.setAttribute("submit", "Submitted"); return "success"; } with Eclipse IDE, it helped to recognise errors (about cast), I correct them, public static String processMultiForm (HttpServletRequest request, HttpServletResponse response){ Collection parsed = (Collection) UtilHttp.parseMultiFormData (UtilHttp.getParameterMap(request)); List combined = (List) new ArrayList(); Iterator parsedItr = (Iterator) ((java.util.Collection<Map<String,Object>>) parsed).iterator(); while (((java.util.Iterator<Map<String, Object>>) parsedItr).hasNext()) { Map record = (Map)((java.util.Iterator<Map<String, Object>>) parsedItr).next(); combined.add(record.get("firstName") + " " + record.get("lastName")); } request.setAttribute("combined", combined); request.setAttribute("allParams", UtilHttp.getParameterMap(request)); request.setAttribute("submit", "Submitted"); return "success"; } however errors still remain. Please can anyone give me the correct code that I should put Thank you so much for your help. Regards. |
Hello ,
Ur code is correct and it works perfectly.. I didnt get any error while using ur code in ofBiz. Have u imported import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.ofbiz.base.util.UtilHttp; The above 3 are required for ur method's code. If still not work copy paste ur full java class here.... Tell me ur JDK version. and ofBiz version ?? Regards, Deval |
In reply to this post by G.Ben
Hello,
have you added the corresponding folder into src ? On Wed, Jul 18, 2012 at 9:08 PM, G.Ben <[hidden email]> wrote: > Hi All, > > i've been following a tutoriel and once entered this Java Code > public static String processMultiForm (HttpServletRequest request, > HttpServletResponse response){ > Collection parsed = UtilHttp.parseMultiFormData > (UtilHttp.getParameterMap(request)); > List combined = new ArrayList(); > Iterator parsedItr = parsed.iterator(); > while (parsedItr.hasNext()) { > Map record = (Map)parsedItr.next(); > combined.add(record.get("firstName") + " " + > record.get("lastName")); > } > request.setAttribute("combined", combined); > request.setAttribute("allParams", > UtilHttp.getParameterMap(request)); > request.setAttribute("submit", "Submitted"); > return "success"; > } > > with Eclipse IDE, it helped to recognise errors (about cast), I correct > them, > public static String processMultiForm (HttpServletRequest request, > HttpServletResponse response){ > Collection parsed = (Collection) > UtilHttp.parseMultiFormData > (UtilHttp.getParameterMap(request)); > List combined = (List) new ArrayList(); > Iterator parsedItr = (Iterator) > ((java.util.Collection<Map<String,Object>>) parsed).iterator(); > while (((java.util.Iterator<Map<String, > Object>>) > parsedItr).hasNext()) { > Map record = > (Map)((java.util.Iterator<Map<String, Object>>) > parsedItr).next(); > combined.add(record.get("firstName") + " " + > record.get("lastName")); > } > request.setAttribute("combined", combined); > request.setAttribute("allParams", > UtilHttp.getParameterMap(request)); > request.setAttribute("submit", "Submitted"); > return "success"; > } > however errors still remain. > Please can anyone give me the correct code that I should put > > Thank you so much for your help. > > Regards. > > -- > View this message in context: > http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > |
In reply to this post by devalpatel
Hello devalpatel,
Thank you for your help, I've already added the import. Actually I'm working with JDK 1.6 & OFBiz 12.04 And here is the full java class code : package org.ofbiz.learning.learning; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.party.contact.ContactMechWorker; public class LearningEvents { public static String postalAddressAdvisory(HttpServletRequest request, HttpServletResponse response) { String partyId = request.getParameter("partyId"); Map mechMap = new HashMap(); ContactMechWorker.getContactMechAndRelated(request, partyId, mechMap); Map postalAddress = (Map)mechMap.get("postalAddress"); if (postalAddress == null) return "notMars"; String planet = (String)postalAddress.get("planet"); if (planet == null || !planet.equalsIgnoreCase("Mars")) return "notMars"; return "isMars"; } public static String processFirstForm(HttpServletRequest request, HttpServletResponse response){ String firstName = request.getParameter("firstName"); String lastName = request.getParameter("lastName"); request.setAttribute("combined", firstName + " " + lastName); request.setAttribute("allParams", UtilHttp.getParameterMap(request)); request.setAttribute("submit", "Submitted"); return "success"; } public static String processMultiForm (HttpServletRequest request, HttpServletResponse response){ Collection parsed = UtilHttp.parseMultiFormData (UtilHttp.getParameterMap(request)); List combined = new ArrayList(); Iterator parsedItr = parsed.iterator(); while (parsedItr.hasNext()) { Map record = (Map)parsedItr.next(); combined.add(record.get("firstName") + " " + record.get("lastName")); } request.setAttribute("combined", combined); request.setAttribute("allParams", UtilHttp.getParameterMap(request)); request.setAttribute("submit", "Submitted"); return "success"; } } I appreciate your help so much. Regards. |
In reply to this post by Prabhakar Pandey
Hello Prabhakar Pandey,
excuse me but I don't think that I've understood what you meant, I've already been working with same file in the method "processFirstForm" and it did work, when trying to work with "processMultiForm" there are errors there. Thank you for your help. Regards. |
In reply to this post by G.Ben
Hello Madam,
Just replace your import with below : import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.ofbiz.base.util.UtilHttp; import org.ofbiz.party.contact.ContactMechWorker; And, it will resolve the errors. Regards, Deval |
Free forum by Nabble | Edit this page |