Tuesday 28 May 2013

How to send ajax request in Liferay

http://www.liferay.com/community/forums/-/message_boards/message/9582892

Thursday 9 May 2013

How to develop portal using Liferay

http://mrbool.com/how-to-develop-portal-using-liferay/27987


  • Before completing step(3) in above suggested url steps  MAKE SURE to follow the steps:

1 copy the build.properties file in same location inside sdk plugin folder of liferay
2. Rename to build.<USERNAME(name of the user operating the machine)>.properties
Ex- build.VHV.properties

3. Now change the argument:

app.server.dir=C:\liferay-portal-6.1.1-ce-ga2\tomcat-7.0.27 (path of Liferay tomcat folder)

4. Save
5.  Now install sdk in eclipse


  • Also change database as mysql for liferay after running on localhost

Wednesday 10 April 2013

Create Desktop application in Java Using XML

http://stackoverflow.com/questions/5213838/java-create-a-gui-with-xml

1.There are some Java-based engines to render XUL (using Swing), but I'm not sure what state they are in.



I have had good experience with ANTFormhttp://antforms.sourceforge.net/.
It generates Java Swing panels from XML. I have used it to build simple GUI apps that execute ANT targets.
Example of the XML declaration:
<antform title="Send Mail" 
    save="properties.txt"
    image="doc/images/testlogo.jpg">
    <label>To send a mail, use the following form. Pick a recipient,
 type a subject and a body...the script will do the rest.</label>
    <selectionProperty label="Recipient: " 
    property="recipient" 
    values="address1@somewhere.com; address2@somewhere.com; address4@somewhere.com" 
    separator=";"/>
    <textProperty label="Subject : " property="subject" />
    <multilineTextProperty label="Message body: "
        property="body"/>
    <booleanProperty label="Send immediately: " property="send"/>
</antform>
Example of what it produces:
enter image description here
share|edit
I used Apache Pivot http://pivot.apache.org/ and really liked it.

Create Desktop application in java using HTML

Using JavaFX
http://docs.oracle.com/javafx/2/swing/overview.htm
http://docs.oracle.com/javafx/2/webview/jfxpub-webview.htm

Q. Difference between Declarative and Programmatic/Procedural approach?



Ans :
A Procedural language provides "assignments" to keep and/or alter the states while executing through steps. It provides the means to express WHAT a program can do in STEPS (the HOWs) 
A pure declarative programming language has no concept of "assignments" to allow you alter states. It allow the programmers to express what the software can do only. (not the how-part)

I suppose there is always a programmatic approach available since the UI is not made of magic. I guess declarative UIs are just build on the top of programmatic UIs

Declarative
Describe a result and get it via a black box. Examples:
·         yacc
·         Treetop
·         SQL
·         Regular Expressions
·         lex
·         XSLT
·         Markup (XML,HTML etc), troff, CSS, VHDL
Procedural
Describe the algorithm and process steps, at various degrees of abstraction.
·         C, most legacy languages
·         PHP, mostly
·         in some sense all major languages
Object Oriented
·         Tends to be in the procedural category, typically refers to languages that exhibit a hierarchy of types that inherit both methods and state from base types to derived types, but also kind of includes prototype-based languages like JavaScript. Somewhat a separate dimension from the other categories here.
Functional
You left this one out. The opposite of imperative programming, it emphasizes the application of functions without side effects and without mutable state. The declarative systems above exhibit certain aspects of functional programming.
·         Scheme
·         Erlang
·         OCaml
·         Haskell
·         Lisp, depending. (Lisp perhaps deserves its own unique category)
·         Clojure, somewhat
·         Ruby, somewhat less
·         F#
Ex-
Building User Interfaces with JSF: Declarative vs. Programmatic Approach
When we are using JSF tags to build the user interface, we are using the declarative approach. With declarative approach we can visualize the hierarchy of the user interface.
Let̢۪s see how it̢۪s possible to produce the same user interface using both approaches. We will build the following simple panel:
richpanel.png
Here is an example of declarative approach:
  <h:outputText value="I love New York"/>  <h:outputText value="I love the Big Apple and using RichFaces"/> 
Using tags mimics better how the actual user interface will look. In other words, it̢۪s easier to build the user interface using tags.
Here is an example of programmatic approach that produces exactly the same page:
Application application = FacesContext.getCurrentInstance().getApplication(); // create rich:panel HtmlPanel panel = (HtmlPanel)application.createComponent(HtmlPanel.COMPONENT_FAMILY); // set width panel.setStyle("width:400px"); // create h:outpuText HtmlOutputText outputTextHeader = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); // set h:outputText value outputTextHeader.setValue("I love New York"); // add header facet to rich:panel panel.getFacets().put("header", outputTextHeader); // create h:outputText HtmlOutputText outputText = (HtmlOutputText)application.createComponent(HtmlOutputText.COMPONENT_TYPE); // set h:outputText value outputText.setValue("I love the Big Apple and using RichFaces"); // add h:outputText as a child to rich:panel panel.getChildren().add(outputText);
As you can probably see, when using programmatic approach, it̢۪s more difficult to visualize and understand the hierarchy of the user interface. It basically looks flat.
While most of JSF pages will be built using the declarative style, programmatic approach will almost always be required in a large application. In situations where pages are highly dynamic, the programmatic approach provides power and flexibility. The programmatic approach is also needed when components need to be manipulated inside a Java class (for example managed beans). A common example of this would be using the ‘binding’ attribute and setting some property of the component, for example:
component.setRendered(false);
The programmatic approach is not â€Å“badâ€? as long as you know how and when to use it.
This is just to give you an idea what is the difference between declarative and programmatic approaches to developing user interfaces. Of course JSF provides a declarative approach to build the user interface using JSF and RichFaces tags

