Monday, November 30, 2015

Solved: Problem opening up Spanish resource file in inteliJ

Please refer to PROBLEM below.
Settings for inteliJ
 Finally the results.
Hope following helps.

Saturday, April 18, 2015

Shout out to our very own Tosha Shah for representing Texas and NIC at the myAmerica Developer Summit hackathon hosted...

Posted by Texas.gov on Friday, April 17, 2015

Tuesday, March 24, 2015

Salesforce Iwatch webinar

The Apple Watch is the long anticipated wearable device from Apple. It includes a striking design and innovative new interface. Developers can build apps, or specifically extensions to apps running on their iPhone, using WatchKit, Apple’s developer SDK. Now, with the latest Salesforce Wear Developer Pack developers can build apps for Apple Watch and Salesforce.com Join this webinar to learn how to build your first Apple Watch app using Salesforce Wear Kit.







What you will learn:
 
  • How to use the Salesforce Wear Developer Pack to extend your iPhone apps to the Apple Watch
  • Common implementation patterns for Apple Watch development, including: notifications, glances, messaging with the Salesforce Mobile SDK of iOS delegates, and more
  • Storyboards and project targets for xCode and Apple Watch
  • Writing Swift code to work with Salesforce data
 

Key Takeaways

    • How to create an Apple Watch app in conjunction with the Salesforce Mobile SDK for iOS
    • Sending and receiving data from Salesforce on the Apple Watch
     

    Intended Audience

       
      Existing Apple iOS developers, or Salesforce Platform developers interested in getting started with iOS Development

      Wednesday, July 30, 2014

      Java Questions

      Does Java pass by reference or pass by value?

       

      Q: If Java uses the pass-by reference, why won't a swap function work?
      A: Java does manipulate objects by reference, and all object variables are references. However, Java doesn't pass method arguments by reference; it passes them by value.
      Take the badSwap() method for example:
      public void badSwap(int var1, int var2)
      {
        int temp = var1;
        var1 = var2;
        var2 = temp;
      }
      When badSwap() returns, the variables passed as arguments will still hold their original values. The method will also fail if we change the arguments type from int to Object, since Java passes object references by value as well. Now, here is where it gets tricky:
      public void tricky(Point arg1, Point arg2)
      {
        arg1.x = 100;
        arg1.y = 100;
        Point temp = arg1;
        arg1 = arg2;
        arg2 = temp;
      }
      public static void main(String [] args)
      {
        Point pnt1 = new Point(0,0);
        Point pnt2 = new Point(0,0);
        System.out.println("X: " + pnt1.x + " Y: " +pnt1.y); 
        System.out.println("X: " + pnt2.x + " Y: " +pnt2.y);
        System.out.println(" ");
        tricky(pnt1,pnt2);
        System.out.println("X: " + pnt1.x + " Y:" + pnt1.y); 
        System.out.println("X: " + pnt2.x + " Y: " +pnt2.y);  
      }
      If we execute this main() method, we see the following output:
      X: 0 Y: 0
      X: 0 Y: 0
      X: 100 Y: 100
      X: 0 Y: 0
      The method successfully alters the value of pnt1, even though it is passed by value; however, a swap of pnt1 and pnt2 fails! This is the major source of confusion. In the main() method, pnt1 and pnt2 are nothing more than object references. When you pass pnt1 and pnt2 to the tricky() method, Java passes the references by value just like any other parameter. This means the references passed to the method are actually copies of the original references. Figure 1 below shows two references pointing to the same object after Java passes an object to a method.


      Figure 1. After being passed to a method, an object will have at least two references
      Java copies and passes the reference by value, not the object. Thus, method manipulation will alter the objects, since the references point to the original objects. But since the references are copies, swaps will fail. As Figure 2 illustrates, the method references swap, but not the original references. Unfortunately, after a method call, you are left with only the unswapped original references. For a swap to succeed outside of the method call, we need to swap the original references, not the copies.


      Figure 2. Only the method references are swapped, not the original ones
      O'Reilly's Java in a Nutshell by David Flanagan (see Resources) puts it best: "Java manipulates objects 'by reference,' but it passes object references to methods 'by value.'" As a result, you cannot write a standard swap method to swap objects.


      Tony Sintes is a principal consultant at BroadVision. Tony, a Sun-certified Java 1.1 programmer and Java 2 developer, has worked with Java since 1997.
       
       
      Source: http://www.javaworld.com/article/2077424/learn-java/does-java-pass-by-reference-or-pass-by-value.html

       

      Thursday, June 12, 2014

      Largest Sum Contiguous Subarray

       Complexity is O(n)


      public static void kandealgo ()
          {
              int[] numbers = { -1, -2 };
              int max_so_far = 0;
              int max_end_here = 0;
      
              boolean allnegative = false;
              int max_negative_value = 0;
      
              for (int i = 0; i < (numbers.length); i++)
              {
                  if (numbers[i] > 0)
                  {
                      allnegative = true;
                  }
                  else
                  {
                      if (max_negative_value == 0 || max_negative_value < numbers[i])
                      {
                          max_negative_value = numbers[i];
                      }
      
                  }
      
                  max_end_here = max_end_here + numbers[i];
      
                  max_end_here = Math.max(max_end_here, 0);
                  max_so_far = Math.max(max_so_far, max_end_here);
              }
      
              if (!allnegative)
              {
                  System.out.println("All values are negative in array , and min value is " + max_negative_value);
              }
              else
              {
                  System.out.println("Max so far is " + max_so_far);
              }
          }

      Thursday, December 26, 2013

      Fix: SoapUI - 4.6.3 Test case

      If you have installed newer version of soapUI chances are it wont work with mac
      • Installation problems




      If your installed SoapUI instance on a Mac is not responsive, try the following steps to resolve the issue:
      1. In soapui-settings.xml file add or update the following line:
        true
      2. If that doesn't work, start SoapUI Pro with the following parameter added to the command line:
        -Dsoapui.jxbrowser.disable=true
      3. Alternatively, you can navigate to SoapUI*.app and do "Show Package Info" ( from popup menu ).
        Then you should see Contents directory. Open Info.plist file for editing where you can add:
        soapui.jxbrowser.disable
        true
      4. We have also seen some issues with SoapUI installs in Mac when GateKeeper is active. So to rule out that possible conflict, deactivate GateKeeper and try starting SoapUI

      Also if you want to change the look and feel of SoapUI or SoapUI Pro to look more like a Mac application, change the following settings:
      1. Go to File > Preferences > UI Settings tab
      2. Check "Use native look & feel"
      3. Restart SoapUI Pro

      Installing soapui

      Once you've downloaded the installer the installation is pretty strait forward. Start it by just double-clicking on it. After preparing the installation which takes only a few seconds you'll see the starting screen:
      mac-setup-start

      Just click Next to continue. You'll be asked to accept our license agreement

      mac-setup-soapui-lic-agreement

      After accepting and clicking Next you'll be able to select the destination folder which by default is set to /Applications but can be changed.
      mac-dest-install-folder

      Next step gives you opportunity to optionally include, as additional components, soapUI source files and Hermes installation.

      mac-install-components

      In case of installing soapUI Pro JDBC drivers jars can be included as additional option (and of course no source is available).

      mac-setup-wizard-select-comp-pro
      After that a window appears where you'll be asked to select if desktop icon should be created and if jxbrowser should be disabled. Starting from version soapUI 3.6-beta2 JxBrowser is working on mac, but there is still a issue left with  browser being always displayed on top if opened.
      mac-select-additional
      Finally, by clicking Next, the installation starts
      mac-setup-installing
      If you have chosen to install Hermes the installation will be triggered next, with it's own info and license agreement
      mac-start-hermes-installation
      mac-hermes-info
      mac-hermes-lic-agreement
      and choosing the destination
      mac-hermes-destination
      mac-hermes-pacs
      mac-hermes-listed
      mac-hermes-install
      mac-hermes-done

      After couple of minutes most the installation should be finished and you should see the next screen:
      mac-setup-wizard-finished
      Now you are ready to use it. Good luck!

      Wednesday, August 28, 2013

      Match Making Algorithm

      My friend is interviewing for Cerner Corporation and one of the questions asked was how will you design a match making algo for hospitals and students where

      Hospitals rank students as per their preference
      Students ranks hospitals as per their preference
      Number of positions in hospitals and number of students are equal so student will end up going in hospital.


      Given :

      Student1 ->  Hospital1 - 1(pref) , Hospital2(pref)
      Student 2 -> Hospital1 -1(pref) ,  Hospital2 (pref)

      Hospital1 -> Student2 - 1(pref), Student1 - 2(Pref)
      Hospital2 -> Student 1 - (pref) , Student 2 - 2 (pref)


      We need a list of hospitals in rank stating with super awesome to lower

      for each student
                         check preference in acceding order
                                        if hospital has space accommodate student
                                         else
                                         check the internal ranking for hospital and see if current student has higher preference
                                                    if so kick a student with lowest rank as per hospital list who still has got admission to his next best preference

                                                              if the second college is filled do that for same as above college
                           end the student loop

      The algo will be very well written recursively

      Tracing given example

      Hospital one = empty , Hospital 2 =  empty both having capacity of accommodating 1 Student each

      ----Student1 wants in Hospital 1 -> go for it

      ----Student 2 wants in Hospital 1 but Hospital 1 can only accommodate one student so checking internal list -> Student2 is more preferred so Student 1 has to go to Hospital 2

      Final Solution

      Hospital1 will have Student2
      Hospital2 will have Student1


      Algorithm is more biased to students as Students preferred list is first checked.

      Complexity of Algorithm would be O(n!) which is quite high probably someone can do it better.

      Please Comment will love to hear more about it.
                                                                

      Tuesday, March 5, 2013

      Carrer cup - 4th edition

      4.1
      Add arithmetic operators (plus, minus, times, divide) to make the following expression true: 3 1 3 6 = 8. You can use any parentheses you’d like. 

       Answer: +3 -1 +(-3+6) = 8


      9.2   The Game of Master Mind is played as follows:
      - The computer has four slots containing balls that are red (R), yellow (Y), green (G) or blue (B). For example, the computer might have RGGB (eg, Slot #1 is red, Slots #2 and #3 are green, #4 is blue).

      - You, the user, are trying to guess the solution. You might, for example, guess YRGB.

      - When you guess right color for the right slot, you get a “hit”. If you guess a color that exists but is in the wrong slot, you get a “psuedo-hit”. For example, the guess YRGB has 2 hits and one pseudo-hit.

      For each guess, you are told the number of hits and pseudo hits. Write a method that, given a guess and a solution, returns the number of hits and pseudo hits.

      public class carrercup_9_2 {

          void printHitsPseudohits(String solution, String guess)
          {
              int hits =0, psudohits = 0;
            
              int position = 0;
            
              for (int i=0;i        {
                
                  position = solution.indexOf(guess.substring(i, i+1));
                
                  if(position == i) //guess at same position as that of solution
                  {
                      hits++;
                  }
                
                  else if(position != -1) // guess charecter is there in solution somewhere
                  {
                      psudohits ++;
                  }
                
                  position = 0;//resetting position
              }
            
              System.out.println("For solution = "+solution +" and guess = "+guess +" hits = "+hits+" psudohits = "+psudohits);
          }
      }
       

      Monday, February 25, 2013

      DB2 to SQL Server conversion

      I have been working lately on converting native queries in Java project from DB2 to SQL.

      Apart from the date conversion one of the more tricky conversion was NEXTVALUE()  which had no equivalent in sql server 2008.


      So here is how I did it.

      Essentially we will create a table which wil have auto generated Ids that will supply us next value.
      
      
       Create table tableName ( [id] [int] IDENTITY(1,1) NOT NULL ON [PRIMARY]); 


      In order not to save ids in table created above we need to have stored procedure which will get id and roll back the transaction.

      
      CREATE procedure spName
      
       as
      
       begin     
      
      declare @id int     
      
      set NOCOUNT ON     
      
      insert into tableName default values     
      
      set @id = scope_identity()     
      
      delete from tableName WITH (READPAST)
      
      
      
      select @id as id
      
      
      
      end
      


      Additional links


      If you are using an identity column on your SQL Server tables, you can set the next insert value to whatever value you want. An example is if you wanted to start numbering your ID column at 1000 instead of 1.
      It would be wise to first check what the current identify value is. We can use this command to do so:
      
      
      DBCC CHECKIDENT (‘tablename’, NORESEED)
      For instance, if I wanted to check the next ID value of my orders table, I could use this command:
      
      
      DBCC CHECKIDENT (orders, NORESEED)
      To set the value of the next ID to be 1000, I can use this command:
      
      
      DBCC CHECKIDENT (orders, RESEED, 999)
      Note that the next value will be whatever you reseed with + 1, so in this case I set it to 999 so that the next value will be 1000.
      Another thing to note is that you may need to enclose the table name in single quotes or square brackets if you are referencing by a full path, or if your table name has spaces in it. (which it really shouldn’t)
      
      
      DBCC CHECKIDENT ( ‘databasename.dbo.orders’,RESEED, 999)

      Also calling stored procedure Seam project (Java) was a big task and has been accoplished in Entity class like code below:

      Declaration in Model/Entity class:
      
      
      import javax.persistence.NamedNativeQueries;
      
      import javax.persistence.NamedNativeQuery;
      
      import javax.persistence.SqlResultSetMapping;
      
      import javax.persistence.Table;
      
      
      
      
      
      @Entity
      
      
      
      @SqlResultSetMapping(name="mappingName", columns=@ColumnResult(name="id")) 
      
      @NamedNativeQueries({
      
                @NamedNativeQuery(name = NativeQueries.spName, 
      
                                query = NativeQueries.spName, 
      
                                hints={ @QueryHint(name = "org.hibernate.callable",value = "true"), @QueryHint(name = "org.hibernate.readOnly",value = "true")}, 
      
                                resultSetMapping = "mappingName")
      
                })
      
      

      Calling a Stored Procedure:

      
      
        if(entityManager == null) {
      
                  entityManager = (EntityManager)Component.getInstance("entityManager");
      
                  if(entityManager == null) {
      
                      log.fatal("entityManager is not available in seam context!");
      
                  }
      
              }
      
              Query query = entityManager.createNamedQuery(spName);
      
              NEXTNUMBER (Integer) query.getSingleResult();     
      
      
      
                               




      Thursday, January 10, 2013

      Recovering Windows key

      Have you ever wondered how much pain is it when u loose you product key. Windows 8 have 90 days free support where they can remotely access your computer and try to fix it.

      Well I was trying to install .net 3.5 for running  downward compatible programs but oh my got it was just in a loop.  I cant get key because I downloaded from my Academic institute and they just wont give me access.

      Well not deviating from my topic how to find product key here is how it worked for me

      Belarc Advisor: http://www.belarc.com/free_download.html
      (It does a good job of providing a wealth of information.)
      Also: http://www.magicaljellybean.com/keyfinder.shtml
      and: http://www.nirsoft.net/utils/product_cd_key_viewer.html
      and RockXP: http://www.majorgeeks.com/download4138.html which has additional features

      are the four utilities listed on (source: http://answers.microsoft.com/en-us/windows/forum/windows_8-windows_install/where-do-i-find-the-windows-8-product-key-when-it/d4c5c0c1-825d-47f2-9bed-d9625c7e68ff)

      Belarc Advisor didnt worked for me. :(

      But  http://www.magicaljellybean.com/keyfinder.shtml actually worked.

      Now I am gonna try my OS registry files and see but ya best of luck. :)

      Monday, January 7, 2013

      Changing WAR or adding time stamp to your war name for maven supported project

      Changing names for a maven project can be done in one to the two ways.

      Easy fix:

      The war name is same as artifact ID

          <groupId>com</groupId>
          <artifactId>ABC</artifactId>
          <version>0.0.1-SNAPSHOT    </version>
          <packaging>war</packaging>
      
      

      will generate ABC.WAR in target specified folder


      Other way:

      So in this senario I also want to attach dynamically generated timestamp to my war

      We will need to install plugin to generate time stamp as we want
       
                 <build>
                      <finalName>
                              ${project.artifactId}-${project.version}-${timestamp}
                      </finalName>
                      <plugins>
                          <plugin>
                              <groupId>
                                  com.keyboardsamurais.maven
                              </groupId>
                              <artifactId>
                                  maven-timestamp-plugin
                              </artifactId>
                              <version>
                                  1.0
                              </version>
                              <configuration>
                                  <propertyName>
                                      timestamp
                                  </propertyName>
                                  <timestampPattern>
                                          dd.MM.yyyy HH.mm
                                  </timestampPattern>
                              </configuration>
                              <executions>
                                  <execution>
                                      <goals>
                                          <goal>
                                              create
                                          </goal>
                                      </goals>
                                  </execution>
                              </executions>
                          </plugin>
                      </plugins>
                  </build>

      Should output: ABC-0.0.1-SNAPSHOT-07.01.2013 11.54.war

      Wednesday, October 3, 2012

      Adding database to Jboss-as-7

      So I was trying to add database configuration on my Jboss 7 server. So there are two modes for operation.
      • Standalone mode
      • Domain mode
      More documentation can be found here
      So download Jboss server from here and navigate to JBOSS_HOME/bin
      In order to connect:
      JBOSS_HOME/bin$ ./standalone.sh
      

      In order to disconnect: jboss
      JBOSS_HOME/bin$ ./jboss-cli.sh --connect --command=:shutdown 
      JBOSS_HOME/bin$ bin/jboss-cli.sh --connect command=:shutdown
      JBOSS_HOME/bin$ bin/jboss-cli.sh --connect :shutdown
      

      Copy your war file in JBOSS_HOME/standalone/deployments
      app_name.war.isdeploying 
      app_name.war.deployed
      app_name.war.failed
      

      There you go on terminal you will be able to see the logs for your current project
       Depending on your project configuration:
       INFO  [org.jboss.web] (MSC service thread 1-16) JBAS018210: Registering web context: /app_name
      

      Web browser : http://localhost:8080/app_name
      By default index.jsf,index.html will load default is configured in web.xml file

      In order to connect to database

      Step1: Copy jar connector in deployments folder

      Step2: Make changes in Jboss_Home/standalone/configuration/standalone.xml
                <datasources>
                      <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                          <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
                          <driver>h2</driver>
                          <security>
                              <user-name>sa</user-name>
                              <password>sa</password>
                          </security>
                      </datasource>
                      <datasource jndi-name="java:/name in persistant unit" pool-name="SqlServerDS_Pool" enabled="true" use-java-context="true">
                          <connection-url>jdbc:sqlserver://;databasename=</connection-url>
                          <driver>The Connector Jar you copied in deployments folder/driver>
                          <security>
                              <user-name>USER</user-name>
                              <password>*****</password>
                          </security>
                      </datasource>
                      <drivers>
                          <driver name="h2" module="com.h2database.h2">
                              <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                          </driver>
                      </drivers>
                  </datasources>
      

      Step 3 : Now you can reference data source from your app with JNDI lookup
      Example: persistence.xml
        
      <?xml version="1.0" encoding="UTF-8"?>
      <persistence version="2.0"
         xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="
              http://java.sun.com/xml/ns/persistence
              http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
      
          <persistence-unit name="primary">
            <jta-data-source>java:/name_in_standalone.xml</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.look_up for your server"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop" />
            
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="hibernate.default_schema" value="dbo"/>
             </properties>
         </persistence-unit>
      </persistence>
      
      

       In case for errors like

      
      Caused by: java.lang.NoClassDefFoundError: Lorg/slf4j/spi/LocationAwareLogger;
      
      Caused by: java.lang.ClassNotFoundException: org.slf4j.spi.LocationAwareLogger from [Module "org.jboss.logging:main" from local module loader @50988 (roots: /Users/tshah/Downloads/jboss-as-7.1.1.Final/modules)]
      
      
      Do make changes in JBOSS_HOME\modules\org\jboss\logging\main\module.xml
      Older version: 
      <module xmlns="urn:jboss:module:1.1" name="org.jboss.logging">
     <resources>
 
             <resource-root path="jboss-logging-3.1.0.GA.jar"/>
     
         <!-- Insert resources here -->
    </resources>
          <dependencies>
    
          <module name="org.jboss.logmanager"/>
  
        </dependencies>

      </module>
       
      Newer Version:
       
      <module xmlns="urn:jboss:module:1.1" name="org.jboss.logging">
    <resources>
     
         <resource-root path="jboss-logging-3.1.0.GA.jar"/>
      
            <!-- Insert resources here -->
    </resources>
            <dependencies>
       
            <module name="org.jboss.logmanager"/>
   
            <module name="org.slf4j" />
     
            <module name="org.apache.log4j" />
    
         </dependencies>
      
</module>
      

      Wednesday, September 26, 2012

      All about navigational flows - JSF 2.0

      Many tutorial online but most of them are JSF 1.2 and would not work as expected.
      Navigational output:
      Note: Please pay attention how URL changes
      Faces-config.xml this file is by default when you have your project supported with JavaServer Faces 2.0.

      If not you can have it by Project Properties Project Facets Check Javaserver Faces



      faces-config.xml
      <?xml version="1.0" encoding="UTF-8"?>
      
      <faces-config
          xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
       version="2.0">
       
       
      </faces-config>
      
      

      Navigation without bean Page1.xhtml Page2.xhtml without url change display
      Page1.xhtml
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"> 
      
      <h:head></h:head> 
      <body>
          <rich:panel>
              <f:facet name="header">
              Experimenting with JSP navigation
              </f:facet>
        <h:outputText value="This is Page 1" /> 
        <br />
        <br />
        <h:form>
         <h:commandButton action="Page2" id="Button1" value="Navigate to Page2"></h:commandButton>
        </h:form>
        <br />
        <br />
        <h:form>
         <h:commandButton action="Page2?faces-redirect=true" id="Button2" value="Navigate to Page2 with updatedURL"></h:commandButton>
        </h:form>
        <br />
        <br />
        <h:form>
         <h:commandButton action="#{testbean.navigate}" id="Button3" value="Navigate using Bean"></h:commandButton>
        </h:form>
        <br />
        <br />
        <h:form>
         <h:commandButton action="#{testbean.navigate_changeurl}" id="Button4" value="Navigate using Bean and updated URL"></h:commandButton>
        </h:form>
        
       </rich:panel>
      </body> 
      </html>
      

      Page2.xhtml
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
      <html xmlns="http://www.w3.org/1999/xhtml"
            xmlns:h="http://java.sun.com/jsf/html"
            xmlns:a4j="http://richfaces.org/a4j"
            xmlns:rich="http://richfaces.org/rich"
            xmlns:f="http://java.sun.com/jsf/core"
            xmlns:ui="http://java.sun.com/jsf/facelets"> 
      
      <h:head></h:head> 
      <body>
          <rich:panel>
              <f:facet name="header">
              Experimenting with JSP navigation
              </f:facet>
        <h:outputText value="This is Page 2" /> 
        
       </rich:panel>
      </body> 
      </html>
      

      TestBean.java
      import javax.enterprise.context.RequestScoped;
      import javax.faces.bean.*;
      
      @ManagedBean(name="testbean")
      @RequestScoped
      
      
      public class TestBean {
      
       public String navigate()
       {
        return "Page2";
       }
       
       public String navigate_changeurl()
       {
        return "Page2?faces-redirect=true";
       }
      }
      

      Tuesday, September 25, 2012

      Rich Faces 4.2.2 - Trying New Stuff

      Output on Jboss server:


      Ajax String Example:
      Client Side Code:
      <h:form id ="form1">
       <h:inputText value="#{testbean.name}">
        <a4j:ajax event="keyup" render="form2">
               </a4j:ajax>
       </h:inputText>
      </h:form>
         
      <h:form id = "form2">
       <h:outputText value="#{testbean.name}" />
      </h:form>
      
      

      Code for Backing Bean:
      
      import javax.enterprise.context.RequestScoped;
      import javax.faces.bean.*;
      @ManagedBean(name="testbean")
      @RequestScoped
      
      public class TestBean {
       private String name="tosha";
      
       public String getName() {
        return name;
       }
       public void setName(String name) {
        this.name = name;
       }
      }
      
      
      PickList:
      Client Side Code:
      <h:form>   
          <h:outputText value="Pick list Example"></h:outputText>      
                  <rich:pickList sourceCaption="Available" targetCaption="Selected" listWidth="165px" listHeight="100px" >
                    <!-- static list -->
          <f:selectItem itemLabel="Option 1" itemValue="1"/>
                    <f:selectItem itemLabel="Option 2" itemValue="2"/>
                    <f:selectItem itemLabel="Option 3" itemValue="3"/>
                   <f:selectItem itemLabel="Option 4" itemValue="4"/>
                    <f:selectItem itemLabel="Option 5" itemValue="5"/>
         
         <!-- Dynamic list from a backing bean -->
                   <f:selectItems value="#{listSelectBean.capitals}"/>
              </rich:pickList>   
      </h:form>
      
      Code for backing Bean:
      package com.trial;
      import javax.annotation.PostConstruct;
      import javax.faces.bean.ApplicationScoped;
      import javax.faces.bean.ManagedBean;
      import javax.faces.bean.ManagedProperty;
      import javax.faces.bean.RequestScoped;
      import java.util.ArrayList;
      import java.util.Iterator;
      import java.util.List;
       
      @ManagedBean(name="listSelectBean")
      @ApplicationScoped
      
      public class ListSelectBean {    
          private List capitals;
          private List selectedCapitals;
         
          public ListSelectBean() {
           capitals = new ArrayList();
           capitals.add("India");
           capitals.add("Australia");
           capitals.add("USA");
          }
       
          public List getCapitals() {
              return capitals;
          }
       
          public void setCapitals(List capitals) {
              this.capitals = capitals;
          }
       
          public List getSelectedCapitals() {
              return selectedCapitals;
          }
       
          public void setSelectedCapitals(List selectedCapitals) {
              this.selectedCapitals = selectedCapitals;
          }
      }
      
      Table Example:
      Client Side Code:
      <h:form>
       <rich:panel>
        <h:panelGrid columns="2">
         <a4j:commandButton value="+" action="#{bean.add}" render="list" />
         <a4j:commandButton value="-" action="#{bean.remove}" render="list" />
         </h:panelGrid>
         <rich:dataTable id="list" value="#{bean.list}" var="item"
          width="60px">
          <rich:column>
           <h:outputText value="#{item}" />
          </rich:column>
         </rich:dataTable>
        </rich:panel>
       </h:form>
       <h:form>
        <rich:panel>
         <h:panelGrid columns="2">
          <a4j:commandButton value="+" action="#{bean.add}" render="list" />
          <a4j:commandButton value="-" action="#{bean.remove}" render="list" />
         </h:panelGrid>
         <rich:dataTable id="list" value="#{bean.list}" var="item"
          width="60px">
          <rich:column>
          <h:outputText value="#{item}" />
         </rich:column>
        </rich:dataTable>
       </rich:panel>
      </h:form>
      
      Backing Bean Code:
      package com.trial;
      import javax.enterprise.context.RequestScoped;
      import javax.faces.bean.*;
      
      @ManagedBean(name="testbean")
      @RequestScoped
      
      
      public class TestBean {
       private String name="tosha";
      
       public String getName() {
        return name;
       }
      
       public void setName(String name) {
        this.name = name;
       }
      }
      

      Setting Hibernate Tool to Generate Entities - Part 1

      Object-relational mapping (ORM, O/RM, and O/R mapping) in computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools.

      Hibernate is a ORM database Tables Java Classes implies Rows in a Table Java Objects

      Step1:
      • Download and install hibernate Plugin from here along with many handy tools for JBoss
      Step2:
      • Create a Web Dynamic Project or you can go with Plain Java Project.
      Step 3:
      • Project New Other Hibernate Configuration File
      • Select your project/JavaSource
      • Fill in details about your database
      • Make sure you select Checkbox Create a console configuration
      • Finish
      You should get hibernate.cfg.xml
      Hibernate Configuration File Wizard
      Code (SQL Server):
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
      <hibernate-configuration>
          <session-factory name="">
              <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
              <property name="hibernate.connection.password">****</property>
              <property name="hibernate.connection.url">jdbc:sqlserver://servername;databaseName=YourDatabase</property>
              <property name="hibernate.connection.username">bhauser</property>
              <property name="hibernate.default_catalog">Make sure You know your Catlog for SQL Server</property>
              <property name="hibernate.default_schema">SchemaName</property>
              <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
          </session-factory>
      </hibernate-configuration>
      
      Step 4:
      • Project Properties Project Facets Enable JPA Apply Ok
      • It will take some time to install JPA
      • In Persistant management class Select Radio Button "Discover annotated class automatically"

      Step 5:
      This step is going to be setting up hibernate console. From Step 3 you already have hibernate console for your project.
      • Change Perspective to Hibernate
      • Now near you project explorer you must see Hibernate Configuration Pane.
      • Right Click on your Project configuration file and Edit



      All set to generate dynamic entities! :)