如何在JSF中将对象从一页传递到另一页而无需编写转换器 [英] How to pass objects from one page to another page in JSF without writing a converter

查看:104
本文介绍了如何在JSF中将对象从一页传递到另一页而无需编写转换器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,对不起我的英语.我在JSF2中有两个页面,一个页面列出乘客,另一个页面创建/更新乘客.我也有两个@ViewScoped bean,一个包含乘客列表,一个用于将所选乘客保留在pageB中.我看到了通过viewParam或@ManagedProperty传递旅客的方法,但我不想编写转换器.

first of all sorry for my english. I have two pages in JSF2, one to list Passengers and another one to create/update passengers. I have also two @ViewScoped beans, one with the list of passengers and one for hold in pageB the selected passenger. I see the ways to pass the passenger through viewParam or @ManagedProperty but i don´t want to write a converter.

我想知道是否有一种方法可以将对象从pageA传递到pageB,而无需传递乘客的ID和编写转换器,或者不传递ID,然后去DB来检索乘客. 以下是我的工作方式.我通过setPropertyActionListener在flash作用域中设置了所选对象,并导航到pageB,在viewScopedBean的@PostConstruct中,我获取了flashScope并检索了对象.如我所说,这可行,但我不知道它是否正确.这是代码 页面A:

What i want to know if there is a way to pass the object from pageA to pageB without passing the id of the passenger and write a converter or without passing the id and then go to the DB to retrieve the passenger. What i do and works is the following. I set in flash scope through setPropertyActionListener the selected object and navigate to pageB, in the @PostConstruct of the viewScopedBean i get the flashScope and retrieve the object. As i said, this works but i don´t know if it is correct. Here is the code Page A:

<p:column width="10" style="text-align: center;">                    
    <p:commandButton icon="ui-icon-pencil" action="editClientes?faces-redirect=true">                         
        <f:setPropertyActionListener target="#{flash.pax}" value="#{row}"/> 
     </p:commandButton>
</p:column>

pageB bean的@PostConstruct

@PostConstruct of pageB bean

@PostConstruct
private void initBean(){          
    this.pax = (Passenger) JSFUtils.getFlashScope().get("pax"); 
    if(this.pax == null){
        this.pax = new Passenger();
    }           
}

这是正确的方法还是写转换器的正确方法? 谢谢.

Is this correct, or the correct way is to write a converter? Thanks.

推荐答案

取决于您是否希望/editClientes请求成为幂等(可书签").

Depends on whether you want the /editClientes request to be idempotent ("bookmarkable") or not.

闪光方法是不是幂等的.链接/共享/标记/editClientes URL以便编辑 specific 客户端是不可能的.当最终用户复制此URL进行共享/添加书签并重新执行该请求时(即使只是按浏览器地址栏中的[enter]),最终用户将面对的是一个新客户端的空白编辑表单,而不是新的客户端.最终用户通过Flash范围最初选择的一个.

The flash approach is not idempotent. It's not possible to link/share/bookmark the /editClientes URL in order to edit a specific client. When the enduser copies this URL for sharing/bookmarking and re-executes the request on it (even though it's just pressing [enter] in browser's address bar), all the enduser would face is an empty edit form for a new client instead of the one the enduser initially selected via flash scope.

请求参数方法是幂等的.每次最终用户重新执行请求时,最终用户都可以完全获得相同的响应.

The request parameter approach is idempotent. The enduser is able to get exactly the same response everytime the enduser re-executes the request.

由我们决定您的/editClientes页面是否应幂等.是你的.

It's not our decision whether your /editClientes page should be idempotent or not. It's yours.

这篇关于如何在JSF中将对象从一页传递到另一页而无需编写转换器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