Showing posts with label jsf. Show all posts
Showing posts with label jsf. Show all posts

Wednesday, October 17, 2012

Lessons learned Seam 2.2 project

Quick post with some bullet points of lessons learned during my last (and first) Seam project:

  • Seam 2.2
  • Hibernate 3.3.1
  • JEE 5
  • EJB 3.0
  • JSF 1.2
  • Richfaces 3.3
  • JBoss 5.1
  • Drools 5
  • SQLServer 2008
  • MySql 5.x
  • TestNG
  • Hudson
Seam
- To have a navigation for a method with a parameter like exportSelected(String value): see Seam navigation based on a function with parameters
- If your Seam app keeps re-deploying (restarting) when using JBoss within Eclipse: delete all files that end with 'dia' in your WEB-INF dir. See: Seam keeps redeploying For example, I modified pages.xml, which apparently created a pagesdia (or similar) file... after removing that one, it worked fine again.

Hibernate
- To see which validator fails on a persist():


    try {
        entityManager.persist(verbinding);
    } catch (InvalidStateException e) {     
        for (InvalidValue invalidValue : e.getInvalidValues()) {         
            System.err.println("--------------> create(): exception Instance " +
               "of bean class: " + 
               invalidValue.getBeanClass().getSimpleName() +                  
               " has an invalid property: " + invalidValue.getPropertyName() +
               " with message: " + invalidValue.getMessage());     
        } 
	throw new RuntimeException(e);
    }




MySql
- To see data in better format in MySQL: show engine innodb status\G (so add the \G to a query)

Hibernate/JPA
- NamedQueries are loaded and parsed at startup time, so that's an advantage above em.createQuery() which are only parsed and evaluated at runtime. So with NamedQueries you get the errors sooner.

Drools
To solve this error in Drools decision table .XLS spreadsheet:


   [testng] DEBUG [test.service.drools.DroolsHandling] getKnowledgeBase: getting path info from settings service
   [testng] DEBUG [test.service.drools.DroolsHandling] getting test.service.drools.DroolsHandling ruletable file: HandlingModelTest.xls
   [testng] DEBUG [test.service.drools.DroolsHandling] getKnowledgeBase: Trying to open a File
   [testng] WARN  [jxl.read.biff.NameRecord] Cannot read name ranges for Excel_BuiltIn__FilterDatabase_1 - setting to empty
   [testng] WARN  [test.service.drools.DroolsHandling] There are errors in the decision table file
   [testng] WARN  [test.service.drools.DroolsHandling] Decision table error: message=[ERR 102] Line 9:16 mismatched input '"DroolsHandling6"' expecting ']' in rule "DroolsData_12" in pattern stringDataset
   [testng] WARN  [test.service.drools.DroolsHandling]     line: 9
   [testng] WARN  [test.service.drools.DroolsHandling] Decision table error: message=[ERR 102] Line 9:35 mismatched input '"Prefab"' expecting ']' in rule "DroolsData_12" in pattern stringDataset
   [testng] WARN  [test.service.drools.DroolsHandling]     line: 9
   [testng] WARN  [test.service.drools.DroolsHandling] Decision table error: message=[ERR 102] Line 22:16 mismatched input '"DroolsHandling6"' expecting ']' in rule "DroolsData_12" in rule "DroolsData_13" in pattern stringDataset
   [testng] WARN  [test.service.drools.DroolsHandling]     line: 22



Make sure your definition has all the cells merged that contain a condition! For example, check the red arrow pointing at the border of the cells between G9 and H9.
The last cell for the condition Prefab is not merged (i.e one cell) with all the other conditions. Here's now how it should be: see again the red arrow, there's no cell separation anymore, all condition columns are now merged into 1 cell.


- A space in a condition in a decision spreadsheet can cause a non-match! E.g GATE VALVE is not matched. Fixed it by always replacing a ' ' with an '_'.

Sunday, February 7, 2010

Best of this Week Summary 1 February - 7 February 2010

Sunday, November 1, 2009

Best of this Week Summary 26 October - 01 November 2009

Sunday, May 3, 2009

Best of this Week Summary 27 April - 03 May 2009

Sunday, March 22, 2009

