on 07-10-2007 3:49 AM
Dear Expert,
I would like to know the best way to carrying data in Webdynpro between View.
For example, I have a Quiz applcation with 10 pages (View) of question. I would like to submit the answer at the end of the page (10th View). So, at the end of the page, I need the to retreive the answer from page 1 to 10 and submit it.
1. I am using copyToLocal. What that does it when the application fire Next event plug. it will
Quiz.<b>set</b>QuizAns1(Quiz.<b>get</b>QuizAns1)
and do the same thing for next 9 pages in order to bring the answer from page 1 to the end.
To simplfied, I am considering.
2. Model Beans
/people/valery.silaev/blog/2005/06/29/apojo--almostplain-old-java-objects-as-model
3. Session Beans.
Is any concern that I shouldn't use session bean in webdynpro??
Or any other way to make the Code more organize?
Thanks all.
Hi,
How are you validating the answers?
Are you taking the answers from the database and validating that with the answers given by the users?
If so then you have two options :
Option 1:
Create two context attribute in the component controller called Ctx_Answer and Ctx_Result.
Map the context attribute Ctx_Answer with the view controller Ctx_Answer. Every time the user choose any answer it'll come to the component controller Ctx_Answer.
Create a method in the component controller which will execute the model and will validate the answer with the database. If its a correct answer then add 1 to the Ctx_Result. Map the Ctx_Result attribute to the result/final view.
This way you can get how many answers are correct.
But this process will be slow as you have to execute the model every time you navigate from a view.
Option 2:
Create a node Answer and in that create a attribute Ctx_Answer. The node cardinality should be 0..n. For each navigation from views create a element of the node and add the answer to that node.
At the end of all the question views loop through node and retrieve the model and validate how many are correct answer.
For each correct answer add 1 to the node Ctx_Result.
This way you can find out how many are correct answer.
Hope this information will be helpful to you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The best way to carry data in WebDynpro views is through context attributes.
Create a context as below in component controller
Context
+Questions (node:cardinality 0..n,selection 0..n)
---Question
+Answers
---Ans (node:cardinality 0..n,selection 0..n)
Map the above context to all the views.
In the wdDoInit() of component controller create Ans elements under Answers node equal to question node.
for(int i=0;i<wdContext.nodeQuestions.size();i++)
{
wdContext.nodeAnswers().addElement(wdContext.nodeAnswers().createAnswersElement());
}
// This way we need not create the elements in each view before going to the next view.
Populate the Question attribute with Questions.
Through indexing show the question corresponding to views as
In first view (index 0)
wdContext.nodeQuestions.getQuestionsElementAt(<b>0</b>).getQuestion();
In second view (index 1)
wdContext.nodeQuestions.getQuestionsElementAt(<b>1</b>).getQuestion();
and so on..
// Note: The Answer node will not be populated intially with values as your answer might be multiple choice.
After the user gives answer store the answer in the corresponding index of Ans attribute under node Answers as
For the answer in first view
wdContext.nodeAnswers.getAnswersElementAt(<b>0</b>).setAns(<get the answer from the view>);
For the answer in second view
wdContext.nodeAnswers.getAnswersElementAt(<b>1</b>).getAns(<get the answer from the view>);
In your last view you can get the Questions and Answers by looping through the Questions and Answers node.
This way you will need only one attribute for Question and Answer respectively.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can make a attribute in the context of component controller.
Map all the views to this component controller. The attribute in the component controller will be like a shared variable among all the views controllers.
Regards,
Ashwani Kr Sharma
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
98 | |
11 | |
11 | |
10 | |
10 | |
8 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.