Announcement Announcement Module
Collapse
No announcement yet.
Error displaying data from Mysql (Spring security, webflow, jsf 2) Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error displaying data from Mysql (Spring security, webflow, jsf 2)

    Hi everybody!! i was developing an example on how to retrieve some data from mysql server using spring webflow and rendering the data in jsf page.

    the problem is at the render moment in web page. it throws this error in stacktrace:

    javax.el.ELException: /WEB-INF/flows/ehcache/exampleform.xhtml @24,52 value="#{userDetails.address}": Cannot convert address of type class java.lang.String to class java.lang.Integer
    at com.sun.faces.facelets.el.TagValueExpression.getVa lue(TagValueExpression.java:114)

    here is my files:

    FLOW.XML
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"
    	parent="parent-flow">
    	<!--
    		Also see ../parent-flow.xml. 
    	-->
    	<secured attributes="ROLE_USER" />
    	<on-start>
    		<evaluate expression="userDetailsService.findDatabByUserName(currentUser.name)" result="flowScope.userDetails" />
    	</on-start>
    	<view-state id="exampleform"  model="UserDetails">	
    		<transition on="logout" to="endAndLogout"/>
    	</view-state>	
    	<end-state id="endAndLogout" view="externalRedirect:servletRelative:/logout?activeTab=springSecurity" />
    
    </flow>
    USERDETAILS.JAVA
    Code:
    package com.spring.examples;
     
    import java.io.Serializable;
    
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.Id;
    
    @Entity (name="user_profile")
    public class UserDetails implements Serializable {
    
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 2773048431812678156L;
    	
    	private long id;
    	private String user_login;
    	private String user_name;
    	private String address;
    	private String phone;
    	
    	//Getters and Setters
    	
    	@Id
        @GeneratedValue
    	public long getId() {
    		return id;
    	}
    	public void setId(long id) {
    		this.id = id;
    	}
    	public String getUser_login() {
    		return user_login;
    	}
    	public void setUser_login(String user_login) {
    		this.user_login = user_login;
    	}
    	public String getUser_name() {
    		return user_name;
    	}
    	public void setUser_name(String user_name) {
    		this.user_name = user_name;
    	}
    	public String getAddress() {
    		return address;
    	}
    	public void setAddress(String address) {
    		this.address = address;
    	}
    	public String getPhone() {
    		return phone;
    	}
    	public void setPhone(String phone) {
    		this.phone = phone;
    	}
    }
    JPAUSERDETAILS.JAVA
    Code:
    package com.spring.examples;
    
    import java.io.Serializable;
    import java.util.List;
    
    import javax.persistence.EntityManager;
    import javax.persistence.PersistenceContext;
    
    import org.springframework.stereotype.Repository;
    import org.springframework.stereotype.Service;
    import org.springframework.transaction.annotation.Transactional;
    
    
    	@Service("userDetailsService")
    	@Repository
    	public class JpaUserDetails implements UserDetailsInterface, Serializable {
    
    	    private static final long serialVersionUID = 1L;
    	    
    	    private EntityManager em;
    
    	    @PersistenceContext
    	    public void setEntityManager(EntityManager em) {
    		this.em = em;
    	    }
    
    	    /**/
    	    
    	    
    	    @Transactional(readOnly = true)
    	    @SuppressWarnings("unchecked")
    	   
    	    public List<UserDetails> findDatabByUserName(String username) {
    	    	
    	    	if (username != null) {
    	    		
    			    return em.createQuery("select user_name, phone, address from user_profile WHERE user_name = :username")
    				    .setParameter("username", username).getResultList();
    			} else {
    			    return null;
    			}
    	    }
    	}
    EXAMPLEFORM.XHTML

    Code:
    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
    	    		xmlns:ui="http://java.sun.com/jsf/facelets"
    				xmlns:c="http://java.sun.com/jsp/jstl/core"
    	  			xmlns:h="http://java.sun.com/jsf/html"
    	  			xmlns:p="http://primefaces.org/ui"
    	  			xmlns:f="http://java.sun.com/jsf/core"
    	  			xmlns:sec="http://www.springframework.org/security/tags"
    	  			template="/WEB-INF/layouts/standard.xhtml">
    
    <ui:define name="title">You are in Secure View</ui:define>
    
    
    
    <ui:define name="content">
    	<p class="alt">
        	Main Page
        	You're currently logged in as '${currentUser.name}' <!-- this works fine -->
        
    	</p>
    <h:panelGrid id="usrLogName" columns="2" border="2">
    							<h:outputText value="User Login Name :"></h:outputText>
    							
    					<h:outputText value="#{userDetails.address}"/> <!-- this is the example that cannot render -->
    					<!-- already tried with '${userDetails.address}' and it failed -->
    							
    					
    						</h:panelGrid>
    
    		<h:form>
    	    <p:commandButton value="Logout" action="logout"/>
    	    <p:commandButton value="Exit" action="exit"/>   
    	</h:form>
    
    </ui:define>
    
    </ui:composition>
    BEAN PROPERTY TO ACCESS DATABASE
    Code:
    	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost/test" />
    		<property name="username" value="root" />
    		<property name="password" value="password" />
    	</bean>
    MYSQL DATABASE QUERY
    Code:
    CREATE DATABASE  IF NOT EXISTS `test` /*!40100 DEFAULT CHARACTER SET latin1 */;
    USE `test`;
    -- MySQL dump 10.13  Distrib 5.5.16, for Win32 (x86)
    --
    -- Host: localhost    Database: test
    -- ------------------------------------------------------
    -- Server version	5.5.27
    
    /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
    /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
    /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
    /*!40101 SET NAMES utf8 */;
    /*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
    /*!40103 SET TIME_ZONE='+00:00' */;
    /*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
    /*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
    /*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
    /*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
    
    --
    -- Table structure for table `user_profile`
    --
    
    DROP TABLE IF EXISTS `user_profile`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `user_profile` (
      `id` int(11) NOT NULL,
      `user_name` varchar(45) DEFAULT NULL,
      `user_login` varchar(45) DEFAULT NULL,
      `phone` varchar(45) DEFAULT NULL,
      `address` varchar(45) DEFAULT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `user_profile`
    --
    
    LOCK TABLES `user_profile` WRITE;
    /*!40000 ALTER TABLE `user_profile` DISABLE KEYS */;
    INSERT INTO `user_profile` VALUES (1,'Freddy','admin','444444','venture av. 34'),(2,'Alex','user','88888','longton st. 567');
    /*!40000 ALTER TABLE `user_profile` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `users`
    --
    
    DROP TABLE IF EXISTS `users`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `users` (
      `USER_ID` int(10) unsigned NOT NULL,
      `USERNAME` varchar(45) NOT NULL,
      `PASSWORD` varchar(45) NOT NULL,
      `ENABLED` tinyint(1) NOT NULL,
      PRIMARY KEY (`USER_ID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `users`
    --
    
    LOCK TABLES `users` WRITE;
    /*!40000 ALTER TABLE `users` DISABLE KEYS */;
    INSERT INTO `users` VALUES (100,'user','123456',1);
    /*!40000 ALTER TABLE `users` ENABLE KEYS */;
    UNLOCK TABLES;
    
    --
    -- Table structure for table `user_roles`
    --
    
    DROP TABLE IF EXISTS `user_roles`;
    /*!40101 SET @saved_cs_client     = @@character_set_client */;
    /*!40101 SET character_set_client = utf8 */;
    CREATE TABLE `user_roles` (
      `USER_ROLE_ID` int(10) unsigned NOT NULL,
      `USER_ID` int(10) unsigned NOT NULL,
      `AUTHORITY` varchar(45) NOT NULL,
      PRIMARY KEY (`USER_ROLE_ID`),
      KEY `FK_user_roles` (`USER_ID`),
      CONSTRAINT `FK_user_roles` FOREIGN KEY (`USER_ID`) REFERENCES `users` (`USER_ID`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
    /*!40101 SET character_set_client = @saved_cs_client */;
    
    --
    -- Dumping data for table `user_roles`
    --
    
    LOCK TABLES `user_roles` WRITE;
    /*!40000 ALTER TABLE `user_roles` DISABLE KEYS */;
    INSERT INTO `user_roles` VALUES (1,100,'ROLE_USER');
    /*!40000 ALTER TABLE `user_roles` ENABLE KEYS */;
    UNLOCK TABLES;
    /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
    
    /*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
    /*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
    /*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
    
    -- Dump completed on 2012-08-12  0:43:55
    please anybody can help me???
    THANKSSSS

  • #2
    any suggestions?

    thanks!

    Comment

    Working...
    X