Best of this Week Summary 16 March - 22 March 2009

  • Great article by Dion Hinchcliffe with 10 emerging technologies every software architect has to know about. In short:

    1. Cloud computing

    2. Non-relational databases

    3. Next-generation distributed computing

    4. Web-oriented architecture (WOA)

    5. Mashups

    6. Open supply chains via APIs

    7. Dynamic languages (e.g Rails, PHP compared to Java/.Net)

    8. Social computing

    9. Crowdsourcing and peer production architectures

    10. New Application Models (e.g the symantic web, opensocial, widgets)

  • Elaborate explanation of managing boilerplate text (e.g. titles, button labels, prompt, error messages, tool tips) in JSF applications. This includes more advanced locale requirements, like certain text that needs to be different when shown to junior and senior users.

  • Here's a nice diagram with an overview of what activities are needed to create a website, from idea to support and everything in between.


  • Always annoyed that you have to manually close a resource like InputStreams, Connections etc? And that the first exception might be surpressed by the second in the finally block? Here's a suggested solution: the Automatic Resource Management pattern by Joshua Bloch.

  • Ten more Eclipse shortcuts you maybe didn't know...

  • Of course you've heard/read that Microsoft has released IE8 last week. Here's a bunch of tips when migrating your site from IE7 to IE8.

  • Ever need to create a UUID/GUID? Here's a few offline generators compared. uuidgen is an online UUID generator supporting version 1 and 4. A handy FAQ on UUIDs with some more depth can be found here.

Sunday, March 8, 2009

Best of this Week Summary 02 March - 08 March 2009

Saturday, December 13, 2008

