Hey all…
I would like to find out how I can perform Addition using X-application with Checkboxes.
In my project, I have a car database each of which have a set of fixed accessories. What I need to do is to have all the accessories assigned with a checkbox and when the user checks it, the cost of the accessory gets stored. When the user checks another one, the current cost will be added to the previously marked one and so on…And finally when the user clicks on Calculate total cost, it generates the entire cost for the car along with the accessories.
Is there any way this can be acheived using X-application or is coding in Java Server Pages required? If not, then can someone tell me what to do?
Thanks,
Parth
X-Application Version: 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1
sounds like client side solution use javascript/vbscript to do this.
Amit
Hello Parth,
currently, we have not planned the support for checkboxes within the Tag Library of X-Application. Perhaps, it will be a solution when we support data types. Then, for Boolean types the edit tag could create a checkbox by default.
However, for your use case, this solution would not be sufficient. What you need is the evaluation of the checkbox values combined with a application-specific modification on your document(s). For the current version 3.1.2 of X-Application, the only solution I can propose is to use Scriptlets: embedded Java Code within the page which is invoked when the user sends the form with the check boxes.
Within the Scriptlets
- access the standard request object of JSP pages to extract the checkbox parameter,
- access the sessionContext object (see changelog.txt of your X-Application directory for an example)
- access your document:
BusinessDocument doc = sessionContext.getWorkspace().lookup(?the name of the document?);
- set the values depending on checkbox parameters
…
doc.getDescendant(?path to an acessory?).setValue(?accessory price?);
…
Use also Scriptlet code
- to calculate the sum.
- when you have to fill the checkbox
For the next version 3.1.3 of X-Application, we support a plugin mechanisms. Then, the calculation of the sum can be invoked by an element action and the code is part of a java classes you implement for your business logic.
For the checkbox evaluation, I don?t know if it?s possible to deliver a plugin which could support you. It would be interesting for us, when you could sent us your schema and the JSP page containing the checkboxes. Then, we could try out the implementation of checkbox evaluation via plugin and give some hints about this topic.
Many thanks,
Christian.
Dear Christian,
many thanks for the suggestion. However I still have a few doubts. When I generate the Jsp page which has all my checkboxes, there is no way that I can assign to them a variable is there? like in servlets… where I give each checkbox name= " " and value = " " . Can I do this here?
Also once thats done I will simply write a servlet that will accept the parameters , but how will it know which accessory i am choosing… since all this has to be dynamic.
Please can u give me an algorithmic solution?
Many thanks,
Parth
Hello Parth,
I have attached two pages you can copy into the directory of your X-Application simple examples
%XAPPLICATION_HOME%\examples\jsp\simple
After starting Tomcat, you can invoke the first page with
http://localhost:8080/simple/Checkboxes.jsp
The example lists fifteen Properties. From this set you can select properties (! checkbox). The price of the selected properties is added on the following page (! Scriptlet Code).
I hope, this example gives a hint how you could implement your application logic.
For more support, I need your schema and your JSPs.
Bye,
Christian.
checkbox.zip (2.44 KB)
There is another method.
1-) if your are difficulties creating dynamic context checkbox you can build a javascript function on servelet side(javascript source generation). So you can use function where you want on JSP side. It is better way than to create spaghetti.
2-) If you are using xapplication;
on servelet side
extend edit tag and use bodycontent.
BodyContent body = getBodyContent();
String bodyContentStr=body.getString();
then parse the string and use your setter methods.
on JSP side
use your new edit tag with body . of coure you will use javascript function on body.
Be careful about setter methods of your new edit tag.
brgs
Hello Christian,
here are the jsps & schemas of the project. We havent yet made the checkboxes page yet, but we will implement the idea that you gave us.
carsjsps.zip (9.64 KB)