PDA

View Full Version : Visibility of bean properties?



getStringfromObject
Jun 14th, 2010, 05:12 AM
Hi,

I'm quite new to this stuff, so be nice. ^^

I'm trying to put through data of a bean into a jsp page. It's working fine with one exception - from the jsp page the id of the bean object doesn't seem to be visible.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="security" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
...
<table class="summary">
<thead>
<tr>
<th>Game</th>
<th>Player</th>
<th>Home</th>
<th>Away</th>
</tr>
</thead>
<tbody>
<c:forEach var="tipp" items="${tippsList}">
<tr>
<td>${tipp.game}</td>
<td>${tipp.player}</td>
<td>${tipp.home}</td>
<td>${tipp.away}</td>
</tr>
</c:forEach>
</tbody>
</table>

The above works perfectly fine.
But when I try to add

<td>${tipp.tippid}</td>
I get the following error:

javax.el.PropertyNotFoundException: Property 'tippid' not found on type org.springframework.webflow.wc.Tipps

Here is the Class Tipps:

package org.springframework.webflow.wc;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "tipps")
public class Tipps implements Serializable {

private int TippID;

private String Player;

private int Game;

private int Home;

private int Away;

@Id
@GeneratedValue
@Column(name = "TippID")
public int getTippID() {
return TippID;
}

public void setTippID(int tippID) {
TippID = tippID;
}

public String getPlayer() {
return Player;
}

public void setPlayer(String player) {
Player = player;
}

public int getGame() {
return Game;
}

public void setGame(int game) {
Game = game;
}

public int getHome() {
return Home;
}

public void setHome(int home) {
Home = home;
}

public int getAway() {
return Away;
}

public void setAway(int away) {
Away = away;
}

@Override
public String toString() {
return "Tipps(" + TippID + "," + Player + "," + Game + "," + Home + "," + Away + ")";
}

}

Is it just a coincidence that the one attribute that doesn't go through is the primary key?



Thanks in advance. :)

Hetal B
Jun 14th, 2010, 06:08 AM
Hi,

Can you please elaborate how are you passing the tipsList onto the jsp?

-Hetal

Marten Deinum
Jun 14th, 2010, 06:26 AM
I suggest a read on the javabeans specifications.

There is no property named 'tippid' in your class.. There is a property named 'tippID'.

getStringfromObject
Jun 14th, 2010, 10:48 AM
Thanks for your answers.

@Hetal B: I'm passing the TippsList through a Controller which accesses a Service Class.


@RequestMapping(value = "/registration", method = RequestMethod.GET)
public void search(Principal currentUser, Model model) {
if (currentUser != null) {
List<Tipps> tipps = tippsService.findTipps();
model.addAttribute(tipps);
}
}
Method in the Service Class:

@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<Tipps> findTipps() {
Query query = em.createQuery("SELECT e FROM Tipps e");
List<Tipps> lt = query.getResultList();
return lt;

}

@Marten Deinum:
I've tried several versions, among them one which gets this error:

javax.el.PropertyNotFoundException: Property 'TippID' not found on type org.springframework.webflow.wc.Tipps
Crazy thing is it seems to work with all the other properties but not with the id...
So I thought maybe it's something about the primary key.

Thanks for any help.

getStringfromObject
Jun 14th, 2010, 10:53 AM
Sorry, I just figured it out when I reread the posting from Martin Deinum.

So bean properties always start with a lower letter. Now I'm embarressed. :(

Thanks for the answer though. :D