Best of this Week Summary 8 December - 14 December 2008

  • Spring's Web Flow 2 now lets you use JSF as view technology. It addresses a couple of the existing JSF issues and already some features only present in JSF 2.0.

  • Microsoft (yes yes, don't stop reading immediately ;-) has published a How-To Design Using Agile Architecture guide which "will help you start the process of designing your application. It discusses the six main steps you should follow, and then discusses the issues involved in making logical choices. It also provides checklists to help you ensure that the proposed design will meet your requirements", including patterns, best practices and agile considerations. This is a quick summary of the guide.

  • A tiny bit off-track, but still interesting to point out: of course you know Google's GWT, in which you can create a Javascript web front-end application in Java. But now this is also possible in Python (recently releasing version 3) with Pyamas! Pretty cool!

  • Talking about software architecture, how would you document that correctly? Here's a bunch of good tips trying to answer that. It is a good high-level overview of what you should document in an application architecture. Focus is on UML 2.0, but what should be in the documentation is valid for any notation format.

  • Here's the first list (and maybe last :-) I'll post on looking back @ 2008: on overview of what happened with Java in 2008.

Thursday, November 20, 2008

JSFUnit static analysis unit testing in ADF

Introduction
Currently I'm working on the framework design of an ADF application in JDeveloper 11.1.1.0.0 (yes sometimes a man's got to do what a man's got to do ;-). One of the parts is how we are going to do (unit) testing. And one of elements in there is testing the JSF part of the ADF application. Application Developer Framework consists of several layers where the View layer consists of a JSF implementation. This JSF implementation is named ADF Faces (RichFaces) and built on top of Trinidad, the open source JSF components implementation. ADF Faces has many components Ajax-ized and has more components than Trinidad.
My eye caught JSFUnit, an open source project from JBoss. I was only able to focus on the static analysis part JSFUnit offers (it offers also other dynamic "regular unit" tests). But little information was found about that. I couldn't find any installation tips for ADF (JBoss here and here, and Websphere setup tips were available).
Thus it was just me and the computer. Here's the steps that in the end did do the job (running on Windows XP).

Setup
A couple of things are needed for all types of static analysis.

  1. Download via JSFUnit Getting Started under the section “Files”: jboss-jsfunit-core-1.0.0.Beta3.jar en jboss-jsfunit-analysis-1.0.0.Beta3.jar

  2. Note that it was not necessary to download/install myfaces-api-1.2.0.jar or JSF 1.2 API.

  3. Start JDeveloper 11.1.1.0.0 and open an ADF application with Model and ViewController project.

  4. Right-click the ViewController project, select Properties and select Libraries and Classpath in the popup. Add the above downloaded jars there.

Three types of static tests are possible with JSFUnit. I'll describe setting up each type seperately. Most information was deducted from this part of the JSFUnit documentation.

Configuration static analysis
These tests test your JSF configuration. See the above mentioned documentation part for examples of what tests are performed.
  1. Create a JUnit testclass in your ViewController project. Modify it such that it matches this example class:


    package test.com.project;

    import java.io.File;
    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractFacesConfigTestCase;

    public class JSFUnitStaticAnalysisConfigTest extends AbstractFacesConfigTestCase {

    private static Set paths = new HashSet() {{
    // Example absolute path: add("C:/work/workspace/jsf-unit/src/faces-config.xml");
    // Relative path example below.
    add("public_html\\WEB-INF\\faces-config.xml");
    }};

    public JSFUnitStaticAnalysisConfigTest() {
    super(paths);
    }
    }



    Note the paths variable which points to the faces-config file to validate. Relative paths work too. Of course might not be valid in your test/production environment.

    Tip: notice for easier separation at deployment, I put the test class in a separate package, starting with "test.".

  2. And you're set: run the test. Of course you should see a green bar. If not, your config is probably not 100% ok (probably because what if a JSFUnit test is incorrect... Of course you then immediately contribute to the JSFUnit community project :-). I had for example several Serialization errors.

    Below is a screenshot with the result of running the config testcase:



TLD analysis
These tests test your TLDs. See the above mentioned documentation part for examples of what tests are performed.
  1. Add the dependent libraries mentioned here, at the bottom of the page: maven-taglib and commons-logging. For the commons-logging you can use the one provided by JDeveloper: Commons Logging 1.0.4. The third one, jsp-api-2.1.jar does not seem to be necessary in the ADF project.

  2. Create a JUnit testclass in the ViewController project with .tld files. Modify it such that it matches this example class:


    package test.com.project;

    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractTldTestCase;
    import static org.junit.Assert.*;

    public class JSFUnitStaticAnalysisTLDTest extends AbstractTldTestCase {

    private static Set paths = new HashSet() {{
    // Example: add("C:/work/workspace/jsf-unit/src/demo.tld");
    add("C:\\myprojects\\app\\src\\META-INF\\myjsf.tld");
    }};

    public JSFUnitStaticAnalysisTLDTest() {
    super(paths);
    }
    }



    Note the paths variable which points to the .tld to validate. Did not try if a relative path also works.

  3. And you're set: run the test. Of course you should see a green bar. If not, your .tld is probably not 100% ok.

    Below is a screenshot with the result of running the TLD testcase:



View static analysis
These tests test your JSF views. See the above mentioned documentation part for examples of what tests are performed.
  1. No extra libs are needed, so we can immediately create a JUnit testclass in the ViewController project. Modify it such that it matches this example class:


    package test.com.project;

    import java.io.File;
    import java.util.HashSet;
    import java.util.Set;
    import org.jboss.jsfunit.analysis.AbstractFacesConfigTestCase;
    import org.jboss.jsfunit.analysis.AbstractViewTestCase;

    public class JSFUnitStaticAnalysisViewTest extends AbstractViewTestCase {


    private static Set absoluteViewPaths = new HashSet() {{
    // Example: add("C:/work/project/src/home.xhtml");
    add("C:\\myprojects\\app\\mysite\\ViewController\\public_html\\detailsPage.jspx");
    }};

    private static Set recursiveViewPaths = new HashSet() {{
    // Example: add("C:/work/project/src/views");
    add("C:\\myprojects\\app\\mysite\\ViewController\\public_html");
    }};

    public JSFUnitStaticAnalysisViewTest() {
    super(absoluteViewPaths, recursiveViewPaths,
    "public_html\\WEB-INF\\faces-config.xml");
    }

    }



    Note the paths variables. Nowhere I could find what they exactly mean. The above runs a test that passes, so I assume the paths are set correctly...

  2. And you're set: run the test. Of course you should see a green bar. If not, your view is probably not 100% ok.

    Below is a screenshot with the result of running the view testcase:


Conclusion
So that's it. Not hard at all! If you want to know a bit more high level stuff about JSFUnit, check this presentation by the project lead at the Javapolis conference (currently rebranded to Devox conference). And here's another introduction presentation.

The Shale Test Framework could be an interesting alternative for unittesting JSF. Needs some more investigation...

Saturday, October 4, 2008

Best of this Week Summary 29 September - 05 October 2008

Saturday, September 27, 2008

Best of this Week Summary 22 September - 28 September 2008

Sunday, March 2, 2008

Saturday, January 19, 2008

Best of this Week Summary 14 January - 20 January 2008