seam page parameters not working as expected.

Posted by rangalo on Stack Overflow See other posts from Stack Overflow or by rangalo
Published on 2010-05-23T22:11:12Z Indexed on 2010/05/23 22:21 UTC
Read the original article Hit count: 673

Filed under:
|
|

Hi,

I am learning seam and following a very famous 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();

    }
}

© Stack Overflow or respective owner

Related posts about jboss

Related posts about seam