Display tag prefix and spring webflow - spring-webflow

I am working on an interface using Spring web flow.
I have this [B]uebersicht.xhtml[/B]
<!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:display="http://displaytag.sf.net"
xmlns:h="http://java.sun.com/jsf/html"
template="/WEB-INF/layouts/standard.xhtml">
<ui:define name="content">
<h:dataTable value="#{arrayVar}" var="conv">
<h:column>
<h:outputText value="#{conv.id}"/>
</h:column>
</h:dataTable>
<div>
<div>
Table:
<display:table id="row" name="arrayVar" pagesize="3" requestURI="/spring/uebersicht">
<display:column title="row number" sortable="true" sortName="rowNum">
<h:outputText value="${row_rowNum}"/>
</display:column>
<display:column title="name" sortable="true" sortName="name">
<h:outputText value="${row.id}"/>
</display:column>
</display:table>
</div>
</div>
</ui:define>
</ui:composition>
arrayVar is the variable where I save the value from an action on one flow:
<on-start>
<evaluate expression="databaseActionsBean.getArrayVar()" result="flowScope.arrayVar " />
</on-start>
Using the first example, I get the values that I need. But I want to use displayTag, so I built this java class:
#Controller
#RequestMapping(value="/spring/uebersicht")
public class UebersichtController {
private DatabaseActionsBean databaseActionsBean = new DatabaseActionsBean();
#RequestMapping(method = RequestMethod.GET)
public String conversationsToShow(Model model) {
model.addAttribute("arrayVar", databaseActionsBean.getStoppedConversations());
return "uebersicht";
}
}
But the second table does not give me any result, and I can see this warning message
Warning: This page calls for XML namespace http://displaytag.sf.net
declared with prefix display but no taglibrary exists for that
namespace.
What could be the problem?
I include the pom dependencies:
<!--Display tag-->
<dependency>
<groupId>displaytag</groupId>
<artifactId>displaytag</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl104-over-slf4j</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
Thanks in advance

Related

Seam pageflow example NumberGuess Not landing on to the second page

