Package org.javarosa.form.api
Class FormEntryController
java.lang.Object
org.javarosa.form.api.FormEntryController
public class FormEntryController extends Object
This class is used to navigate through an xform and appropriately manipulate
the FormEntryModel's state.
-
Field Summary
Fields Modifier and Type Field Description static intANSWER_CONSTRAINT_VIOLATEDstatic intANSWER_OKstatic intANSWER_REQUIRED_BUT_EMPTYstatic intEVENT_BEGINNING_OF_FORMstatic intEVENT_END_OF_FORMstatic intEVENT_GROUPstatic intEVENT_PROMPT_NEW_REPEATstatic intEVENT_QUESTIONstatic intEVENT_REPEATstatic intEVENT_REPEAT_JUNCTURE -
Constructor Summary
Constructors Constructor Description FormEntryController(FormEntryModel model)Creates a new form entry controller for the model provided -
Method Summary
Modifier and Type Method Description intanswerQuestion(IAnswerData data, boolean midSurvey)Attempts to save answer at the current FormIndex into the datamodel.intanswerQuestion(FormIndex index, IAnswerData data, boolean midSurvey)Attempts to save the answer at the givenFormIndexinto the instance and returns one of three possibleintattempt result codes:ANSWER_OKANSWER_REQUIRED_BUT_EMPTYANSWER_CONSTRAINT_VIOLATEDFormIndexdeleteRepeat()Deletes a repeated instance of a group referenced by the current FormIndex.voiddeleteRepeat(int n)FormIndexdeleteRepeat(FormIndex questionIndex)Deletes a repeated instance of a group referenced by the specified FormIndex.FormIndexdescendIntoNewRepeat()FormIndexdescendIntoRepeat(int n)FormEntryModelgetModel()intjumpToIndex(FormIndex index)Jumps to a given FormIndex.voidnewRepeat()Creates a new repeated instance of the group referenced by the current FormIndex.voidnewRepeat(FormIndex questionIndex)Creates a new repeated instance of the group referenced by the specified FormIndex.booleansaveAnswer(IAnswerData data, boolean midSurvey)saveAnswer attempts to save the current answer into the data model without doing any constraint checking.booleansaveAnswer(FormIndex index, IAnswerData data, boolean midSurvey)saveAnswer attempts to save the current answer into the data model without doing any constraint checking.voidsetLanguage(String language)Sets the current language.intstepToNextEvent()Navigates forward in the form.intstepToPreviousEvent()Navigates backward in the form.
-
Field Details
-
ANSWER_OK
public static final int ANSWER_OK- See Also:
- Constant Field Values
-
ANSWER_REQUIRED_BUT_EMPTY
public static final int ANSWER_REQUIRED_BUT_EMPTY- See Also:
- Constant Field Values
-
ANSWER_CONSTRAINT_VIOLATED
public static final int ANSWER_CONSTRAINT_VIOLATED- See Also:
- Constant Field Values
-
EVENT_BEGINNING_OF_FORM
public static final int EVENT_BEGINNING_OF_FORM- See Also:
- Constant Field Values
-
EVENT_END_OF_FORM
public static final int EVENT_END_OF_FORM- See Also:
- Constant Field Values
-
EVENT_PROMPT_NEW_REPEAT
public static final int EVENT_PROMPT_NEW_REPEAT- See Also:
- Constant Field Values
-
EVENT_QUESTION
public static final int EVENT_QUESTION- See Also:
- Constant Field Values
-
EVENT_GROUP
public static final int EVENT_GROUP- See Also:
- Constant Field Values
-
EVENT_REPEAT
public static final int EVENT_REPEAT- See Also:
- Constant Field Values
-
EVENT_REPEAT_JUNCTURE
public static final int EVENT_REPEAT_JUNCTURE- See Also:
- Constant Field Values
-
-
Constructor Details
-
FormEntryController
Creates a new form entry controller for the model provided- Parameters:
model-
-
-
Method Details
-
getModel
-
answerQuestion
Attempts to save answer at the current FormIndex into the datamodel.- Parameters:
data-- Returns:
-
answerQuestion
Attempts to save the answer at the givenFormIndexinto the instance and returns one of three possibleintattempt result codes:Side effects: When it returns
ANSWER_OK, it mutates theTreeElementcorresponding to the givenFormIndexby setting its value to the givenIAnswerDataor by copying an itemset answer if the question is complex.- Parameters:
index- The index of the question/prompt that is being currently evaluateddata- The data to attempt to answer the question with.- Returns:
- the attempt's
intresult code - Throws:
RuntimeException- when the question is complex and it has constraints. See inline comments.- See Also:
QuestionDef.isComplex()
-
saveAnswer
saveAnswer attempts to save the current answer into the data model without doing any constraint checking. Only use this if you know what you're doing. For normal form filling you should always use answerQuestion or answerCurrentQuestion.- Parameters:
index-data-- Returns:
- true if saved successfully, false otherwise.
-
saveAnswer
saveAnswer attempts to save the current answer into the data model without doing any constraint checking. Only use this if you know what you're doing. For normal form filling you should always use answerQuestion().- Parameters:
data-- Returns:
- true if saved successfully, false otherwise.
-
stepToNextEvent
public int stepToNextEvent()Navigates forward in the form.- Returns:
- the next event that should be handled by a view.
-
stepToPreviousEvent
public int stepToPreviousEvent()Navigates backward in the form.- Returns:
- the next event that should be handled by a view.
-
jumpToIndex
Jumps to a given FormIndex.- Parameters:
index-- Returns:
- EVENT for the specified Index.
-
descendIntoRepeat
-
descendIntoNewRepeat
-
newRepeat
Creates a new repeated instance of the group referenced by the specified FormIndex.- Parameters:
questionIndex-
-
newRepeat
public void newRepeat()Creates a new repeated instance of the group referenced by the current FormIndex. -
deleteRepeat
Deletes a repeated instance of a group referenced by the specified FormIndex.- Parameters:
questionIndex-- Returns:
-
deleteRepeat
Deletes a repeated instance of a group referenced by the current FormIndex.- Returns:
-
deleteRepeat
public void deleteRepeat(int n) -
setLanguage
Sets the current language.- Parameters:
language-
-