Latest Articles

Categories

Spring Web Flow stream or generate files

Published Thu 19 Aug, 10:46 by, admin in development

Spring Web Flow is a neat framework for JSF navigation and action management. It may not be the most versatile or very advanced but it will handle almost all of the scenarios in web development. In the future they will finally get rid of Dojo dependency for ajax operations and allow any javascript library (jquery, prototype,etc) to be used instead.

 

http://www.springsource.org/go-webflow2

In any enterprise application users expect to generate Adobe PDF reports or Excel worksheets, but how do you map an action that retrieves a pdf back to the user using Spring Web Flow. Here is a perfect example from my own experience:

Flow definition

 

<transition on="getPdfreport" validate="false">
            <evaluate
                expression="someBean.getFile(flowRequestContext,requestParameters.selectedName)" />
        </transition>

 

Class method

 

 public void getFile(final RequestContext context, final String name
            ) throws Exception

{

//some standard code to set content

try{ 

final HttpServletResponse response = (HttpServletResponse) context
                    .getExternalContext().getNativeResponse();
            response.setContentType("application/pdf");
            final OutputStream out = response.getOutputStream();
            out.write(fileContent);
            out.flush();
            out.close();
        }catch(Exception ex){
            log.error(ex);
        }finally{
            // its important to complete response otherwise the JSF rendering will
            // fail
            // java.lang.IllegalStateException: Response already committed
            context.getExternalContext().recordResponseComplete();
        }

}

 

The most important line here is recordResponseComplete(), it completes the response JSF cycle properly through SWF.

You must be passing the context in order to do this, see class: org.springframework.webflow.execution.RequestContext

 

Happy Programming

View Article


Seam conversations

Published Mon 19 Apr, 11:55 by, admin in All

Seam conversations

 

http://seamframework.org/Community/EndingAConversation

View Article


Finding constraint information

Published Mon 22 Mar, 07:41 by, admin in oracle

Often enough when debugging or viewing your logs in your Java or .NET (or other) apps you'd stumble upon something with a name "SYS_C005049" that would say Constraint violated.

You'd ask yourself, why couldn't they provide a meaningful name, well that happens when you don't name table constraints with something proper that would indicate the table name and its referencing table name.

Fret not!

Execute this query: select * from ALL_CONS_COLUMNS where table_name = 'Mytable';

With a list of columns: OWNER, CONSTRAINT_NAME, TABLE_NAME, COLUMN_NAME, POSITION

To Search by constraint name:  select * from ALL_CONS_COLUMNS where constraint_name = 'SYS_C005049'

 

Enjoy

 

View Article


Oracle Expression Edition 10g tips and tricks

Published Wed 17 Mar, 05:44 by, admin in oracle

Oracle Express is indeed a great way developing for Oracle database, it provides Apex (run on a small application server) that allows you to be DBA and a normal user without using any other tools for most tasks, even monitoring or executing jobs, scripts,etc. It can tuned (or de-tuned) to use less RAM (memory) on your workstation by changing SGA and PGA (PGA can be heavily reduced) parameters (still using a web tool). Of course this product comes with a limit of 1Gb max of RAM and few other limits which simply make sense.

Recycle Bin

 

Before you start creating tables and then droping them, you should realize that Oracle XE (express edition) has something called Recycle Bin.

Whenever you drop a table , a copy of that object is not really purged permanently , it is stored in a recycle bin, pretty much a simplified backup in case your app did something wrong.

Here comes the Tip

 

If you are completely sure that you droped the right table(s) , then Purge It with this command:

purge recyclebin;

View Article


Guaranteed way of creating proper SQL Scripts

Published Wed 17 Mar, 04:20 by, admin in oracle

Most developers end up writing their DDL (data definition ) scripts that create various objects related to their design. However there is a great feature in Oracle (existed for a while) that allows the script act as single unit of work (much like a transaction but on Definition level) which is really useful when the script is big and contains quite a few tables and/or views.

 

Note:Only Create table, create view and grant statements are allowed to be executed as a single operation (it hasn't changed in Oracle 11g

A good example of use (from Oracle):

 

CREATE SCHEMA AUTHORIZATION scott
CREATE TABLE dept (
deptno NUMBER(3,0) PRIMARY KEY,
dname VARCHAR2(15),
loc VARCHAR2(25))
CREATE TABLE emp (
empno NUMBER(5,0) PRIMARY KEY,
ename VARCHAR2(15) NOT NULL,
job VARCHAR2(10),
mgr NUMBER(5,0),
hiredate DATE DEFAULT (sysdate),
sal NUMBER(7,2),
comm NUMBER(7,2),
deptno NUMBER(3,0) NOT NULL
CONSTRAINT dept_fkey REFERENCES dept)
CREATE VIEW sales_staff AS
SELECT empno, ename, sal, comm
FROM emp
WHERE deptno = 30
WITH CHECK OPTION CONSTRAINT sales_staff_cnst
GRANT SELECT ON sales_staff TO human_resources;

 

If something fails , say a column is too long or default value is of unacceptable type, the whole operation will be rolled back.

View Article