Wednesday May 09, 2007
Wednesday May 09, 2007
Day 1 at JavaOne 07 was full of good stuff. There were a lot of announcements about FX, which sounds like an exciting new technology. I talked to a guy in the Erickson booth (You can't miss the booth, it is the only booth in the Sun section of the Pavilion where they aren't wearing the blue Sun shirts), and he did a good job of explaining how FX will change the way we use our phones.
My first session of the day was one on JRuby by Charles Nutter and Thomas Enebro (TS-9370). I have been hearing alot about Ruby, such as Craig making jMaki work with Ruby, so I decided I would use JavaOne as an opportunity to learn about this technology. Charles and Thomas gave an excellent introductory session for beginners like me. First they explained what Ruby was and why it was an improvement over Perl and JavaScript. For example:
On that last bullet, the woman next to me had switched from Perl and JavaScript to Ruby about a year ago, and she told me that it was indeed easy to learn and had also increased her productivity. She also agreed with their statement that the language was "addicting".
The duo then went on to explain why JRuby:
Gail recently helped with a NetBeans tutorial Creating a Ruby Weblog in 10 Minutes. I hope to give it a whirl when I get back from JavaOne. Also, there is this NetBeans day interview with Charles Nutter.
Another session I really enjoyed was David Botterill's Birds of a Feather talk about developing a real-world web application with the NetBeans IDE (TS-4092). He gave some fantastic tips and promises to follow up in detail on his web site. I highly recommend that you check out his slides when they become available and that you watch his blog for future entries.
I spent a lot of time at the NetBeans and Web 2.0 booths in the Pavilion. Sandip Chitale was showing how to use the new dynamic faces complib. We talked a bit about how to use fire transaction to do dynamic coordinated dropdowns. I hope to blog on that soon.
Next to the NetBeans booth is the jMaki booth. Carla was there showing how easy it is to use jMaki to add Ajax widgets to web applications. I never got a chance to talk to her because there was always a crowd. But I am attending all the jMaki sessions that I can.
--
Tuesday Mar 06, 2007
Monday Jan 08, 2007
A few customers have pointed out a bug in the Generating Reports and PDFs From a Web Application tutorial. I have to admit that I am somewhat embarrased that I never noticed that the first record is missing from the reports.
I am trying to get the fix pushed out this week. In the meantime, for those who are using code from the tutorial, you should know that you need to either call beforeFirst() or execute() on the rowset before passing the rowset to the JRResultSetDataSource constructor.
Tuesday Dec 19, 2006
Now that we blog about both the Sun Java Studio Creator IDE and the NetBeans Visual Web Pack, we needed a place to put blogs that apply to both products. So, if you have only been reading the topics in the Sun Java Studio Creator category, you might want to add the Web UI Components category to your reading list as well (and you should probably add Ajax too).
Sunday Dec 10, 2006
In our Tabbing Thru the Tulips entry, we show how to use a Tab Set component in a Page Fragment for site navigation. I am happy to say that a Sun Java Studio Creator IDE user has designed a different solution, which better addresses real-world scenarios. He has been kind enough to post his solution on the community java.net wiki for the IDE. You can read his write up at http://wiki.java.net/bin/view/Javatools/MenuTabSetExample.
Thanks Mark (aka Yossarian aka Khumalo).
Tuesday Dec 05, 2006
If you are developing a web application using the Sun Java Studio Creator IDE, and the application does not use Enterprise JavaBeans technology, you might not really need the overhead of a full blown application server. If that is a case, consider using the Sun Java System Web Server 6.1 for your development phase. While it is true that you can war up your web application and deploy it to an application or servlet container, as shown in our deployment tutorials, the IDE also offers a one-step menu item, Deploy to Remote Server, that deploys your project to an instance of the Sun Java System Web Server and runs the web application in your browser. You might find the test-modify-redeploy cycle a bit faster and the memory consumption somewhat lower.
After downloading and installing the web server (don't forget to write down the User Id and Password that you entered), copy the following files to the web server's bin/https/jar folder.
/SunAppServer8/lib/driveradapter.jar
and then add the necessary driver files for your database server to the jar folder as well./SunAppServer8/derby/lib/derbyclient.jar,
but you cannot copy the other JDBC drivers because they are locked, so you need to
obtain other drivers from the OEMs.
Start the Admin Server and open the web server's Admin Console typically, http://localhost:8888) in your browser. Select a web server (when you first install, there is just one) and click Manage.
webserver_install_dir/bin/https/jar/dom.jar webserver_install_dir/bin/https/jar/xercesImpl.jarFor example, on a Windows system, enter:
C:/Sun/WebServer6.1/bin/https/jar/driveradapter.jar;C:/Sun/WebServer6.1/bin/https/jar/derbyclient.jar
webserver_install_dir/bin/https/jar/driveradapter.jar webserver_install_dir/bin/https/jar/yourdatabasedriver.jar
Now you are ready to set up the web server in the IDE.
That takes care of the setup. To test a web application using the Sun Java System Web Server, right-click the web application's node in the Projects window and choose Deploy to Remote Server > your web server from the pop-up menu.
Monday Nov 20, 2006
We just published a new tutorial today on how to use the JasperReports framework in a web application built using the Sun Java Studio Creator IDE. In this tutorial, you create a web application that displays and prints information from a travel database. The web application lets you view a trip report in either HTML format or PDF format.
Some interesting parts of this tutorial are that you use a managed bean instead of a servlet to generate the report, you add an entry to the build.xml file to compile the reports for you, and you reuse your dataprovider's rowset query for the report.
Check it out at http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/2/reports.html.
Wednesday Nov 15, 2006
At the bottom of each of our Sun Java Studio Creator tutorials is a Rate and Review box where you can rate the tutorial and submit comments or questions. The responses that you have sent to us are extremely valuable. We have made many improvements based on the feedback that you send to us using the Rate and Review box.
Unfortunately, this mechanism broke about one month ago and the Rate and Review responses are going into a black hole, never to see the light of day. After repeated requests to fix this, we finally got word that they are not going to fix it. Eventually, they will move to some other mechanism. When that happens, we will let you know. In the meantime, don't bother with the Rate and Review box. If you have suggestions, problems, or questions, you can submit them to us by going ot http://developers.sun.com/prodtech/javatools/jscreator/learning/tutorials/index.jsp and clicking on the link to the feedback form.
Friday Oct 27, 2006
There have been many posts on the Sun Java Studio Creator IDE forum from people having trouble with using getSelected() or getCookieSelectedTreeNode() when building dynamic trees. We have had the same problems while writing our database tree tutorial. I have filed some bugs on their behalf as well as ours, but we won't see fixes in the near future. In a nutshell, you can't tell what node was selected if the user has cookies turned off, and if there are stale cookies around, getCookieSelectedTreeNode might serve up that stale cookie instead of the actual node selected.
So, in the meantime, I came up with this workaournd. What we do in the database tree tutorial (which is still work in progress) is to pass the selected value in a URL.
Here is the modified code. Notice the setUrl()
public void prerender() {
// If the Request Bean's personId is set, then
// we just came back from the Trip page
// and had displayed a selected trip.
// We use the personId later to determine whether
// to expand a person's node
Integer expandedPersonId = getRequestBean1().getPersonId();
try {
// Set up the variables we will need
Integer currentPersonId = new Integer(-1);
// If nbrChildren is not 0 then this is a
// postback and we have our tree already
int nbrChildren = displayTree.getChildCount();
if (nbrChildren == 0) {
// List of outer (person) nodes
List outerChildren = displayTree.getChildren();
// Erase previous contents
outerChildren.clear();
// List of inner (trip) nodes
List innerChildren = null;
// Execute the SQL query
tripDataProvider.refresh();
// Iterate over the rows of the result set.
// Every time we encounter a new person, add first level node.
// Add second level trip nodes to the parent person node.
boolean hasNext = tripDataProvider.cursorFirst();
while (hasNext) {
Integer newPersonId =
(Integer) tripDataProvider.getValue(
"TRIP.PERSONID");
if (!newPersonId.equals(currentPersonId)) {
currentPersonId = newPersonId;
TreeNode personNode = new TreeNode();
personNode.setId("person" + newPersonId.toString());
personNode.setText(
(String)tripDataProvider.getValue(
"PERSON.NAME"));
// If the request bean passed a person id,
// expand that person's node
personNode.setExpanded(newPersonId.equals
(expandedPersonId));
outerChildren.add(personNode);
innerChildren = personNode.getChildren();
}
// Create a new trip node
TreeNode tripNode = new TreeNode();
tripNode.setId("trip" +
tripDataProvider.getValue("TRIP.TRIPID").toString());
tripNode.setText(
tripDataProvider.getValue("TRIP.DEPDATE").toString());
tripNode.setUrl("/faces/Trip.jsp?tripId=" +
tripDataProvider.getValue("TRIP.TRIPID").toString());
innerChildren.add(tripNode);
hasNext = tripDataProvider.cursorNext();
}
}
} catch (Exception ex) {
log("Exception gathering tree data", ex);
error("Exception gathering tree data: " + ex);
}
}
|
Then, in the destination page, we add the following code to pick up the passed parameter.
public void prerender() {
// Get the person id from the request parameters
String parmTripId = (String)
getExternalContext().getRequestParameterMap().get("tripId");
if (parmTripId != null) {
Integer tripId = new Integer(parmTripId);
try {
getSessionBean1().getTripRowSet1().setObject(1, tripId);
tripDataProvider1.refresh();
} catch (Exception e) {
error("Cannot display trip " + tripId);
log("Cannot display trip " + tripId, e);
}
}else {
error("No trip id specified.");
}
}
|
Wednesday Oct 04, 2006
Many people have been asking in the forum and in requests sent using our tutorial docs feedback form how to generate reports, such as PDF, from web apps built using Java Studio Creator IDE. I have been working on a JasperReports tutorial for quite some time, and have hopes to get it published in a couple of weeks. One of our customers Sander beat me to the punch. He wrote his own tutorial and he makes it available from his company's website. Thanks Sander!
Thursday Sep 21, 2006
I am working on a tutorial on how to use JasperReports in JSF web applications. At first, like most examples out there, I built a servlet and called the servlet from my web page. I eventually figured out that it is quicker and easier to use a managed bean, and took that route instead.
However, I do see a lot of posts in the forum asking how to use servlets in JSF web applications built using the IDE, so here is what I learned.
public String button1_action() {
try {
FacesContext facesContext = getFacesContext();
HttpServletResponse response =
(HttpServletResponse) facesContext.getExternalContext().getResponse();
response.sendRedirect("makeReport");
facesContext.responseComplete();
} catch (Exception e) {
log(e.getMessage());
error(e.getMessage());
}
return null;
}
|
Thursday Sep 07, 2006
Here is a mini tutorial that teaches you how to dynamically build a tree structure from data in a database. You populate the first-level nodes in the Tree with names from a database and the second-level nodes with the trip dates for that person.
Notes: Due to cookie problems, it is hard to tell which node the user selects. See http://blogs.sun.com/divas/entry/workaround_for_dynamic_trees for a workaround
Events related to tree node selection do not work correctly in portlets because the Tree component uses cookies to pass the selected node id back and forth, and cookies are not correctly handled by the portlet container.
You begin by building a home page that includes the Tree component and the TRIP database table. The following figure shows the page.
Figure 1: Page Design |
DatabaseTree.Travel Information, and press Enter. In the Properties window, set the id property to displayTree and the clientSide property to True.
clientSide is True, every child node (expanded or not) is sent to the client, but is not made visible unless the
parent node is expanded. When clientSide is False, only the child nodes of the expanded parent nodes are rendered.Next, you connect the page with a database table in the Travel data source. You then use the Query Editor to modify the SQL query used to retrieve the data so that the traveler names appear in alphabetical order and the travel dates appear in chronological order.
Figure 2 : Query Editor |
Now you add code to the prerender() method to dynamically build the Tree component from the TRIP and PERSON database tables.
prerender method. Replace the body of the prerender method with the following code shown in bold.| Code Sample 1: prerender method for Page1 |
public void prerender() {
try {
// Set up the variables we will need
Integer currentPersonId = new Integer(-1);
// If nbrChildren is not 0 then this is a
// postback and we have our tree already
int nbrChildren = displayTree.getChildCount();
if (nbrChildren == 0) {
// List of outer (person) nodes
List outerChildren = displayTree.getChildren();
// Erase previous contents
outerChildren.clear();
// List of inner (trip) nodes
List innerChildren = null;
// Execute the SQL query
tripDataProvider.refresh();
// Iterate over the rows of the result set.
// Every time we encounter a new person, add first level node.
// Add second level trip nodes to the parent person node.
boolean hasNext = tripDataProvider.cursorFirst();
while (hasNext) {
Integer newPersonId =
(Integer) tripDataProvider.getValue(
"TRIP.PERSONID");
if (!newPersonId.equals(currentPersonId)) {
currentPersonId = newPersonId;
TreeNode personNode = new TreeNode();
personNode.setId("person" + newPersonId.toString());
personNode.setText(
(String)tripDataProvider.getValue(
"PERSON.NAME"));
outerChildren.add(personNode);
innerChildren = personNode.getChildren();
}
// Create a new trip node
TreeNode tripNode = new TreeNode();
tripNode.setId("trip" +
tripDataProvider.getValue(
"TRIP.TRIPID").toString());
tripNode.setText(
tripDataProvider.getValue(
"TRIP.DEPDATE").toString());
// Set "action" property to use for navigation
tripNode.setAction(
getApplication().createMethodBinding
("#{Page1.tripNode_action}", null));
innerChildren.add(tripNode);
hasNext = tripDataProvider.cursorNext();
}
}
} catch (Exception ex) {
log("Exception gathering tree data", ex);
error("Exception gathering tree data: " + ex);
}
}
|
Figure 3: Dynamic Tree Node |
Wednesday Aug 30, 2006
Here is a mini-tutorial for creating a Popup window for the user to lookup values. One scenario that you might use this for is when the page visitor needs more information then can be displayed in a drop-down list.
Note: The original post of this blog entry had code that did not work in Internet Explorer. Escritorioooo posted a solution to the forum and I updated the code using Escritorioooo's solution. Thanks Escritorioooo!
Popup.onClick property to doSave('#{currentRow.value['STATE.STATEID']}')
ui:body:
<ui:body binding="#{Popup.body1}" id="body1" style="-rave-layout: grid">
<script><![CDATA[
function doSave(val) {
window.opener.setVal(val);
window.close();
}]]></script>
|
Form1. Make it be the start page.
text property
to State Code.url property to /faces/Popup.jsp.onClick property to doPopup("form1:textField1")form1:textField1_field.popup. Click in some field and check that both values stuck.
Then click OK.target property value is still blank, select popup from
the combobox for that property.ui:body:
<ui:body binding="#{Popup.body1}" id="body1" style="-rave-layout: grid">
<script><![CDATA[
function doPopup(destination) {
popup = window.open("", "popup",
"height=300,width=200,toolbar=no,menubar=no,scrollbars=yes");
destinationElement=document.getElementById(destination);
popup.focus();
}
function setVal(val){
destinationElement.value=val;
}]]></script>
|
openerDestinationElement
to the popup window. The script for the Popup page uses openerDestinationElement
to get to the Text Field component on the Form1 page.
Friday Aug 25, 2006
As Java Studio Creator IDE users began building large web applications, we started hearing requests for better IDE performance. So the Creator team decided that the right thing to do was to give performance improvement a top priority and assigned a Performance Tiger team to produce results. As part of the effort, the Tiger team worked directly with customers to identify problems and to verify the performance improvements. The Quality Engineering team was an integral part of this effort, designing tests based on the customer applications, measuring results (see the above chart), and ensuring that that there were no regressions.
Most of the customer applications that were used for testing had over 50 pages. The Quality Engineers couldn't even open many of the applications in the IDE without first changing the default memory setting in the creator.conf file from -J-Xmx384m to -J-Xmx512m or more. One of the customer applications had over 175 pages.
I want to mention that the Performance Tiger team is not dumping and running. They want your feedback. If you are still having performance problems, please post your issues to the forum. Of course, if you are seeing significant improvements, they would probably like to hear about that too.
You can download today's hot fix release from the update center. To learn how to use the update center, go to the Updates web page.
I would like to say "well done" to the Performance Tiger Team, Quality Engineering, Release Engineering, and the customers who worked with us.
Note: for more improvement stats, see Sakthi's blog.
Friday Aug 18, 2006
If you have submitted any comments using the Rate and Review Comment box at the bottom of our tutorials, please know that the submissions are not getting to us. Apparently, the mechanism has been broken for a few weeks.
We apologize to those of you who have written to us using the comment box and have not received a reply.
They have not told us when this will be fixed.
Last night we posted our newest tutorial, Using Hibernate With the Sun Java Studio Creator IDE. This tutorial shows the essential steps necessary for adding a Hibernate framework to your project, as well as shows now to display the query results in a DropDown List component and a Table component.
This tutorial is not only helpful for Hibernate users, it is also helpful for anyone who is using a database for which compliant JDBC drivers are not available. You can use the concepts shown here to learn how to use the ObjectListDataProvider and Option arrays to feed the data from your result sets to the web application.
Note: NetBeans has a plug-in to generate the Hibernate persistence classes. You can read about it here and here.
Wednesday Jun 21, 2006
The Java Studio Creator File Upload tutorial shows how to upload a file to the web application's /resources/images folder. But, what if you want to save the uploaded files elsewhere? Here are some alternatives.
A different folder in the web application.You can put the images in any directory in the web application (that is, any directory under the web application's web directory). For example, you can create an upload/images subfolder under web and use the following code to store the images there:
String realPath =
theApplicationsServletContext.getRealPath
("/upload/images");
File file = new File(realPath + File.separatorChar +
justFileName);
One thing you need to be careful about when putting the uploaded files in the web application, is that anyone can access the files by URL, such as http://localhost:29080/MyWebApplication/faces/upload/images/myPicture.gif.
A known directory on the server. If you want to store the images somewhere else on the server, you can use code like the following:
File file = new File("C:/upload/images" + File.separatorChar +
justFileName);
uploadedFile.write(file);
If you plan to deploy the application to different servers, you might want to use code like the following to ensure that the upload directory exists:
File dir = new File("C:/upload/images");
if (! dir.exists()) dir.mkdirs();
File file = new File(dir.getCanonicalPath() + File.separatorChar +
justFileName);
uploadedFile.write(file);
For more information about the File class, see http://java.sun.com/j2se/1.3/docs/api/java/io/File.html.
An as yet unknown directory. An alternative is to put the directory path in the deployment descriptor, so that you can change the location dynamically.
String uploadDirectory =
getExternalContext().getInitParameter("uploadDirectory");
File file = new File(uploadDirectory +
File.separatorChar +
justFileName);
uploadedFile.write(file);
Thursday Jun 15, 2006
After all these months, I am finally making progress on the tutorial for the Table component. It might be a long time before I document all the steps and get the tutorial through quality assurance, editorial, and production processes. So, for those who can learn by examining code, I have decided to post the project that you build by completing the tutorial.
Here are some of the project's features:
Of course, everything I learned, I learned from Winston. He has posted lots of good Table component tips in his blog, so be sure to go there for advanced Table component information.
You can download the project zip from here.
Wednesday Jun 14, 2006
You asked--we delivered. The PDF versions of the Java Studio Creator tutorials are here! Cindy Church converted all of the 44 published tutorials and compressed them into ZIP files that align with the categories on the tutorials index page. For example, the GetStarted.zip file contains: Getting Started With Sun Java Studio Creator, Developing a Web Application, and Using the Java Editor
The hyperlinks work within each PDF file. Cindy added page numbers and formatted the files with wide margins so you can add the printed document to a binder or write notes in the margins. We thank our PDF early reviewers for their comments on the early iterations of our PDF files. If you have any questions or comments about the PDF files, please use our Feedback Form
Friday Jun 09, 2006
We have lots of good things going on with the Sun Java Studio Creator tutorials
Tutorials International
In addition to English, the Java Studio Creator tutorials are available in the following languages:
We also have the two new tutorials on how to create an internationalized applications in the Java Studio Creator IDE.
PDFs and Videos