如何在参数的接缝中调节导航

时间:2023-02-04 20:09:22

I have a Seam application originally generated by seam-gen with a view Search.xhtml.

我有一个最初由seam-gen生成的Seam应用程序,其中包含View.xhtml视图。

Search.xhtml has a number of input fields, half of which are bound to the Office entity and half to the Devices entity.

Search.xhtml有许多输入字段,其中一半绑定到Office实体,一半绑定到Devices实体。

For example, if you enter a hostname, it is bound to a field in Devices, if you enter a City, it is bound to a field in Office.

例如,如果输入主机名,则它将绑定到“设备”中的字段,如果输入“城市”,则它将绑定到Office中的字段。

The destination page is going to be OfficeResult.xhtml by default, or, if a "Devices" property has been entered, to the DeviceResult.xhtml.

默认情况下,目标页面将为OfficeResult.xhtml,如果已输入“Devices”属性,则为DeviceResult.xhtml。

My question has 2 parts:

我的问题有两个部分:

  1. What component should I use in Search.xhtml for the submit button? I assume h:commandButton, but then what do I use for the action? If I use a destination view, will that be overridden by the navigation rule in page.xml file?

    我应该在Search.xhtml中使用哪个组件作为提交按钮?我假设h:commandButton,但那我该怎么用于动作呢?如果我使用目标视图,是否会被page.xml文件中的导航规则覆盖?

  2. How to set up my Search.page.xml file? How do I condition the navigation on the parameter?

    如何设置我的Search.page.xml文件?如何调整参数的导航?

Here is Search.xhtml (pseudo code):

这是Search.xhtml(伪代码):

<h:inputText value="#{devicesList.devices.devSerialNum}" />
<h:inputText id="state" value="#{officeList.office.state}" />

<h:commandButton id="search" action="/OfficeResult.xhtml" value="Search"  />

Search.page.xml (pseudo code):

Search.page.xml(伪代码):

<navigation>
  <rule if devSerNum is set >
<redirect view-id="/DeviceResult.xhtml"/>
  </rule>
  <rule if state is set >
    <redirect view-id="/OfficeResult.xhtml"/>
  </rule>
</navigation>

2 个解决方案

#1


If I'm understanding your question correctly, and based on your current design, I believe you could do something similar to this:

如果我正确理解你的问题,并根据你当前的设计,我相信你可以做类似的事情:

Your Search.xhtml file:

您的Search.xhtml文件:

<h:inputText value="#{devicesList.devices.devSerialNum}" />
<h:inputText id="state" value="#{officeList.office.state}" />

<h:commandButton id="search" action="#{devicesList.isDeviceSearch()}" value="Search"  />

Add a new method to your DevicesList.java file

将新方法添加到DevicesList.java文件中

@Name("devicesList")
public class DevicesListImpl implements DevicesList {

    ...other properties and methods...

    public boolean isDeviceSearch() {

        boolean result;

        ...logic to determine if the search value exists...

        return result;

    }
}

And then in your Search.page.xml file:

然后在您的Search.page.xml文件中:

<navigation from-action="#{devicesList.isDeviceSearch()}">
    <rule if-outcome="true">
        <redirect view-id="/DeviceResult.xhtml" />
    </rule>

    <redirect view-id="/OfficeResult.xhtml" />
</navigation>

#2


I have had some difficulty understanding how the navigation works as well. I finally have mine working to some degree here are some ideas I would try:

