You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ofbiz.apache.org by "G.Ben" <g....@gmail.com> on 2012/07/18 17:38:14 UTC

Errors with JAava code in OFBiz

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&lt;String,Object>>) parsed).iterator();
			while (((java.util.Iterator<Map&lt;String, Object>>)
parsedItr).hasNext()) {
			Map record = (Map)((java.util.Iterator<Map&lt;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.

Re: Errors with JAava code in OFBiz

Posted by "G.Ben" <g....@gmail.com>.
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.

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635036.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Errors with JAava code in OFBiz

Posted by Prabhakar Pandey <ng...@gmail.com>.
Hello,
have you added the corresponding folder into src ?


On Wed, Jul 18, 2012 at 9:08 PM, G.Ben <g....@gmail.com> 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&lt;String,Object>>) parsed).iterator();
>                         while (((java.util.Iterator<Map&lt;String,
> Object>>)
> parsedItr).hasNext()) {
>                         Map record =
> (Map)((java.util.Iterator<Map&lt;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.
>

Re: Errors with JAava code in OFBiz

Posted by devalpatel <de...@netweb.biz>.
Hello ,

hey i  have tried the exact code and works correctly.. 

if u have skype can be plz online,,,, i want to see the location where u got
the errors.... my skype id is "npatde11" 



Thanks,
Deval


--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635037.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Errors with JAava code in OFBiz

Posted by "G.Ben" <g....@gmail.com>.
Hi Again,

Thanks so much, i was struggling with the import ...
I did the build and it worked perfectly 
Thank you so much.

Regards.

G.Ben.

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635039.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Errors with JAava code in OFBiz

Posted by devalpatel <de...@netweb.biz>.
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

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635038.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Errors with JAava code in OFBiz

Posted by "G.Ben" <g....@gmail.com>.
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.

--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635035.html
Sent from the OFBiz - User mailing list archive at Nabble.com.

Re: Errors with JAava code in OFBiz

Posted by devalpatel <de...@netweb.biz>.
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


--
View this message in context: http://ofbiz.135035.n4.nabble.com/Errors-with-JAava-code-in-OFBiz-tp4635012p4635027.html
Sent from the OFBiz - User mailing list archive at Nabble.com.