English 中文(简体)
我如何利用共同未来论坛形成一种可重复的看法
原标题:How can I create a reusable view using JSF

在这种情况下,我想形成一种观点,从其他一些观点中可以用来制造和编辑特定类型的物体。

My application has an address entity which can be shared between other entities. In the view which maintains an entity, I would like a button/link which navigates to the address edit view for the address linked to that entity. Another view which handles a different entity also needs to be able to navigate to the address edit view with its address. The address view would then navigate back to the calling view once editing is completed.

我的问题是,我似乎无法找到一种办法,把地址实体从第一种观点纳入到处理观点。

我认为,我需要某种对话范围,但不知道如何在不了解页标语的情况下找到地址,但我的讲话显然只能了解地址。

我正在使用JSF2.1(MyFaces/PrimeFaces)和CDI(OpenWeb Beans)和CODI。

I m sure I must be missing something simple. (Simple relative to JSF/CDI terms that is!)

问题回答

仅将地址ID作为请求参数,其目标目标是通过<代码><f:viewParam>将其转换、鉴定和定位在标本上。

E.g.

<h:link value="Edit address" outcome="addresses/edit">
    <f:param name="id" value="#{address.id}" />
</h:link>

编号:addresses/edit.xhtml>。

<f:metadata>
    <f:viewParam id="id" name="id" value="#{editAddressBacking.address}"
        converter="#{addressConverter}" converterMessage="Bad request. Unknown address."
        required="true" requiredMessage="Bad request. Please use a link from within the system." />
</f:metadata>
<h:message for="id" />

<h:form rendered="#{not empty editAddressBacking.address}">
    <h:inputText value="#{editAddressBacking.address.street}" />
    ...
</h:form>

In order to navigate back to the original page, you could pass another request parameter.

<h:link value="Edit address" outcome="addresses/edit">
    <f:param name="id" value="#{address.id}" />
    <f:param name="from" value="#{view.viewId}" />
</h:link>

由<代码><f:viewParam>确定 并且,为了让你能够提出假装地址的手法,证明人有理由返回:

public String save() {
    // ...

    return from + "?faces-redirect=true";
}

See also:

I think I have come up with a solution.

As I am using CODI I can leverage the ConversationGroup annotation. I ve created an emtpy interface AddressConversation, then added this to all the backing beans that need to show the address/addressEdit.xhtml view, as well as the backing bean for the addressEdit view.

I m also using CODI view config so my action methods return ViewConfig derived class objects.

@Named
@ConversationScoped
@ConversationGroup(AddressConversation.class)
public class AddressView implements Serializable
{
    private Class<? extends Views> fromView;
    private Address editAddress;
    private Address returnAddress;

    // Getters/setters etc...

    public Class<? extends Views> cancelEdit()
    {
        returnAddress = null;

        return fromView;
    }
}

因此,我在呼吁中(PrimeFacestorLink)

<p:commandLink value="#{enquiryView.addressLinkText}" action="#{enquiryView.editAddress()}" immediate="true"/>

www.un.org/chinese/sc/presidency.asp EnquiryView 在正确的谈话小组中,我可以@Inject AddressView,然后在使用行动方法时确定地址和回归观点。

@Named
@ConversationScoped
@ConversationGroup(AddressConversation.class)
public class EnquiryView implements Serializable
{
    @Inject @ConversationGroup(AddressConversation.class) private AddressView addrView;

    public Class<? extends Views> editAddress()
    {
        addrView.setAddress(editEnq.getAddress());
        addrView.setFromView(Views.Enquiry.EnquiryEdit.class);
        return Views.Address.AddressEdit.class;
    }
}

I can also observe the navigation in EnquiryView and update the enquiry entity when an address has been "saved" in the address edit view.

protected void onViewConfigNav(@Observes PreViewConfigNavigateEvent navigateEvent)
{
    if (navigateEvent.getFromView() == Views.Address.AddressEdit.class && 
            navigateEvent.getToView() == Views.Enquiry.EnquiryEdit.class)
    {
        onEditAddressReturn();
    }
}

private void onEditAddressReturn()
{
    if (addrView.getReturnAddress() != null) {
        // Save pressed
        editEnq.setAddress(addrView.getReturnAddress());
    }
}

如果你想要在地址是K时确定另一个实体,那么,只是给压力者程序以你想要确定的名称:

<f:param name="targetBeanSetter" value="enquiryBean.adress" />

And in Java :

public String executeAndBack() {
    int last = this.targetBeanSetter.lastIndexOf( . );
    String base = this.targetBeanSetter.substring(0, last);
    String property = this.targetBeanSetter.substring(last + 1);
    Object yourEntityToSet = FacesContext.getCurrentInstance().getELContext().getELResolver().getValue(context.getELContext(), null, base);
    try {
            PropertyUtils.setSimpleProperty(yourEntityToSet, property, constructeurHolder.getConstructeur());
        } catch (Throwable e) {
            throw new RuntimeException(e.getMessage());
        }
    return from + "?faces-redirect=true";
}

如果你只需要获得选择的供暖,而不必建造连接的物体,那么,当你回到第1页时,就应当使用在问讯中投放。

@ManagedProperty(value="{address}")
Address adress;




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签