我很难理解导航的工作原理。我终于让我的工作在某种程度上有一些想法我会尝试:

  1. use pages.xml first with one to verify you can get your navigation working with the default, simple ruleset. /WEB-INF/pages.xml

    首先使用pages.xml和一个来验证您是否可以使用默认的简单规则集来使用导航。 /WEB-INF/pages.xml

  2. enable the trace loglevel for your application if you are unsure what is happening, chances may be Seam cannot find a component. 2.1 #{devicesList ... } may not be found if you are not importing it in your components.xml unless that component's name is devicesList. My components use their fully qualified name, com.* ... The advantage of that is, you avoid collisions, but to access the component, you have to write out the full path or do an import as described above.

    如果您不确定发生了什么,请为您的应用程序启用跟踪日志级别,可能是Seam无法找到组件。如果您没有在components.xml中导入它,则可能找不到2.1#{devicesList ...},除非该组件的名称是devicesList。我的组件使用其完全限定名称com.* ...其优点是,您可以避免冲突,但是要访问组件,您必须写出完整路径或执行上述导入。

  3. verify the view id's exist (/OfficeResult.xhtml and /DeviceResult.xhtml)

    验证视图ID是否存在(/OfficeResult.xhtml和/DeviceResult.xhtml)

  4. make sure every page is declared only once

    确保每个页面只声明一次

  5. your commandButton should be an actual component from my understanding. If you have a searchAction, then it would be something like:

    你的commandButton应该是我理解的实际组件。如果你有一个searchAction,那么它将是这样的:

    #{searchAction.search}

Check out the seam examples, they work well and show you how to do many different things. You can download them in the seam source code which is about 130 MB including all of those examples.

查看接缝示例,它们运行良好并向您展示如何执行许多不同的操作。您可以使用大约130 MB的接缝源代码下载它们,包括所有这些示例。

Walter

#1


If I'm understanding your question correctly, and based on your current design, I believe you could do something similar to this:

如果我正确理解你的问题,并根据你当前的设计,我相信你可以做类似的事情:

Your Search.xhtml file:

您的Search.xhtml文件:

<h:inputText value="#{devicesList.devices.devSerialNum}" />
<h:inputText id="state" value="#{officeList.office.state}" />

<h:commandButton id="search" action="#{devicesList.isDeviceSearch()}" value="Search"  />

Add a new method to your DevicesList.java file

将新方法添加到DevicesList.java文件中

@Name("devicesList")
public class DevicesListImpl implements DevicesList {

    ...other properties and methods...

    public boolean isDeviceSearch() {

        boolean result;

        ...logic to determine if the search value exists...

        return result;

    }
}

And then in your Search.page.xml file:

然后在您的Search.page.xml文件中:

<navigation from-action="#{devicesList.isDeviceSearch()}">
    <rule if-outcome="true">
        <redirect view-id="/DeviceResult.xhtml" />
    </rule>

    <redirect view-id="/OfficeResult.xhtml" />
</navigation>

#2


I have had some difficulty understanding how the navigation works as well. I finally have mine working to some degree here are some ideas I would try:

我很难理解导航的工作原理。我终于让我的工作在某种程度上有一些想法我会尝试:

  1. use pages.xml first with one to verify you can get your navigation working with the default, simple ruleset. /WEB-INF/pages.xml

    首先使用pages.xml和一个来验证您是否可以使用默认的简单规则集来使用导航。 /WEB-INF/pages.xml

  2. enable the trace loglevel for your application if you are unsure what is happening, chances may be Seam cannot find a component. 2.1 #{devicesList ... } may not be found if you are not importing it in your components.xml unless that component's name is devicesList. My components use their fully qualified name, com.* ... The advantage of that is, you avoid collisions, but to access the component, you have to write out the full path or do an import as described above.

    如果您不确定发生了什么,请为您的应用程序启用跟踪日志级别,可能是Seam无法找到组件。如果您没有在components.xml中导入它,则可能找不到2.1#{devicesList ...},除非该组件的名称是devicesList。我的组件使用其完全限定名称com.* ...其优点是,您可以避免冲突,但是要访问组件,您必须写出完整路径或执行上述导入。

  3. verify the view id's exist (/OfficeResult.xhtml and /DeviceResult.xhtml)

    验证视图ID是否存在(/OfficeResult.xhtml和/DeviceResult.xhtml)

  4. make sure every page is declared only once

    确保每个页面只声明一次

  5. your commandButton should be an actual component from my understanding. If you have a searchAction, then it would be something like:

    你的commandButton应该是我理解的实际组件。如果你有一个searchAction,那么它将是这样的:

    #{searchAction.search}

Check out the seam examples, they work well and show you how to do many different things. You can download them in the seam source code which is about 130 MB including all of those examples.

查看接缝示例,它们运行良好并向您展示如何执行许多不同的操作。您可以使用大约130 MB的接缝源代码下载它们,包括所有这些示例。

Walter