0

我一直在玩 spring web flow 酒店预订应用程序,并对其进行了一些扩展,以尝试更好地理解 spring web flow 和 JSF 如何集成在一起。spring 文档在这方面并不是那么好,我的印象是,在你改变它们之前,事情是有效的,然后没有明确的文档描述它是如何工作的,所以你不知道你是如何破坏它的。

无论如何,希望您熟悉 spring web flow 酒店预订示例应用程序。如果不是,则主流程接受搜索条件并返回酒店列表,然后可以选择酒店,然后显示其信息。我正在尝试扩展它,以便当您查看酒店时,您可以查看有关各个酒店房间的信息。

这是流程的代码:

    <view-state id="reviewHotels">
    <on-render>
        <evaluate expression="bookingService.findHotels(searchCriteria, flowRequestContext)" result="viewScope.hotels" result-type="dataModel" />
    </on-render>
    <transition on="select" to="reviewHotel">
        <set name="flowScope.hotel" value="hotels.selectedRow" />
    </transition>

当您选择酒店时,它会调用定价服务。这是该视图:

<view-state id="reviewHotel" model="hotel">
    <on-render>
        <evaluate expression="bookingService.priceHotel(flowScope.hotel, flowRequestContext)" result="flowScope.hotel"/>
    </on-render>

    <transition on="price" to="displayPriceBreakdown">
        <set name="flowScope.room" value="flowScope.hotel.rooms.selectedRow"></set>
    </transition>
</view-state>

然后 displayPriceBreakdown 视图显示当您单击酒店价格时价格是如何计算的。这是视图配置:

    <view-state id="displayPriceBreakdown" view="displayPriceBreakdown.xhtml">
    <on-entry>
        <render fragments="priceBreakdownFragment" />
    </on-entry>
    <transition on="back" to="reviewHotel"/>
</view-state>

显示酒店详细信息及其房间的 reviewHotel.xhtml 如下所示:

<ui:define name="content">
<div class="section">
<h2>View Hotel</h2>
<ui:fragment id="messages">
        <div id="messagesInsertionPoint">
            <h:messages errorClass="errors" />
        </div>
</ui:fragment>

<h:form id="hotel">
    <fieldset>
        <div class="field">
            <div class="labelhotel">Name:</div>
            <div class="outputhotel">#{hotel.name}</div>
        </div>
        <div class="field">
            <div class="labelhotel">Address:</div>
            <div class="outputhotel">#{hotel.address}</div>
        </div>
        <div class="field">
            <div class="labelhotel">City:</div>
            <div class="outputhotel">#{hotel.city}</div>
        </div>
        <div class="field">
            <div class="labelhotel">Post Code:</div>
            <div class="outputhotel">#{hotel.zip}</div>
        </div>
        <div class="field">
            <div class="labelhotel">Country:</div>
            <div class="outputhotel">#{hotel.country}</div>
        </div>
        <div class="field">
            <div class="labelhotel">Amenities:</div>
            <div class="outputhotel"><h:dataTable id="amentities" var="a" value="#{hotel.amenities}">
                                    <h:column>#{a.name} - #{a.description}</h:column></h:dataTable></div>
        </div>

        <div class="field">
            <div class="labelhotel">Rooms:</div>
            <ui:fragment id="roomsFragment">
            <div class="outputhotel"><h:dataTable id="rooms" styleClass="summary" var="r" value="#{hotel.rooms}">
                                    <h:column>#{r.roomType} - #{r.bedType}</h:column> 
                                    <h:column><sf:commandLink id="priceBreakdownLink" value="#{r.roomPrice} #{r.roomPriceCurrency}" action="price" processIds="priceBreakdownFragment"/> </h:column>
                                    <h:column><sf:commandLink id="bookHotelLink" value="Book Hotel" action="select"/></h:column>
                                </h:dataTable>
            </div>
            </ui:fragment>
        </div>

        <div class="buttonGroup">
            <h:commandButton id="cancel" action="cancel" value="Back to Search"/>
        </div>
    </fieldset>
</h:form>

重要的是用于显示酒店房间的数据表:

            <div class="field">
            <div class="labelhotel">Rooms:</div>
            <ui:fragment id="roomsFragment">
            <div class="outputhotel"><h:dataTable id="rooms" styleClass="summary" var="r" value="#{hotel.rooms}">
                                    <h:column>#{r.roomType} - #{r.bedType}</h:column> 
                                    <h:column><sf:commandLink id="priceBreakdownLink" value="#{r.roomPrice} #{r.roomPriceCurrency}" action="price" processIds="priceBreakdownFragment"/> </h:column>
                                    <h:column><sf:commandLink id="bookHotelLink" value="Book Hotel" action="select"/></h:column>
                                </h:dataTable>
            </div>
            </ui:fragment>
        </div>

房间信息正确显示,但是当用户点击价格时,我想显示所选特定房间的价格明细列表。这就是我希望通过以下方式实现的目标:

        <transition on="price" to="displayPriceBreakdown">
        <set name="flowScope.room" value="flowScope.hotel.rooms.selectedRow"></set>
    </transition>

但是,当我运行时,我得到了 selectedRow 的 NumberFormatException。

HTTP Status 500 -

类型异常报告

信息

描述 服务器遇到一个内部错误 () 阻止它完成这个请求。

例外

org.springframework.web.util.NestedServletException:请求处理失败;嵌套异常是 org.springframework.webflow.execution.ActionExecutionException: 异常抛出执行 [AnnotatedAction@34f67 targetAction = [SetAction@4db694 name = flowScope.room, value = flowScope.hotel.rooms.selectedRow, type = [null]], attributes = map[[empty]]] in state 'reviewHotel' of flow 'main' -- 动作执行属性是 'map[[empty]]' org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:583) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.springframework.web.filter.CharacterEncodingFilter。

