I'm newbie in Orbeon xforms, so I ask my questions here. I have REST webservice with some address (method GET) and I want to call him and the result should be provide to metadata of my form:
<!-- Main instance -->
<xforms:instance id="fr-form-instance">
<form>
<section-meta>
<resultOfMyRestWebservice/>
I've tried to follow this tutorial http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data (pull solution) but I don't know how I can put the result of rest in the marker: resultOfMyRestWebservice, and where I have to put the submission code:
<xforms:submission
id="load-data-submission"
method="get" serialization="none"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="?" instance="?"/>
regards
If I were you I would use a temporary run-time instance to hold the results of your REST call and then use setvalue to populate your persisting instance.
The following example works if you define the structure of your meta-data in your model, so you can use setvalue to populate. Otherwise you can use insert.
Ie. In your xforms:model define:
<!-- Run-time instance to hold Service response -->
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
<response/>
</xforms:instance>
Define your submission to replace this response instance:
<xforms:submission id="load-data-submission" method="get"
serialization="none" mediatype="application/xml"
resource="addressOfMyRestWS/{xxforms:get-request-parameter('myParam')}"
replace="instance" instance="fr-service-response-instance"/>
And then create an action to call the submission and populate your instance:
<!-- Populate Data
uses Load Data Submission
runs on form load -->
<xforms:action id="populate-data-binding">
<xforms:action ev:event="xforms-ready" ev:observer="fr-form-model" if="true()">
<xforms:send submission="load-data-submission"/>
</xforms:action>
<!-- Populate resultOfMyRestWebservice control with pathToResults value
following successful submission -->
<xforms:action ev:event="xforms-submit-done" ev:observer="load-data-submission"
context="instance('fr-service-response-instance')">
<xforms:action>
<xf:var name="control-name" value="'resultOfMyRestWebservice'" as="xs:string"/>
<xf:var name="control-value" value="/pathToResults" as="xs:string"/>
<xforms:setvalue ref="instance('fr-form-instance')/*/*[name() = $control-name]"
value="$control-value"/>
</xforms:action>
</xforms:action>
</xforms:action>
Note pathToResults is the xpath to the value you want from the results.
I do everything like in mentioned tutorial: http://wiki.orbeon.com/forms/how-to/logic/load-initial-form-data I mean:
....
<xf:model id="fr-form-model" xxf:expose-xpath-types="true">
<!-- User in which user data is collected -->
<xf:instance id="user-data">
<registration>
<first-name/>
<last-name/>
</registration>
</xf:instance>
<!-- Load initial data from a service -->
<xf:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xf:submission id="load-data-submission" method="get" serialization="none"
resource="http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml"
replace="instance"
instance="user-data"/>
<!-- Main instance -->
<xf:instance id="fr-form-instance">
<form>
<name/>
....
....
<fr:body xmlns:xbl="http://www.w3.org/ns/xbl"
xmlns:dataModel="java:org.orbeon.oxf.fb.DataModel"
xmlns:oxf="http://www.orbeon.com/oxf/processors"
xmlns:p="http://www.orbeon.com/oxf/pipeline">
....
<xforms:action ev:event="xforms-enabled">
<xforms:setvalue ref="xxf:instance('fr-form-instance')/name"
value="xxf:instance('user-data')/first-name"/>
</xforms:action>
</fr:body>
....
I want to get xml from link (http://github.com/orbeon/orbeon-forms/raw/master/src/resources/apps/xforms-sandbox/samples/howto/load-initial-form-data-pull-instance.xml), put in to the 'user-data' instance and then get the first-name and put to the 'name' marker in the 'fr-form-instance'. Unfortunately it does not working, I mean setvalue not working, because when I change 'user-instance' like that:
<xf:instance id="user-data">
<registration>
<first-name>SomeName</first-name>
<last-name/>
</registration>
</xf:instance>
it working, and the final xml look like:
....
<name>SomeName</name>
....
I really haven't idea why it doesn't working.
regards
///
Now I see that my problem may be reduced to:
It works:
<xforms:instance id="user-data" src="http://example.org/service/load-initial-form-data-pull-instance"/>
And it does not work:
<xforms:send ev:event="xforms-model-construct-done" submission="load-data-submission"/>
<xforms:submission id="load-data-submission"
method="get" serialization="none"
resource="http://example.org/service/load-initial-form-data-pull-instance"
replace="instance" instance="user-data"/>
I have to use second way, because I have to pass some parameter to resource (resource="http.../{xxforms:get-request-parameter('myParam')}")
Related
I have three templates in my project—we'll call them first.html, second.html, third.html.
first.html gets a string from the user, using an <input> tag:
<input type="radio" name="selection" value="example_string" />
second.html displays this string using {{selection}}. (In my views.py, I got the value using request.POST.get and render_to_response().)
The question is: how do I send this value from second.html to third.html? One of my attempts—using a <span> tag to save the information in a variable—is illustrated below, but it doesn't seem to work.
<span name="selection" value={{selection}}>{{selection}}</span>
Edit: The following line works by creating a dummy single radio button. I don't know why it shouldn't be possible to create a variable without an <input> tag [visible to the user].
<input type="radio" name="selected" value={{selected}} checked="checked" />
You need to understand how the web works: each page is entirely separate, and is requested using a separate request.
Your basic options are: save data on the client side, or post it back to the server.
Both options can be performed with javascript, or posting back can also be performed by posting the form back to the server.
If you want to send it back to the server, it will have to be stored in the current session, or in a model.
There are many javascript libraries. If you want to use them, I suggest you google around the subject.
Answering my own question, now that I've found the answer on Django's documentation.
There's a special kind of <input> tag precisely for this: "hidden". The following line accomplishes the same as was asked in the question, but without a dummy element visible to the user:
<input type="hidden" name="selected" value={{selected}} />
http://django-rest-framework.org/api-guide/relations.html#primarykeyrelatedfield
I am trying to write to a PrimaryKeyRelatedField() and, although a 200 status is returned, an empty value is being input for the field in question, rather than multiple values.
$.ajax({url:'<MY MODELVIEWSET>/<ID>', type:'PUT', data:{'field1':'xyz', <FIELD IN QUESTION WITH PrimaryKeyRelatedField(many=True)>:[1,2,3]}})
--> Updated field is empty
Updates are successful and correct when only one value is given for this field.
$.ajax({url:'<MY MODELVIEWSET>/<ID>', type:'PUT', data:{'field1':'xyz', <FIELD IN QUESTION WITH PrimaryKeyRelatedField(many=True)>:1}})
--> Updates correctly
You need to set traditional to true so jquery will encode the params that contains arrays in a way that django will understand:
$.ajax({
url:'<MY MODELVIEWSET>/<ID>',
type:'PUT',
traditional: true,
data:{field1:'xyz', field2:[1,2,3]}
})
See here for the difference between default and traditional encoding.
I have a selectOneMenu item with some products. Some of them are unavailable so after you click on it the button "Add" should be disabled and some message should appear that "Sorry the product you chose is currently unavailable". I have no idea how to achieve that. Tried listeners, ajax and still nothing.
This is one of many versions of my JSF Page:
<h:form>
<h:selectOneMenu value="#{productBean.productName}">
<f:selectItems id ="other" value="#{productBean.other}" var="other" itemValue="#{ordersBean.productName}" itemLabel="#{other.name}" />
<f:ajax listener="#{productBean.valueChanged}" />
</h:selectOneMenu>
<h:commandButton value ="Dodaj do zamówienia" rendered="#{productBean.available}"/>
<h:outputLabel id="orderSummary"/>
</h:form>
Beans are rather standard. I just need a clue how to do that and probably I will be able to do it myself.
Thanks in advance.
Here's one of the ways:
In your AJAX listener you could check if a product is available and set up bean field accordingly, or add a message for a component.
Introduce a component in your view that'll hold the message to the user, for example with the #{bean.available ? '' : 'Sorry, out of stock'} value, or enclose it within a <h:panelGroup> and let that component have a rendered attribute, or attach <h:message>/<h:messages> somewhere in your view.
Specify id of the message holder to be rendered within render attribute of <f:ajax> tag.
HI all,
I have an XML with the different email bodies. I am using xslt to prepare an email template for sending these emails. I also want to include <subject> tag to the xml so that the email is more maintainable.I am using spring to send mail. I need to set the body ans subject of the mail. Body of the mail i am setting by using xslt transformation. I want to set the subject too.Please help me out if you have any idea!! I don't want to use xml parsing just for setting subject.Is there any way i can get the subject value using xslt??
here is my xml:
<mailMessage>
<mail type="pinReset">
<subject>Regarding account pin reset</subject>
<body>
<prefix>Hello User You have initiated a pin reset Please click
on the link below to reset your pin</prefix>
<suffix>Thank you</suffix>
</body>
</mail>
<mail type="emailUpdate">
<subject>Regarding account email update</subject>
<body>
<prefix>emailupdated</prefix>
<suffix>thank u</suffix>
</body>
</mail>
<mail type="failureCount">
<subject>Regarding account unsuccessful login</subject>
<body>
<prefix>failureCount</prefix>
<suffix>thank u</suffix>
</body>
</mail>
</mailMessage>
I want to fetch the subject separately.
You could create a second, very simple XSLT template that only outputs the subject line.
You can pass the string value for the subject, and the mail type as parameters to the XSLT transformation, and the transformation can be written in such a way as to produce the whole email message.
How can print a page using xslt.
i need a link, or a button which when clicked invokes the print page printer dialog box.
I suspect you need to specify a bit more about what you are trying to do.
XSLT is simply a way to turn one block of text into another. The input is generally an xml buffer and the output is some text rendering of that buffer.
It is possible that you are trying to generate a script using XSLT and that you want that script to be able to open a print dialog when it is run by something e.g. you generate javascript, that then runs on a browser.
Can you describe in more detail what you want to achieve?
The following in an html page gives you a print link:
Print
XSLT is a language for transforming XML documents. That means you can add/modify content. Assuming your output is HTML, you can do this:
<xsl:template match="top">
<html>
<head>
</head>
<body>
<input name="print" type="button" value="Print"
onclick="javascript:window.print()">
<xsl:apply-templates />
</body>
</html>
</xsl:template>
But of course, where exactly the button has to go depends on your needs. I'd additionally, add a media=print specific CSS at the top so that the document comes out neat!