I'm trying to run simple Seam PageFlow example NumberGuss. I have deployed it on Jboss Server. When I access the URL it lands on the first page but if I hit any of the button provided on that page it says "The page isn't redirecting properly".On server log I found
SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (default task-16) Error Rendering View[/debug.xhtml]: org.jboss.weld.context.NonexistentConversationException: WELD-000321: No conversation found to restore for id 1.
I'm using wildfly-8.1.0 and jboss-seam-2.3.1
Attaching pageflow.jpdl.xml and numberGuess.xhtml for reference. Please help me resolve the issue I'm facing.
<!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:f="http://java.sun.com/jsf/core"
xmlns:s="http://jboss.org/schema/seam/taglib">
<h:head>
<title>Guess a number...</title>
<link href="niceforms.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript" src="niceforms.js"><!-- --></script>
</h:head>
<body>
<h1>Guess a number...</h1>
<h:form id="NumberGuessMain" styleClass="niceform">
<div>
<h:messages id="messages" globalOnly="true"/>
<h:outputText id="Higher"
value="Higher!"
rendered="#{numberGuess.randomNumber gt numberGuess.currentGuess}"/>
<h:outputText id="Lower"
value="Lower!"
rendered="#{numberGuess.randomNumber lt numberGuess.currentGuess}"/>
</div>
<div>
I'm thinking of a number between <h:outputText id="Smallest" value="#{numberGuess.smallest}"/> and
<h:outputText id="Biggest" value="#{numberGuess.biggest}"/>. You have
<h:outputText id="RemainingGuesses" value="#{numberGuess.remainingGuesses}"/> guesses.
</div>
<div>
Your guess:
<h:inputText id="inputGuess" value="#{numberGuess.currentGuess}" required="true" size="3"
rendered="#{(numberGuess.biggest-numberGuess.smallest) gt 20}">
<f:validateLongRange maximum="#{numberGuess.biggest}"
minimum="#{numberGuess.smallest}"/>
</h:inputText>
<h:selectOneMenu id="selectGuessMenu" value="#{numberGuess.currentGuess}" required="true" rendered="#{numberGuess.selectMenuRendered}">
<s:selectItems id="PossibilitiesMenuItems" value="#{numberGuess.possibilities}" var="i" label="#{i}"/>
</h:selectOneMenu>
<h:selectOneRadio id="selectGuessRadio" value="#{numberGuess.currentGuess}" required="true" rendered="#{numberGuess.radioButtonRendered}">
<s:selectItems id="PossibilitiesRadioItems" value="#{numberGuess.possibilities}" var="i" label="#{i}"/>
</h:selectOneRadio>
<h:commandButton id="GuessButton" value="Guess" action="guess"/>
<s:button id="CheatButton" value="Cheat" action="cheat"/>
<s:button id="GiveUpButton" value="Give up" action="giveup"/>
</div>
<div>
<h:message id="message" for="inputGuess" style="color: red"/>
</div>
</h:form>
</body>
</html>
<!--
An example of pageflow in jPDL. This exemplifies the
approach where action handlers are attached transitions
and decision nodes, instead of view components.
An alternative approach would be to attach all action
handlers to view components, and let the jPDL define
only the navigation rules.
-->
<pageflow-definition
xmlns="http://jboss.org/schema/seam/pageflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://jboss.org/schema/seam/pageflow http://jboss.org/schema/seam/pageflow-2.3.xsd"
name="numberGuess">
<start-page name="displayGuess" view-id="/numberGuess.xhtml">
<redirect/>
<transition name="guess" to="evaluateGuess">
<action expression="#{numberGuess.guess}"/>
</transition>
<transition name="giveup" to="giveup"/>
<transition name="cheat" to="cheat"/>
</start-page>
<decision name="evaluateGuess" expression="#{numberGuess.correctGuess}">
<transition name="true" to="win"/>
<transition name="false" to="evaluateRemainingGuesses"/>
</decision>
<decision name="evaluateRemainingGuesses" expression="#{numberGuess.lastGuess}">
<transition name="true" to="lose"/>
<transition name="false" to="displayGuess"/>
</decision>
<page name="giveup" view-id="/giveup.xhtml">
<redirect/>
<transition name="yes" to="lose"/>
<transition name="no" to="displayGuess"/>
</page>
<process-state name="cheat">
<sub-process name="cheat"/>
<transition to="displayGuess"/>
</process-state>
<page name="win" view-id="/win.xhtml">
<redirect/>
<end-conversation/>
</page>
<page name="lose" view-id="/lose.xhtml">
<redirect/>
<end-conversation/>
</page>
</pageflow-definition>
Resolved the issue.Weld is scanning the archive, which seems to cause the problem.The Weld Docs says:
You can either set this up for your deployment only by adding the following content to the META-INF/jboss-all.xml file of your application.
jboss-all.xml file goes to your META-INF for ear archive and likely to WEB-INF for war archive
<jboss xmlns="urn:jboss:1.0">
<weld xmlns="urn:jboss:weld:1.0" require-bean-descriptor="true"/>
</jboss>
It worked for me.

Using SPRING_SECURITY_LAST_USERNAME in a Thymeleaf template

I've got a login form rendered by ThymeLeaf and powered by Spring Security. If an authentication error occurs, I'd like the username field to be pre-populated with the value the user entered on their previous attempt. Spring Security provides SPRING_SECURITY_LAST_USERNAME for that purpose, but my searches of the documentation and online don't turn up how to expose that via ThymeLeaf. Below are simplified versions of the relevant files:
My security XML file:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:sec="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<sec:http auto-config="true">
<sec:intercept-url pattern="/login/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<sec:form-login login-page="/login" authentication-failure-url="/login/fail" default-target-url="/"/>
<sec:logout />
</sec:http>
<sec:global-method-security secured-annotations="enabled"/>
</beans>
login.html:
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head th:include="template::head"></head>
<body class="login">
<nav th:include="template::nav"></nav>
<div>
<h2>Log in</h2>
<div>
<div th:if="${loginFail}" class="error">
Username/password incorrect.
</div>
<form id="login" th:action="#{/j_spring_security_check}" method="POST">
<dl>
<dt>Username</dt>
<dd><input type="text" id="j_username" name="j_username" />#mshare.net</dd>
<dt>Password</dt>
<dd><input type="password" id="j_password" name="j_password" /></dd>
</dl>
<input type="submit" value="Log in" />
</form>
</div>
</div>
</body>
</html>
Controller error handler:
#RequestMapping(value = "/login/fail")
public String loginError(Model model) {
model.addAttribute("loginFail", Boolean.TRUE);
return "login";
}

