Amazon deals

Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Wednesday, October 22, 2008

javax.xml.transform TransformerException: java.lang.NullPointerException : How to Solve?

Just after solving my previous problem I stumbled on NullPointerException in Transformer.transform (Source, Result) method, my application was working fine until yesterday, there was no update, no change in configuration of anything…

What I was doing therewas a simple attempt to use the transformer from the xml api to write an xml file:

Source source = new DOMSource (doc);
Result result = new StreamResult (new File (file));
Transformer transformer = TransformerFactory.newInstance ().newTransformer ();
transformer.transform (source, result);


Personally this is the worlds's most stupid error. Guess what the console gave as the eroor description : ERROR: '' "

Very helpful, isn’t it? What next? Well we'll proceed to the stack trace next:

Down somewhere in the jungle of exceptions you get Caused by: java.lang.NullPointerException

at com.sun.org.apache.xml.internal.serializer. ToUnknownStream.characters(ToUnknownStream.java:312)

the code there looks like this:

public void characters(String chars) throws SAXException
{
final int length = chars.length();


Now we finally see the part that threw the error. Well the char.kength() was zero because there was a null text node insertion beging tried. So now's the solution to this problem

1. Go through your source code

2. Find the text node that is null

3. Give it a String value

4. Recompile and run

OWLS ARE NOT ALWAYS WHAT THEY SEEM

Xforms submission giving null parameters to request.getparameter() - Solution

Simplicity side of X-forms and xml apart, when one goes building any major web app from the very little, itsy bitsy knowledge we have, looms large problems that shake the very fundamentals of what you began coding with. If you ever tried the previous Xform in a debug mode on the Websphere server you would have found out now the hard way that the form does pass values, but jsp page cannot recognise in whatsoever.  Its an irksome problem i had last night and spent around 6 hours of my valuble time figuring out, going through over 1000 links on google and reading over 10 pdfs, to know there isn'at a solution posted anywhere. Ok fine leave apart my difficulties, here's what you came for, the solution to the problem

 

Goto your submission element

<xf:submission action=”process.jsp”
method=”get” id=”sub”/>


add an extra parameter

<xf:submission action=”process.jsp”
method=”get”
seperator="&amp;" id=”sub”/>

voila, you have your parameters now.

Now, the exact reason why the problem occured:

An html form uses the seperator by default and a jsp seperates out and creates a parameter map from this. Xforms by default, doesn't specify the standard seperator, so the addition tag required in the submission element in your model.

Saturday, September 27, 2008

Writing your First Xform

Xforms isn't as complicated as people claim it to be. It is a simple, and with tons of benefits than traditional forms. Here's a step by step procedure involved inwriting an Xform that takes a persons name as an input and sends it to an jsp page process.jsp for processing.

1)

Open notepad and put in the following xhtml header

<html
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">


this header tell the browser the type of XHTML page and the different standards used as per W3C. the first line is the xforms standards, the second of schema for display and the third for the instance model. Without these your browser will not be able to intepret the page properly.

2)

Write the head section as you do in HTML, i'll elaborate the otter fields in comments delimited by //

<head>
<title>Xforms Example</title>


//The model specifies the Xforms data model. Instance contains all the fields you'll have in the model. Here we have only one field in the instance namely name.

<xf:model>
<xf:instance>
<name/>
</xf:instance>

//in submission action link to your serverside code
<xf:submission action="process.jsp"
method="get" id="sub"/>
</xf:model>
</head>


3) Now to the body part of the page.

<body>
<xf:input ref="name">


// the ref field is used to referance particular elements from the instance model. The label is what the label you want to show on the page

<xf:label>Name:</xf:label>
</xf:input>
<br />


//br is normal HTML break. The submission="sub" specifies the id as given in the instance model in head.

<xf:submit submission="sub"><xf:label>Submit</xf:label></xf:submit>
</body>
</html>


4) There you have your first Xforms ready. Save the file with a .xhtml extension and view in any Xforms compitable browser(click here to know more about xforms viewers) and there you go.

Monday, September 22, 2008

Xforms - An insight

Xpath, Xquery, Xlink, XSLT, Xforms uph... the never ending list of techologies that begin with an X and literaly give people headaches being one of the most complicated yet powerful SGML. This is a honest effort to render off itsy bitsy details about one such XML based technology - Xforms.

Well Xforms to begin with is a W3C recommendation that is a replacement for standard HTML forms. XForms provides a richer, more secure, and device independent way of handling web input. Pretty easy to learn actuall if u go through some tutorials like http://www.w3schools.com/xforms/xforms_intro.asp but they don't spell out the looming truth. You can very well write an xform page but to get it to display in your ordinary browser... well its close to defining hell. So here's what you got to do.

XForms browser Plugins


For Mozilla: Well for all those who switched to mozilla 3.0 there's no plugin available for Xforms, there goes W3c statements of supporting Xforms in all future browsers. The new kid on the block Chrome also doesn't support it natively nor has it plugins. For those still on Mozilla 2.0 check http://www.mozilla.org/projects/xforms/download.html

For IE: for once IE is good. Well atleast there are plugin developers who have developed plugins for Xforms for non native support. These include formsplayer and Novell

XForms standalone browsers


The most popular standalone XForms browser is surely X-Smiles, developed by the the University of Helsinky. X-Smiles is a Java-based browser, with full support for XForms and for Smil. X-Smiles works as well on PCs, as on PDAs as on (modern) mobile phones

XForms application servers


This is the third category which is quite useful if you don't want your clients to install software at their end to run your web application. That doesn't make it the recommended option though as its damn slow as the server process your xml based form and renders an equivalent html+js. However you can try it out in case you can sacrifice the speed for delivering your end users a hassle free usage of your application. The most popular of these application servers is probably Chiba 2.0, from ChibaCon. It is open source, very stable, and very easy to install on the server: just deploy the .war file on your favorite application server (Tomcat, JBoss, Orion, Resin, Oracle, WebLogic, WebSphere ...), and you are ready.