Wednesday 6 February 2013

cascade delete on existing table

Cascade delete is a technique used to delete foreign key records (that points to the deleted primary key ) automatically if you are deleting primary key records.

We can set cascade delete while creating table :


CREATE TABLE hard_candy 
   (candy_num INT, 
    candy_flavor CHAR(20),
    FOREIGN KEY (candy_num) REFERENCES all_candy
    ON DELETE CASCADE)


However to perform cascade delete on existing table:

you can not add ON DELETE CASCADE to an already existing constraint. You will have to drop foreign key constraint and then recreate the constraint
1. First I need to view my foreign key constraint name for the table:

mysql to find foreign key detais of table

select * from information_schema.table_constraints where table_name = 'subheadingtb'

2. Now drop the foreign key constraint using

ALTER TABLE tablename
DROP FOREIGN KEY constraintname

3. Now create the constraint with same name using DELETE CASCADE

ALTER TABLE childtablename
ADD CONSTRAINT constraintname
FOREIGN KEY (coloumnname_of_childtable_which_has_foreign_key)
REFERENCES parenttablename(coloumnname_of_parenttable_which_has_primary_key) ON DELETE CASCADE

For more detail on cascade delete:

http://ronaldbradford.com/blog/using-cascade-in-foreign-keys-2006-07-02/

Friday 25 January 2013

Difference between CreateStatement and PreparedStatement

Differences:

CreateStatement
(i) Use for general-purpose access to your database. 
(ii) Useful when you are using static SQL statements at runtime because The Statement interface cannot accept parameters.

(iii) Usually suitable  for DDL commands such as Create,alter,drop,etc
(iv) In terms of efficiency, it is suitable to use CreateStatement only when we know that we will not need to execute the SQL query multiple times.ex- Statement stmt = con.createStatement();
stmt.executeUpdate("DROP TABLE PRODUCTS IF EXISTS");

where as PreparedStatement Use (i) when you plan to use the SQL statements many times i.e in the context of multiple executions. for egsuppose a table to require 1000 times a insert same statement,we go for a prepare statment,

(ii) you must use a PreparedStatement object if you want to use large objects like BLOBs or CLOBs.
(iii) to run dynamic queries beacuse The PreparedStatement interface accepts input parameters at runtime
ex- String sql="select * from emp where emp_id = ?";
PreparedStatement pStmt = conn.prepareStatement(sql); 
pStmt.setLong(1, profile.getUserId()); 

here getUserId is given at run time.

Hence we can use PreparedStatement to safely provide values to the SQL parameters, through a range of setter methods (i.e. setInt(int,int)setString(int,String), etc.).

(iv) The ability to create an incomplete query and supply parameter values at execution time(using ?). This type of query is well suited for filtering queries which may differ in parameter value only: 
SELECT firstName FROM employees WHERE salary > 50
SELECT firstName FROM employees WHERE salary > 200 
To create a parametrized prepared statement, use the following syntax:

// Assume a database connection, conn.
PreparedStatement stmnt = null;
ResultSet rs = null;
try
{
  // Create the PreparedStatement, leaving a '?'
  // to indicate placement of a parameter.
  stmnt = conn.prepareStatement(
    "SELECT firstName FROM employees WHERE salary > ?");

  // Complete the statement
  stmnt.setInt(1, 200);

  // Execute the query to obtain the ResultSet 
  rs = stmnt.executeQuery();
}
  catch(Exception ex)
{
  System.err.println("Database exception: " + ex);
}






(v) Prepared is faster because it is precompiled.Most relational databases handles a JDBC / SQL query in four steps:
  1. Parse the incoming SQL query
  2. Compile the SQL query
  3. Plan/optimize the data acquisition path
  4. Execute the optimized query / acquire and return data

Statement will always proceed through the four steps above for each SQL query sent to the database. A PreparedStatement pre-executes steps (1) - (3) in the execution process above. Thus, when creating a PreparedStatement some pre-optimization is performed immediately. The effect is to lessen the load on the database engine at execution time.

(vi)Prepared is an important protection from SQL injection attacks.

Conclusion :

We can perform all operations using both statements but these above described certain  context in which one statement is efficient over another like

For DDL statement use CreateStatement() because these operations used rarely.
For DMl statements use PreparedStatent(). However if any operation that needs to be performed one or two time during life cycle you can use any one of them.