Dear all,
Could you tell me how to pass a Map's parameter from ftl to java? When in ftl, the parameter has data. But when I call it in java's method by this code below, I got null value: Map<String, Object> jPrm = (Map<String, Object>)request.getAttribute("jrParameters"); JRDataSource jrDataSource = (JRDataSource) request.getAttribute("jrDataSource"); In this case, I want to pass jrParameter and jrDatasource to make a report. Please, help me... Thanks. |
in ofbiz you pass the ftl thru the controller to a request-map
if you need to process the data then you can all a service or event. if you use a service then the data is availible as a context. if you use an event it is availible thru the httprequest. otherwise you can direct to another page through a view that would be your report. if your using widgets you can process data in the action section then define the ftl that will show the report. ofbiz takes care of passing the information. review http://docs.ofbiz.org/display/OFBIZ/OFBiz+Beginner%27s+Development+Guide+Using+Practice+Application. Hari Plaikoil sent the following on 12/2/2008 3:15 AM: > Dear all, > > Could you tell me how to pass a Map's parameter from ftl to java? > > When in ftl, the parameter has data. But when I call it in java's method by > this code below, I got null value: > > Map<String, Object> jPrm = (Map<String, > Object>)request.getAttribute("jrParameters"); > JRDataSource jrDataSource = (JRDataSource) > request.getAttribute("jrDataSource"); > > In this case, I want to pass jrParameter and jrDatasource to make a report. > > Please, help me... > > Thanks. |
I followed your instruction. First, I've got the jrParameters (Map's type) and jrDataSource (JRDataSource's type) as output parameters from java service. Second, I catch the parameters on .bsh file, I put the parameters on context than I pass to .ftl
Third, on .ftl, I've checked both of the parameters, they have the same data like in .bsh file. Fourth, I called java's event from .ftl through controller. On the java's event I realized the value of jrParameters and jrDataSource are null. I really don't have any idea how to set fields or parameters for both of them on .ftl so when I catch on java's event the value will not null. I tried on .ftl assign the parameters like the code below: <@inputHidden name="jrParameters" value="${jrParameters}"/> <@inputHidden name="jrDataSource" value="${jrDataSource}"/> the code causes error exception, so I changed to : <#assign jrParameters = "${jrParameters}"> <#assign jrDataSource = "${jrDataSource}"> again, it causes an error exception too Please, help me out.... Thanks.
|
Why are you waiting until you get to the template? Wouldn't it be easier to
call the method from the bsh script? Regards Scott 2008/12/3 Hari Plaikoil <[hidden email]> > > I followed your instruction. First, I've got the jrParameters (Map's type) > and jrDataSource (JRDataSource's type) as output parameters from java > service. Second, I catch the parameters on .bsh file, I put the parameters > on context than I pass to .ftl > Third, on .ftl, I've checked both of the parameters, they have the same > data > like in .bsh file. > Fourth, I called java's event from .ftl through controller. On the java's > event I realized the value of jrParameters and jrDataSource are null. > > I really don't have any idea how to set fields or parameters for both of > them on .ftl so when I catch on java's event the value will not null. I > tried on .ftl assign the parameters like the code below: > > <@inputHidden name="jrParameters" value="${jrParameters}"/> > <@inputHidden name="jrDataSource" value="${jrDataSource}"/> > > the code causes error exception, so I changed to : > > <#assign jrParameters = "${jrParameters}"> > <#assign jrDataSource = "${jrDataSource}"> > > again, it causes an error exception too :-(( > > Please, help me out.... > > Thanks. > > > BJ Freeman wrote: > > > > in ofbiz you pass the ftl thru the controller to a request-map > > if you need to process the data then you can all a service or event. > > if you use a service then the data is availible as a context. > > if you use an event it is availible thru the httprequest. > > otherwise you can direct to another page through a view that would be > > your report. > > if your using widgets you can process data in the action section then > > define the ftl that will show the report. > > > > ofbiz takes care of passing the information. > > > > review > > > http://docs.ofbiz.org/display/OFBIZ/OFBiz+Beginner%27s+Development+Guide+Using+Practice+Application > . > > > > > > > > Hari Plaikoil sent the following on 12/2/2008 3:15 AM: > >> Dear all, > >> > >> Could you tell me how to pass a Map's parameter from ftl to java? > >> > >> When in ftl, the parameter has data. But when I call it in java's method > >> by > >> this code below, I got null value: > >> > >> Map<String, Object> jPrm = (Map<String, > >> Object>)request.getAttribute("jrParameters"); > >> JRDataSource jrDataSource = (JRDataSource) > >> request.getAttribute("jrDataSource"); > >> > >> In this case, I want to pass jrParameter and jrDatasource to make a > >> report. > >> > >> Please, help me... > >> > >> Thanks. > > > > > > -- > View this message in context: > http://www.nabble.com/passing-map-parameter-from-ftl-to-event-type-java-tp20790183p20805691.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > > |
I need to go to .ftl after visit the .bsh because I have to choose an printer name, report type for my other parameters for the java's event. and the choices are in .ftl (drop-down)
you can say I take a long path just to make a pdf's report frankly, I don't know how to explain that. So, would you like to help me how to pass the parameters (Map's type & JRDataSource's type) from .ftl to java's event? Anyway, I write piece of code on java's event to catch the parameters like this : Map<String, Object> jPrm = (Map)request.getAttribute("jrParameters"); JRDataSource jrDataSource = (JRDataSource) request.getAttribute("jrDataSource"); but, the variables give me null value
|
Ah ok, so you mean that you have a form generated from an ftl and when that
form is submitted you can't get the parameters using request.getAttribute ("jrParameters")? Try using request.getParameter("jrParameters"). Usually when people talk about trying to do things from ftl they are talking about while rendering the template. Regards Scott 2008/12/3 Hari Plaikoil <[hidden email]> > > I need to go to .ftl after visit the .bsh because I have to choose an > printer > name, report type for my other parameters for the java's event. and the > choices are in .ftl (drop-down) :-D > > you can say I take a long path just to make a pdf's report :-D frankly, I > don't know how to explain that. > > So, would you like to help me how to pass the parameters (Map's type & > JRDataSource's type) from .ftl to java's event? > > Anyway, I write piece of code on java's event to catch the parameters like > this : > > Map<String, Object> jPrm = > (Map)request.getAttribute("jrParameters"); > JRDataSource jrDataSource = (JRDataSource) > request.getAttribute("jrDataSource"); > > but, the variables give me null value :-(( > > > > Scott Gray wrote: > > > > Why are you waiting until you get to the template? Wouldn't it be easier > > to > > call the method from the bsh script? > > Regards > > Scott > > > > 2008/12/3 Hari Plaikoil <[hidden email]> > > > >> > >> I followed your instruction. First, I've got the jrParameters (Map's > >> type) > >> and jrDataSource (JRDataSource's type) as output parameters from java > >> service. Second, I catch the parameters on .bsh file, I put the > >> parameters > >> on context than I pass to .ftl > >> Third, on .ftl, I've checked both of the parameters, they have the same > >> data > >> like in .bsh file. > >> Fourth, I called java's event from .ftl through controller. On the > java's > >> event I realized the value of jrParameters and jrDataSource are null. > >> > >> I really don't have any idea how to set fields or parameters for both > of > >> them on .ftl so when I catch on java's event the value will not null. I > >> tried on .ftl assign the parameters like the code below: > >> > >> <@inputHidden name="jrParameters" value="${jrParameters}"/> > >> <@inputHidden name="jrDataSource" value="${jrDataSource}"/> > >> > >> the code causes error exception, so I changed to : > >> > >> <#assign jrParameters = "${jrParameters}"> > >> <#assign jrDataSource = "${jrDataSource}"> > >> > >> again, it causes an error exception too :-(( > >> > >> Please, help me out.... > >> > >> Thanks. > >> > >> > >> BJ Freeman wrote: > >> > > >> > in ofbiz you pass the ftl thru the controller to a request-map > >> > if you need to process the data then you can all a service or event. > >> > if you use a service then the data is availible as a context. > >> > if you use an event it is availible thru the httprequest. > >> > otherwise you can direct to another page through a view that would be > >> > your report. > >> > if your using widgets you can process data in the action section then > >> > define the ftl that will show the report. > >> > > >> > ofbiz takes care of passing the information. > >> > > >> > review > >> > > >> > http://docs.ofbiz.org/display/OFBIZ/OFBiz+Beginner%27s+Development+Guide+Using+Practice+Application > >> . > >> > > >> > > >> > > >> > Hari Plaikoil sent the following on 12/2/2008 3:15 AM: > >> >> Dear all, > >> >> > >> >> Could you tell me how to pass a Map's parameter from ftl to java? > >> >> > >> >> When in ftl, the parameter has data. But when I call it in java's > >> method > >> >> by > >> >> this code below, I got null value: > >> >> > >> >> Map<String, Object> jPrm = (Map<String, > >> >> Object>)request.getAttribute("jrParameters"); > >> >> JRDataSource jrDataSource = (JRDataSource) > >> >> request.getAttribute("jrDataSource"); > >> >> > >> >> In this case, I want to pass jrParameter and jrDatasource to make a > >> >> report. > >> >> > >> >> Please, help me... > >> >> > >> >> Thanks. > >> > > >> > > >> > >> -- > >> View this message in context: > >> > http://www.nabble.com/passing-map-parameter-from-ftl-to-event-type-java-tp20790183p20805691.html > >> Sent from the OFBiz - User mailing list archive at Nabble.com. > >> > >> > > > > > > -- > View this message in context: > http://www.nabble.com/passing-map-parameter-from-ftl-to-event-type-java-tp20790183p20805941.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > > |
Thanks Scott for your advice.
But, I think when I use request.getParameter it will give a String value. I don't want a String, I want a Map and a JRDataSource my jrParameters is Map's type, Map<String, Object> type. I tried request.getParameter("jrParameters"), it was really impossible : Map<String, Object> jrParameters = request.getParameter("jrParameters"); <--- cannot convert from String to Map I really totally confuse with all this code
|
I tried using getParameter and getAttribute for both of the parameters. First, in .ftl I set like this :
<#assign jrP = requestAttributes.jrParameters> <@inputHidden name="jrPr" value=jrP/> <#assign jrD = requestAttributes.jrDataSource> <@inputHidden name="jrDt" value=jrD/> and then I called java event through controller, and I caught both of the parameter like this : Map<String, Object> jPrm = (Map)request.getAttribute("jrPr"); JRDataSource jrDataSource = (JRDataSource) request.getAttribute("jrDt"); Debug.logInfo("jPrm = "+jPrm, module); //gives null value Debug.logInfo("jrDataSource = "+jrDataSource, module); // gives null value Debug.logInfo("jPrm = "+request.getParameter("jrPr"), module); // gives the data Debug.logInfo("jrDataSource = "+request.getParameter("jrDt"), module); // gives the data Does anyone wanna help me to solve this problem? Thanks
|
In reply to this post by Hari Plaikoil
Hi
Sorry but, i don't understand your problem completely. But what ever i understand from your conversation with Scott, i think you want to send value through ftl file. So you try <set field="abc" from-field="parameters.abc"/> <set field="xyz" from-field="parameters.xyz"/> between screens <actions></actions> tag.
|
Hi Nalin, thanks for your response. I'll try to describe my process's path :
First, when I click a submit link, it will call java service. The output of the java service are Map and JRDataSource. (on this service, there is no problem) Second, through a .bsh file, I catch the both of the parameters and put them on context (on this .bsh there is no problem), and I pass the context to .ftl file Third, on .ftl file I catch the Map and JRDataSource which has been sent by .bsh file (on context) before. And here is the problem : I want to send (again) both of the parameters to become input parameters for a java's event. I don't know how to assign both of this parameters on ftl to become attribute. So, when I catch them on java's event by code "request.getAttribute("Map")" it will not give me null value. I don't want to send both of the parameters on .ftl by @inputHidden. All my problem is between .ftl and java's event. There is no screen widget here. That's all. I hope you have a clear view now on my problem. Thanks
|
I dont think you can do this. ftl templates generate the html fragment
and nothing else. In my opinion you have the following choices: 1. Pass these values as hidden parameters. 2. Pass them as query string to the next request. 3. Add them to session. 4. Save them somewhere in the database and retrieve in the next request. Thanks, Raj Hari Plaikoil wrote: > Hi Nalin, thanks for your response. I'll try to describe my process's path : > > First, when I click a submit link, it will call java service. The output of > the java service are Map and JRDataSource. (on this service, there is no > problem) > > Second, through a .bsh file, I catch the both of the parameters and put them > on context (on this .bsh there is no problem), and I pass the context to > .ftl file > > Third, on .ftl file I catch the Map and JRDataSource which has been sent by > .bsh file (on context) before. And here is the problem : I want to send > (again) both of the parameters to become input parameters for a java's > event. > I don't know how to assign both of this parameters on ftl to become > attribute. So, when I catch them on java's event by code > "request.getAttribute("Map")" it will not give me null value. > > I don't want to send both of the parameters on .ftl by @inputHidden. All my > problem is between .ftl and java's event. There is no screen widget here. > > That's all. I hope you have a clear view now on my problem. > > Thanks > > > nalin chandra wrote: > >> Hi >> Sorry but, i don't understand your problem completely. But what ever i >> understand from your conversation with Scott, i think you want to send >> value through ftl file. >> >> So you try >> <set field="abc" from-field="parameters.abc"/> >> <set field="xyz" from-field="parameters.xyz"/> >> between screens <actions></actions> tag. >> >> >> >> >> Hari Plaikoil wrote: >> >>> Dear all, >>> >>> Could you tell me how to pass a Map's parameter from ftl to java? >>> >>> When in ftl, the parameter has data. But when I call it in java's method >>> by this code below, I got null value: >>> >>> Map<String, Object> jPrm = (Map<String, >>> Object>)request.getAttribute("jrParameters"); >>> JRDataSource jrDataSource = (JRDataSource) >>> request.getAttribute("jrDataSource"); >>> >>> In this case, I want to pass jrParameter and jrDatasource to make a >>> report. >>> >>> Please, help me... >>> >>> Thanks. >>> >>> >> > > |
In reply to this post by Hari Plaikoil
the basic flow in ofbiz is to submit through the request-map in the
controller, then return through the request-map to a view. 1) if you mapped the JRDataSource in the service it is part off the context and or httprequest till it is removed. 2) not sure what parameters you catching in the bsh file that you can catch in the service. so they should be available to the ftl in the view you designate in the controller that is returning from the service. 3) then flt links and or submits then go through the controller again to the next or same service any data that is in the FTL is already in the context and/or httprequest your map must be cast to get it from a request find some event code in ofbiz Hari Plaikoil sent the following on 12/4/2008 7:07 PM: > Hi Nalin, thanks for your response. I'll try to describe my process's path : > > First, when I click a submit link, it will call java service. The output of > the java service are Map and JRDataSource. (on this service, there is no > problem) > > Second, through a .bsh file, I catch the both of the parameters and put them > on context (on this .bsh there is no problem), and I pass the context to > .ftl file > > Third, on .ftl file I catch the Map and JRDataSource which has been sent by > .bsh file (on context) before. And here is the problem : I want to send > (again) both of the parameters to become input parameters for a java's > event. > I don't know how to assign both of this parameters on ftl to become > attribute. So, when I catch them on java's event by code > "request.getAttribute("Map")" it will not give me null value. > > I don't want to send both of the parameters on .ftl by @inputHidden. All my > problem is between .ftl and java's event. There is no screen widget here. > > That's all. I hope you have a clear view now on my problem. > > Thanks > > > nalin chandra wrote: >> Hi >> Sorry but, i don't understand your problem completely. But what ever i >> understand from your conversation with Scott, i think you want to send >> value through ftl file. >> >> So you try >> <set field="abc" from-field="parameters.abc"/> >> <set field="xyz" from-field="parameters.xyz"/> >> between screens <actions></actions> tag. >> >> >> >> >> Hari Plaikoil wrote: >>> Dear all, >>> >>> Could you tell me how to pass a Map's parameter from ftl to java? >>> >>> When in ftl, the parameter has data. But when I call it in java's method >>> by this code below, I got null value: >>> >>> Map<String, Object> jPrm = (Map<String, >>> Object>)request.getAttribute("jrParameters"); >>> JRDataSource jrDataSource = (JRDataSource) >>> request.getAttribute("jrDataSource"); >>> >>> In this case, I want to pass jrParameter and jrDatasource to make a >>> report. >>> >>> Please, help me... >>> >>> Thanks. >>> >> > |
In reply to this post by Hari Plaikoil
Hi Hari
tou wrote.. Third, on .ftl file I catch the Map and JRDataSource which has been sent by .bsh file (on context) before. And here is the problem : I want to send (again) both of the parameters to become input parameters for a java's event. so, if you want to send the same Maps for next request then you can put the same in context in bsh and fetch in your java file where you want. in ftl file Maps handling is not so good so if you want to use the same process you first change Maps to list there are many method toList(Maps map) available in ofbiz it will easier to handle the list. In case you use the Maps in ftls it has problem because The ``hash'' type of the FreeMarker Template Language (FTL) is not the same as Java's Map. FTL's hash is an associative array too, but it uses string keys exclusively. i understand your problem but if you give me some idea about what you want to do, so may be i can suggest you alternative.
|
In reply to this post by Hari Plaikoil
Hari,
I am pretty sure that I have understood your problem. Here are few comments from my side: 1) AFAIK, you can never send a Java object other than String and Array as a (hidden) parameter from FTL. What you can send is string values and array. The reason is there are two major methods available with a request object to fetch parameters: String getParameters(String) and String[] getParameterValues(String). You can't fetch any parameter whose value is a Java Object of other types. 2) For your problem, when you catch the parameters in .bsh, instead of putting them in context try using request.setAttribute() method. 3) Now in your Java event use request.getAttribute() method and it should work. -- Thanks & Regards Mridul Pathak Hotwax Media http://www.hotwaxmedia.com [hidden email] On Fri, Dec 5, 2008 at 8:37 AM, Hari Plaikoil <[hidden email]>wrote: > > Hi Nalin, thanks for your response. I'll try to describe my process's path > : > > First, when I click a submit link, it will call java service. The output of > the java service are Map and JRDataSource. (on this service, there is no > problem) > > Second, through a .bsh file, I catch the both of the parameters and put > them > on context (on this .bsh there is no problem), and I pass the context to > .ftl file > > Third, on .ftl file I catch the Map and JRDataSource which has been sent by > .bsh file (on context) before. And here is the problem : I want to send > (again) both of the parameters to become input parameters for a java's > event. > I don't know how to assign both of this parameters on ftl to become > attribute. So, when I catch them on java's event by code > "request.getAttribute("Map")" it will not give me null value. > > I don't want to send both of the parameters on .ftl by @inputHidden. All my > problem is between .ftl and java's event. There is no screen widget here. > > That's all. I hope you have a clear view now on my problem. > > Thanks > > > nalin chandra wrote: > > > > Hi > > Sorry but, i don't understand your problem completely. But what ever i > > understand from your conversation with Scott, i think you want to send > > value through ftl file. > > > > So you try > > <set field="abc" from-field="parameters.abc"/> > > <set field="xyz" from-field="parameters.xyz"/> > > between screens <actions></actions> tag. > > > > > > > > > > Hari Plaikoil wrote: > >> > >> Dear all, > >> > >> Could you tell me how to pass a Map's parameter from ftl to java? > >> > >> When in ftl, the parameter has data. But when I call it in java's method > >> by this code below, I got null value: > >> > >> Map<String, Object> jPrm = (Map<String, > >> Object>)request.getAttribute("jrParameters"); > >> JRDataSource jrDataSource = (JRDataSource) > >> request.getAttribute("jrDataSource"); > >> > >> In this case, I want to pass jrParameter and jrDatasource to make a > >> report. > >> > >> Please, help me... > >> > >> Thanks. > >> > > > > > > -- > View this message in context: > http://www.nabble.com/passing-map-parameter-from-ftl-to-event-type-java-tp20790183p20847035.html > Sent from the OFBiz - User mailing list archive at Nabble.com. > > |
Hai Mridul,
thanks for your advice. I just tried it, but it didn't work. I guess it cannot work because the parameters that I put on request.setAttribute (as you said) called in java's event (by request.getAttribute) after .ftl page. I don't call java's event directly after I load my .bsh. But I call my .bsh, then .ftl, then java's event. So, I think the value of the parameters has lost when it reached in java's event. (Please correct me if I'm wrong)
|
Dear all,
thanks for all your support and advice on my problem. however, I think I should change my process's path to avoid this confusing problem. Thanks a lot. Best regards, Hari Plaikoil
|
In reply to this post by BJ Freeman
All,
In the very first screen widget in my application I set my global variable: <set field="childId" from from-field="parameter.childId" to-scope="user"/> How should I set it up to be certain I will never loose the content of childId? Jacek |
<set field="childId" from-field="parameter.childId" to-scope="user" global="true"/>
-Adrian --- On Wed, 12/31/08, Jacek Wagner <[hidden email]> wrote: > From: Jacek Wagner <[hidden email]> > Subject: passing parameter in ofbiz > To: [hidden email] > Date: Wednesday, December 31, 2008, 3:35 PM > All, > > In the very first screen widget in my application I set my > global variable: > > <set field="childId" from > from-field="parameter.childId" > to-scope="user"/> > > How should I set it up to be certain I will never loose the > content of childId? > > Jacek |
Adrian Crum wrote:
> <set field="childId" from-field="parameter.childId" to-scope="user" global="true"/> > > -Adrian > > --- On Wed, 12/31/08, Jacek Wagner <[hidden email]> wrote: > > >> From: Jacek Wagner <[hidden email]> >> Subject: passing parameter in ofbiz >> To: [hidden email] >> Date: Wednesday, December 31, 2008, 3:35 PM >> All, >> >> In the very first screen widget in my application I set my >> global variable: >> >> <set field="childId" from >> from-field="parameter.childId" >> to-scope="user"/> >> >> How should I set it up to be certain I will never loose the >> content of childId? >> >> Jacek >> > > > > |
All,
What would be a corresponding screen widget command(s) to a Java syntax: context.remove(......) context.put(.....) Jacek |
Free forum by Nabble | Edit this page |