Using Expression Language with Tiles + Spring MVC

If inside a controller I set
model.addAttribute("page-title", "Home");
and I would like to have it on a tiles laytou.jsp like this:
<title><tiles:getAsString name="page-title"/></title>
what should I do?
Write a preparer?
to the preparer de put-attribute definition doesn't matter so looks like it makes no sense.
Just add a <put-attribute name="page-title" value="${page-title}"/>
into definition?
When I do this I just get "${page-title} - My Website" as output. EL is not been evaluated.
So please, what's the best practice and how to make it work?
tiles-defs.xml:
<tiles-definitions>
<definition name="baseLayout" template="/WEB-INF/pages/common/layout.jsp">
<put-attribute name="website-title" value="My Website"/>
<put-attribute name="page-title" expression="Default Title"/>
<put-attribute name="header" value="/WEB-INF/pages/common/header.jsp"/>
<put-attribute name="body" value=""/>
<put-attribute name="footer" value="/WEB-INF/pages/common/footer.jsp"/>
</definition>
<definition name="*" extends="baseLayout">
<put-attribute name="page-title" value="${page-title}"/>
<put-attribute name="body" value="/WEB-INF/pages/{1}.jsp"/>
</definition>
</tiles-definitions>
layout.jsp:
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%# taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%# taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="language" content="English" />
<title><tiles:getAsString name="page-title"/> - <tiles:getAsString name="website-title"/></title>
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/css/style.css" />" media="all"/>
</head>
<body>
<div id="container">
<!-- header -->
<tiles:insertAttribute name="header"/>
<!-- main central container -->
<tiles:insertAttribute name="body"/>
<!-- footer -->
<tiles:insertAttribute name="footer"/>
</div>
</body>
</html>
homeController.java:
#Controller
public class HomeController {
#RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView home(Locale locale, Model model) {
ModelAndView mav = new ModelAndView();
mav.setViewName("home");
model.addAttribute("page-title", "Home");
return mav;
}
}
servlet-context.xml:
<beans:bean id="tilesviewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver" p:order="0"/>
<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions" value="/WEB-INF/tiles/tiles-defs.xml"/>
</beans:bean>
pom.xml:
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-el</artifactId>
<version>2.2.2</version>
</dependency>
Just use pure EL without Tiles. Model attributes are placed on request as attributes (HttpServletRequest#getAttribute) under their name. This is accessible via requestScope['page-title'] or just simply by attribute name itself:
<title><c:out value="${page-title}" /></title>
<title>${page-title} - without HTML escaping provided by c:out</title>
This has nothing to do with Tiles. You don't need to take Tiles into account when working with model / request attributes.
Pavei is right, in your use case it's not obvious why you need to put the request attribute in as a tiles attribute.
If you really do need it as a tiles attribute then do it like
<put-attribute name="page-title" expression="${page-title}"/>
My English is poor. And I haven't use tiles2.x in my project, I use tiles3.x. If you want to use expression language support, first you should enable CompleteAutoloadTilesContainerFactory.
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-defs.xml</value>
</list>
</property>
<!--enable CompleteAutoloadTilesContainerFactory -->
<property name="completeAutoload" value="true"></property>
</bean>
then you have to configure defintions like this .
<definitions name="*" extends="baseLayout">
<put-attribute name="page-title" expression="${page-title}" />
<put-attribute name="body" value="/WEB-INF/pages/{1}.jsp" />
</definitions>
Tiles Document https://tiles.apache.org/framework/tutorial/advanced/el-support.html
Good luck to you .
Let's recap:
The EL language is supported since Tiles 2.1 without extra configuration.
If we use Tiles 3.x, we should:
Adding this dependency to pom:
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.5</version>
</dependency>
Enabling CompleteAutoloadTilesContainerFactory:
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles/tiles-defs.xml</value>
</list>
</property>
<!--enable CompleteAutoloadTilesContainerFactory -->
<property name="completeAutoload" value="true"></property>
</bean>

Question about spring #ModelAttribute taking any arbitrary string

While taking lessons in spring3 I coded a sample from a tutorial. I created a controller as below
package my.spring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import my.spring.form.Contact;
#Controller
public class ContactController {
#RequestMapping(value ="/addContact",method =RequestMethod.POST)
public String addContact(#ModelAttribute("contact") Contact ct){
System.out.println("First Name:" + contact.getFirstname() + "Last Name:" + contact.getLastname());
return "redirect:contacts.htm";
}
#RequestMapping("/contacts")
public ModelAndView showContacts() {
System.out.println("showing contacts");
return new ModelAndView("contact", "userEntries", new Contact());
}
}
Then I decided to play around with it and modified the #ModelAttribute in method parameter from
public String addContact(#ModelAttribute("contact") Contact ct)
to
public String addContact(#ModelAttribute("somevalue") Contact ct)
Still I couldn't find any change in behaviour of the application. This was a bit of surprise for me. As I understood, the data from form is collected in a Contact object and using #ModelAttribute that object is bound to the parameter ct. This parameter is then used to process inside the method.
Is it that the actual string used inside #ModelAttribute( ) doesn't matter?
Here is the WEB-INF/jsp/contact.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%#taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Contact Manager</title>
</head>
<body>
<h2>Contact Manager</h2>
<form:form action="addContact.htm" commandName="userEntries">
<table>
<tr>
<td>
<form:label path="firstname">First Name</form:label>
</td>
<td>
<form:input path="firstname"/>
</td>
</tr>
<tr>
<td>
<form:label path="lastname">Last Name</form:label>
</td>
<td>
<form:input path="lastname"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="Add Contact"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
and the spring servlet configuration
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation=
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<mvc:annotation-driven/>
<context:component-scan base-package="my.spring.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
Finally, the index.jsp forwards to contacts
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>my index</title>
</head>
<body>
<jsp:forward page="contacts.htm"></jsp:forward>
</body>
</html>
It will be used for mapping the model attribute to the form:
<form:form modelAttribute="myObject">
</form>
You will have to use
public String controllerMethod(#ModelAttribute("myObject") Object obj){
....
}
If you don't use the same value in both model attribute values you won't be able to see the error messages of the validation (when doing in the controller result.rejectValue and in the jsp <form:errors/> tag).
There are no differences to populate the values from the form in the object because you can use html tags instead of spring tags, and in the html tags you only have the name attribute to map the value.
In case you use #ModelAttribute in a method like below, you will insert in the model an attribute named "myObject" with value the object returned. This is another feauture of this annotation and it will be invoked before any method of the controller.
#ModelAttribute("myObject") Object obj
public Object method(){
...
return obj;
}

seam page parameters not working as expected

I am learning seam and following a book Seam In Action by Dan Allen.
This is an example from this book.
Seam 2.2.0.GA
JBoss 5.1.0.GA
Here the page parameter roundId is always null even after a round is serialized, it is never passed. Neither to Roud.xhtml nor to RoundEdit.xhtml after clicking save on RoundEdit.xhtml. The entity always stays unmanaged.
RoundEdit.page.xml
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"
login-required="true">
<begin-conversation join="true" />
<param name="roundId" value="#{roundHome.id}" converterId="javax.faces.Long"/>
<param name="teeSetId" value="#{teeSetHome.teeSetId}" />
<param name="roundFrom" />
<action execute="#{roundHome.wire}" />
<navigation from-action="#{roundHome.persist}">
<rule if-outcome="persisted">
<end-conversation/>
<redirect view-id="#{null != roundFrom ? roundFrom : '/Round.xhtml'}" />
</rule>
</navigation>
</page>
RoundEdit.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="roundform">
<rich:panel>
<f:facet name="header>">
#{roundHome.managed ? 'Edit' : 'Add' } Round
</f:facet>
<s:decorate id="dateField" template="layout/edit.xhtml">
<ui:define name="label">Date:</ui:define>
<rich:calendar id="date" datePattern="dd/MM/yyyy" value="#{round.date}"/>
</s:decorate>
<s:decorate id="notesField" template="layout/edit.xhtml">
<ui:define name="label">Notes:</ui:define>
<h:inputTextarea id="notes" cols="80" rows="3" value="#{round.notes}" />
</s:decorate>
<s:decorate id="totalScoreField" template="layout/edit.xhtml">
<ui:define name="label">Total Score:</ui:define>
<h:inputText id="totalScore" value="#{round.totalScore}" />
</s:decorate>
<s:decorate id="weatherField" template="layout/edit.xhtml">
<ui:define name="label">Weather:</ui:define>
<h:selectOneMenu id="weather" value="#{round.weather}">
<s:selectItems var="_weather" value="#{weatherCategories}" label="#{_weather.label}"
noSelectionLabel=" Select " />
<s:convertEnum/>
</h:selectOneMenu>
</s:decorate>
<h:messages/>
<div style="clear: both;">
<span class="required">*</span> required fields
</div>
</rich:panel>
<div class="actionButtons">
<h:commandButton id="save" value="Save"
action="#{roundHome.persist}"
rendered="#{!roundHome.managed}"
disabled="#{!roundHome.wired}" />
<h:commandButton id="update" value="Update" action="#{roundHome.update}"
rendered="#{roundHome.managed}" />
<h:commandButton id="delete" value="Delete" action="#{roundHome.remove}"
rendered="#{roundHome.managed}" />
<s:button id="discard" value="Discard changes" propagation="end"
view="/Round.xhtml" rendered="#{roundHome.managed}" />
<s:button id="cancel" value="Cancel" propagation="end"
view="/#{empty roundFrom ? 'RoundList' : roundFrom}.xhtml"
rendered="#{!roundHome.managed}" />
</div>
<rich:tabPanel>
<rich:tab label="Tee Set">
<div class="association">
<h:outputText value="Tee set not selected" rendered="#{round.teeSet == null}" />
<rich:dataTable var="_teeSet" value="#{round.teeSet}" rendered="#{round.teeSet != null}">
<h:column>
<f:facet name="header">Course</f:facet>#{_teeSet.course.name}
</h:column>
<h:column>
<f:facet name="header">Color</f:facet>#{_teeSet.color}
</h:column>
<h:column>
<f:facet name="header">Position</f:facet>#{_teeSet.pos}
</h:column>
</rich:dataTable>
</div>
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
Round.page.xml
<?xml version="1.0" encoding="UTF-8"?>
<page xmlns="http://jboss.com/products/seam/pages"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd">
<param name="roundId" value="#{roundHome.id}" converterId="javax.faces.Long"/>
</page>
Round.xhtml
<?xml version="1.0" encoding="UTF-8"?>
<!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:s="http://jboss.com/products/seam/taglib"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:a="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
template="layout/template.xhtml">
<ui:define name="body">
<h:form id="roundform">
<rich:panel>
<f:facet name="header>">Round</f:facet>
<s:decorate id="id" template="layout/display.xhtml">
<ui:define name="label">Id:</ui:define>
<h:outputText value="#{null == roundHome.id ? 'null' : roundHome.id}">
<s:convertDateTime type="date" />
</h:outputText>
</s:decorate>
<s:decorate id="date" template="layout/display.xhtml">
<ui:define name="label">Date:</ui:define>
<h:outputText value="#{roundHome.instance.date}">
<s:convertDateTime type="date" />
</h:outputText>
</s:decorate>
<s:decorate id="golfer" template="layout/display.xhtml">
<ui:define name="label">Golfer:</ui:define>
#{roundHome.instance.golfer.name}
</s:decorate>
<s:decorate id="totalScore" template="layout/display.xhtml">
<ui:define name="label">Total Score:</ui:define>
#{roundHome.instance.totalScore}
</s:decorate>
<s:decorate id="weather" template="layout/display.xhtml">
<ui:define name="label">Weather:</ui:define>
#{roundHome.instance.weather}
</s:decorate>
<s:decorate id="notes" template="layout/display.xhtml">
<ui:define name="label">Notes:</ui:define>
#{roundHome.instance.notes}
</s:decorate>
<div style="clear:both"/>
</rich:panel>
<div class="actionButtons">
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" />
</div>
<rich:tabPanel>
<rich:tab label="Tee Set">
<div class="association">
<h:outputText value="Tee set not selected" rendered="#{roundHome.instance.teeSet == null}" />
<rich:dataTable var="_teeSet" value="#{roundHome.instance.teeSet}" rendered="#{roundHome.instance.teeSet != null}">
<h:column>
<f:facet name="header">Course</f:facet>#{_teeSet.course.name}
</h:column>
<h:column>
<f:facet name="header">Color</f:facet>#{_teeSet.color}
</h:column>
<h:column>
<f:facet name="header">Position</f:facet>#{_teeSet.pos}
</h:column>
</rich:dataTable>
</div>
</rich:tab>
</rich:tabPanel>
</h:form>
</ui:define>
</ui:composition>
The entityHome RoundHome.java
#Name("roundHome")
public class RoundHome extends EntityHome<Round>{
#In(required = false)
private Golfer currentGolfer;
#In(create = true)
private TeeSetHome teeSetHome;
#Logger
private Log logger;
public void wire() {
logger.info("wire called");
TeeSet teeSet = teeSetHome.getDefinedInstance();
if (null != teeSet) {
getInstance().setTeeSet(teeSet);
logger.info("Successfully wired the teeSet instance with color: " + teeSet.getColor());
}
}
public boolean isWired() {
logger.info("is wired called");
if(null == getInstance().getTeeSet()) {
logger.info("wired teeSet instance is null, the button will be disabled !");
return false;
}
else {
logger.info("wired teeSet instance is NOT null, the button will be enabled !");
logger.info("teeSet color: "+getInstance().getTeeSet().getColor());
return true;
}
}
#RequestParameter
public void setRoundId(Long id) {
logger.info("in Setter RoundId is: " + id);
super.setId(id);
}
public Long getRoundId() {
Long id = (Long) getId();
logger.info("Setting RoundId : " + id);
return id;
}
#Override
protected Round createInstance() {
Round round = super.createInstance();
round.setGolfer(currentGolfer);
round.setDate(new java.sql.Date(System.currentTimeMillis()));
logger.info("Created a Round with roundId: " + round.getId());
return round;
}
#Override
protected Round loadInstance() {
logger.info("loadInstance for id: " + getId());
return (Round) getEntityManager().createQuery(
"select r from Round r " +
"join fetch r.golfer g " +
"join fetch r.teeSet ts " +
"join fetch ts.course c " +
"where r.id = :id ")
.setParameter("id",getId())
.getSingleResult();
}
}
In Round.xhtml you have:
<div class="actionButtons">
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" />
</div>
This navigates to RoundEdit but it doesn't pass a roundId to be edited. When you add an id to the url you're setting that id manually. To set it in the code you could use a get action and pass it as a param:
<s:button id="edit" view="/RoundEdit.xhtml" value="Edit" >
<param name="roundId" value="#{roundHome.id}"/>
</s:button>
Check out the URL, you'll see the param being passed.

Resources