Simple ui with second ManagedBean fails

UI Components for JSF
Post Reply
dbac2002
Posts: 3
Joined: 17 May 2016, 21:34

17 May 2016, 21:45

Hi,

this is my first post here and my first baby steps with primeface, so please let me know if I have missed any important things.

I try to learn Primefaces and build a simple Ui for the beginning - I use Primefaces 3.3 and jsf 2.1.11 and jstl 1.2

I have the two following bean classes

Code: Select all

public class Player {
	private String name;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
}

Code: Select all

public class Achievement {
	private String title;

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
}
Then I have my two ManagedBeans for them

Code: Select all

@ManagedBean(name = "achievements")
public class AchievementService {
	private final Set<Achievement> achievements = new HashSet<>();

	@PostConstruct
	public void init() {
		final Achievement ac = new Achievement();
		ac.setTitle("Achievement Hurray");
		achievements.add(ac);
	}

	public Set<Achievement> getAchievements() {
		return achievements;
	}
}

Code: Select all

@ManagedBean(name = "players")
public class PlayerService {
	private final List<Player> players = new ArrayList<>();

	@PostConstruct
	public void init() {
		final Player e = new Player();
		e.setName("dbac");
		players.add(e);
	}

	public List<Player> getPlayers() {
		return players;
	}
}
and my index.xhtml which is used is

Code: Select all

<h:body>
	<h:form>
		<p:tabView dynamic="true" cache="true">
			<p:tab title="Players">
				<h:panelGrid columns="2" cellpadding="10">
					<p:dataTable var="player" value="#{players.players}">
						<p:column headerText="Name">
							<h:outputText value="#{player.name}" />
						</p:column>
					</p:dataTable>
					<p:dataTable var="ac" value="#{achievements.achievements}">
						<p:column headerText="Title">
							<h:outputText value="#{ac.title}" />
						</p:column>
					</p:dataTable>
				</h:panelGrid>
			</p:tab>
		</p:tabView>
	</h:form>
</h:body>
Deploying this on tomcat 8, brings the following error message:

/index.xhtml @24,44 value="#{ac.title}": Property 'title' not found on type java.util.Collections$UnmodifiableSet

when I comment the second dataTable out, it works. If I comment out the first dataTable, it is again not working.

Why is the second "Achievement" not working, what do I miss ? I have the feeling its a minor thing and I'm simply blind

Thanks for any hints

tandraschko
PrimeFaces Core Developer
Posts: 3979
Joined: 03 Dec 2010, 14:11
Location: Bavaria, DE
Contact:

18 May 2016, 09:39

try a list instead set.
Thomas Andraschko

PrimeFaces | PrimeFaces Extensions

Apache Member | OpenWebBeans, DeltaSpike, MyFaces, BVal, TomEE

Sponsor me: https://github.com/sponsors/tandraschko
Blog: http://tandraschko.blogspot.de/
Twitter: https://twitter.com/TAndraschko

dbac2002
Posts: 3
Joined: 17 May 2016, 21:34

18 May 2016, 10:15

That helped :)

Thanks for the answer.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: Google [Bot] and 30 guests