Hi Nicolas,
First... I have a ftl file like this. Here I am calling "createStudent" in
the controller through "<@ofbizUrl>createStudent</@ofbizUrl>"
*************************
<form id="regForm" method="post"
action="<@ofbizUrl>createStudent</@ofbizUrl>" name="regForm"
enctype="multipart/form-data">
<body>
..... blah blah blah
</body>
</form>
*************************
Second.... my controller as shown below....
*************************
<request-map uri="createStudent">
<security https="true" auth="true"/>
<event type="java" path="com.sms.events.StudentServices"
invoke="createStudent"/>
<response name="success" type="view" value="newStudent"/>
<response name="error" type="view" value="errorPage"/>
</request-map>
*************************
Third.... from the controller above I am going to a java file called
"StudentServices" and invoking a method in the java file called
"createStudent".
Fourth... In the "createStudent" method of the java file... I have the
following...
**************************
public static String createStudent(HttpServletRequest request,
HttpServletResponse response) {
Delegator delegator = (Delegator) request.getAttribute("delegator");
LocalDispatcher dispatcher = (LocalDispatcher)
request.getAttribute("dispatcher");
GenericValue userLogin = (GenericValue)
request.getSession().getAttribute("userLogin");
Map<String, Object> result = ServiceUtil.returnSuccess();
try {
GenericValue smsSubjectMaster =
delegator.makeValue("smsSubjectMaster");
// Auto generating next sequence of studentId primary key
smsSubjectMaster.setNextSeqId();
// Setting up all non primary key field values from context map
smsSubjectMaster.setNonPKFields(context);
// Creating record in database for smsStudentMaster entity for
prepared value
smsSubjectMaster = delegator.create(smsSubjectMaster);
//subjectId = smsSubjectMaster.getString("studentId");
//context.putIfAbsent("subjectId", subjectId);
context.put("subjectId", subjectId);
result.put("subjectId", smsSubjectMaster.getString("subjectId"));
Debug.log("==========smsSubjectMaster record created successfully
with subjectId: "+smsSubjectMaster.getString("subjectId"));
} catch (GenericEntityException e) {
Debug.logError(e, module);
return ServiceUtil.returnError("Error in creating record in
smsSubjectMaster entity ........" +module);
}
}
**************************
In the try/catch block... pls notice this...
"smsSubjectMaster.setNonPKFields(context);". This 'context' I am talking
about. I want the context in this method ...
public static String createStudent(HttpServletRequest request,
HttpServletResponse response) {
// I NEED CONTEXT HERE
}
AND NOT IN THIS METHOD
public static Map<String, Object> createStudent(DispatchContext dctx,
Map<String, Object> context){
?? HERE I AM ALREADY PASSING CONTEXT AND GETTING IT
}
Now...
I see a 'globalContext' in this link...
https://cwiki.apache.org/confluence/display/OFBIZ/Variables+always+available+in+screen+context
But I think globalcontext is not the same as context. From the link above I
could pass the variables mentioned in the link from ftl to java by setting
screen parameters, but no parameter named 'context' in the link above.
Question: How do I get context in a method where I am passing
"HttpServletRequest request, HttpServletResponse response" as shown above.
regards
Avijit
On Fri, Jul 8, 2022 at 1:05 PM Nicolas Malin <[email protected]>
wrote:
> Hello Avijit,
>
> Can you share some peace of code, I didn't understand your ftl to java ?
>
> You have a ftl template and go to java service through request call or
> you want to call a java code on a ftl code ?
>
> Nicolas
>
> On 28/06/2022 12:45, Avijit Bose wrote:
> > Dear Sir,
> >
> > Can the 'context' be passed from a ftl file to java?
> >
> > I see a 'globalContext' in this link...
> >
> https://cwiki.apache.org/confluence/display/OFBIZ/Variables+always+available+in+screen+context
> >
> > My goal is to use context here..
> > -----------------------
> > dbName.setNonPKFields(context);
> > -------------------------
> > in a method...
> > ------------------------
> > public static String createSubscriber(HttpServletRequest request,
> > HttpServletResponse response) { }
> > -----------------------
> > can I use 'globalContext' in place of 'context'?
> >
> > regards
> > Avijit
> >
>
>