org.springframework.webflow.execution.ActionExecutionException: 异常抛出执行 [AnnotatedAction@34f67 targetAction = [SetAction@4db694 name = flowScope.room, value = flowScope.hotel.rooms.selectedRow, type = [null]], attributes = map[ [empty]]] 处于流 'main' 的状态 'reviewHotel' - 动作执行属性是 'map[[empty]]' org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:60) org.springframework .webflow.engine.support.ActionTransitionCriteria.test(ActionTransitionCriteria.java:82) org.springframework.webflow.engine.support.TransitionCriteriaChain.test(TransitionCriteriaChain.java:71) org.springframework.webflow.engine.Transition.canExecute(Transition .java:195) org.springframework.webflow.engine.Transition.execute(Transition.java:211) 组织。springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391) org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214) org.springframework.webflow.engine.TransitionableState.handleEvent( TransitionableState.java:119) org.springframework.webflow.engine.Flow.handleEvent(Flow.java:555) org.springframework.webflow.engine.impl.FlowExecutionImpl.handleEvent(FlowExecutionImpl.java:386) org.springframework.webflow。 engine.impl.RequestControlContextImpl.handleEvent(RequestControlContextImpl.java:210) org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:230) org.springframework.webflow.engine.ViewState.resume(ViewState.java:196) org.springframework.webflow.engine.Flow.resume(Flow.java:545) org.springframework.webflow.engine。impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259) org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:163) org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet. java:571) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet.service(HttpServlet. java:717) org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76) 根本原因

java.lang.NumberFormatException:对于输入字符串:“selectedRow” java.lang.NumberFormatException.forInputString(NumberFormatException.java:48) java.lang.Integer.parseInt(Integer.java:449) java.lang.Integer.parseInt(Integer .java:499) javax.el.ListELResolver.coerce(ListELResolver.java:166) javax.el.ListELResolver.getValue(ListELResolver.java:51) javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54) org.springframework .binding.expression.el.DefaultELResolver.getValue(DefaultELResolver.java:80) org.jboss.el.parser.AstPropertySuffix.getValue(AstPropertySuffix.java:53) org.jboss.el.parser.AstValue.getValue(AstValue.java :67) org.jboss.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186) org.springframework.binding.expression.el.BindingValueExpression。getValue(BindingValueExpression.java:54) org.springframework.binding.expression.el.E​​LExpression.getValue(ELExpression.java:54) org.springframework.webflow.action.SetAction.doExecute(SetAction.java:75) org.springframework。 webflow.action.AbstractAction.execute(AbstractAction.java:188) org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145) org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51) org.springframework.webflow.engine.support.ActionTransitionCriteria.test(ActionTransitionCriteria.java:82) org.springframework.webflow.engine.support.TransitionCriteriaChain.test(TransitionCriteriaChain.java:71) org.springframework.webflow.engine.Transition. canExecute(Transition.java:195) org.springframework.webflow.engine.Transition.execute(Transition.java:211) org.springframework.webflow.engine.impl.FlowExecutionImpl.execute(FlowExecutionImpl.java:391) org.springframework.webflow.engine.impl.RequestControlContextImpl.execute(RequestControlContextImpl.java:214) org.springframework.webflow.engine。 TransitionableState.handleEvent(TransitionableState.java:119) org.springframework.webflow.engine.Flow.handleEvent(Flow.java:555) org.springframework.webflow.engine.impl.FlowExecutionImpl.handleEvent(FlowExecutionImpl.java:386) org. springframework.webflow.engine.impl.RequestControlContextImpl.handleEvent(RequestControlContextImpl.java:210) org.springframework.webflow.engine.ViewState.handleEvent(ViewState.java:230) org.springframework.webflow.engine.ViewState.resume(ViewState. java:196) org.springframework.webflow.engine.Flow.resume(Flow.java:545) org.springframework。webflow.engine.impl.FlowExecutionImpl.resume(FlowExecutionImpl.java:259) org.springframework.webflow.executor.FlowExecutorImpl.resumeExecution(FlowExecutorImpl.java:163) org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter. java:183) org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875) org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807) org.springframework.web.servlet.FrameworkServlet。 processRequest(FrameworkServlet.java:571) org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511) javax.servlet.http.HttpServlet.service(HttpServlet.java:637) javax.servlet.http.HttpServlet。服务(HttpServlet.java:717)org.springframework.web.filter.CharacterEncodingFilter。doFilterInternal(CharacterEncodingFilter.java:96) org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)

我应该如何将 HotelRoom 对象传递到 displayPriceBreakdown 片段中?

非常感谢您已经走到了这一步并且正在阅读和理解这一点!我试图尽可能彻底,但是如果需要更多信息,请告诉我。

哦,是的,Hotel 作为一个名为 rooms 的变量,它是一个 List 并具有 getRooms : List 和 setRooms(List rooms) 方法。

4

1 回答 1

0

这是flowScope.hotel.rooms.selectedRow参考的 EL 评估的问题。

根据您的描述,flowScope.hotel.rooms引用了一个实现 List 接口的对象。当 EL 遇到这样的对象时,它假定以下引用是该列表的索引 - 因此您可以执行以下操作:

myList[0]- 显示第 0 个元素。

不幸的是,当您没有整数引用时,它会中断,因此flowScope.hotel.rooms.selectedRow会给您一个 numberFormatException,因为它不能将 ' selectedRow' 强制转换为整数。

一种解决方案是从列表中分离出您希望引用的属性。所以你的房间对象不应该实现 List,而是实现 getSelectedRow 和 getItems - 它返回实际的列表进行迭代。

于 2010-11-23T12:00:02.430 回答