Clone wiki

javarosa / ITextAPI

How To Use IText and IText special forms

The text in this document refers to the example xform at the bottom of the page.

You need to access the instance of FormEntryPrompt (or FormEntryCaption) being used by your application then simply call getQuestionText();.

So for example, if the FormEntryController was on the first question in the xform below and you wanted to retrieve the Itext relevant to the question you might use something like this:

String foo = fep.getQuestionText();  //this method first attempts to retrieve the 'long' form then tries for the default form.

In our example, foo would now contain the long form of the first question ("Patient ID").

If you want to retrieve a specific short form (such as say audio) for a question, do:

foo = fep.getSpecialFormQuestionText("audio");

It's possible to make this call for any textID (by using getSpecialFormQuestionText(TextID,form), instead of for the current textID.

Similarly, for items in a single or multi-select, use (assume the FormEntryController is currently at the select1 question in the example xform below)

String itemOneText = fep.getSelectChoiceText(ItemOne);  //where ItemOne is the first SelectChoice item
String itemOneImageText = fep.getSpecialFormSelectChoiceText(ItemOne, "image");

//now itemOneText will = "Icon 4"
//and itemOneImageText = "jr://images/four.gif"

Notes: Generally, these methods will return null if the specified itext type is not found. When attempting to retrieve default text, use methods getQuestionText() or getSelectChoiceText(). These have the following fallback strategy: try get 'long' text, try get default itext, try get labelInnerText, if all fails return null. Bear in mind that "" is a legitimate value that can and will be returned if found during the fallback operation.

Please see the JavaDocs for more in depth information. Convenience methods such as getAudioText() also exist, feel free to use them!

<h:html xmlns:h=""
    <h:title>RichMedia testing Images</h:title>
    <meta jr:name="rm-subforms-test-images"/>
				<id />
				<name />
				<find-mirc />
				<non-local />
				<consTest />

		<bind nodeset="/icons/name" required="true()" />
		<bind nodeset="/icons/find-mirc" required="true()" />
		<bind nodeset="/icons/consTest" type="xsd:int" constraint=". > 10" />
			<translation lang="English" default="">
				<text id="id">
				  <value form="long">Patient ID</value>
				  <value form="short">ID</value>
				  <value form="audio">jr://audio/hah.mp3</value>
				<text id="name">
				  	<value>Full Name</value>
					<value form="short">Name</value>
					<value form="image">jr://images/four.gif</value>
				<text id="find-mirc">
					<value form="long">Please find the mirc icon</value>
					<value form="short">MircIcon</value>
				<text id="pandora">
					<value form="image">jr://images/four.gif</value>
					<value form="long">Icon 4</value>
					<value form="short">AltText</value>
				<text id="mirc">
					<value form="image">jr://images/three.gif</value>
					<value form="long">Icon 3</value>
					<value form="short">AltText</value>
				<text id="gmail">
					<value form="image">jr://images/two.gif</value>
					<value form="long">Icon 2</value>
					<value form="short">AltText</value>
				<text id="powerpoint">
					<value form="image">jr://images/one.gif</value>
					<value form="long">Icon 1</value>
					<value form="short">AltText</value>
				<text id="constraint-test">
					<value>Should Be Less than 10</value>

	<input ref="id"><label ref="jr:itext('id')" /></input>
	<input ref="name"><label ref="jr:itext('name')" /></input>
	<select1 ref="find-mirc">
		<label ref="jr:itext('find-mirc')" />
		<item><label ref="jr:itext('pandora')"/><value>pand</value></item>
		<item><label ref="jr:itext('mirc')" /><value>mirc</value></item>
		<item><label ref="jr:itext('powerpoint')" /><value>powerp</value></item>
		<item><label ref="jr:itext('gmail')" /><value>gmail</value></item>
		<item><label>Non-localized select text item label</label><value>other</value></item>
	<input ref="non-local"><label>Non-Localized label inner text!</label></input>
	<input ref="consTest"><label ref="jr:itext('constraint-test')" /></input>