accessing context from service

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

accessing context from service

tuvok
Hi,

I have a screen in wich I set some variables:

<screen name="myScreen">
        <section>
                <actions>
                        <set field="myVariable" value="test_value" to-scope="user" global="true"/>
                </actions>
                <section>
                        <widgets>
                                <include-form location="component://myExample/widget/Forms.xml" name="myForm"/>
                        </widgets>
                </section>
        </section>
</screen>

and if I understand the field myVariable is accessible in context, but when I want to retrieve myVariable from service myJavaService using context.get("myVariable") I got null. Is it possible to access such a variable from my service and how?

Form myForm:

<form name="myForm" type="single" target="submitMyForm">
        <field name="param_1"><text/></field>
        <field name="param_2"><text/></field>
        <field name="Do something"><submit/></field>               
</form>

controller.xml:

<request-map uri="submitMyForm">
        <security https="true" auth="true"/>
        <event type="service" path="org.ofbiz.myApplication" invoke="myJavaService"/>
        <response name="success" type="view" value="myScreen"/>
</request-map>

Service definition:

 public static Map<String, Object> myJavaService(DispatchContext ctx, Map<String, Object> context) {
        Map<String, Object> result = FastMap.newInstance();
        Delegator delegator = ctx.getDelegator();
        Map<String, Object> myVariable= (Map<String, Object>) context.get("myVariable");
        return result;
}
Reply | Threaded
Open this post in threaded view
|

Re: accessing context from service

tuvok
Problem solved! I added input attribute in service declaration. Stupid mistake :)

<service name="myJavaService" engine="java" invoke="myJavaService" auth="true" location="org.ofbiz.myApplication">
        <attribute name="param_1" mode="IN"/>
        <attribute name="param_2" mode="IN"/>
        <attribute name="myVariable" mode="IN"/>
</service>