【问题标题】:Dynamic navigation with parameter passing in JSF在 JSF 中传递参数的动态导航
【发布时间】:2013-01-11 15:12:39
【问题描述】:

我想将以下清单中的“title”参数动态传递给另一个 jsf Facelet,具体取决于 selectOneMenu 的选择。我的第一种方法如下所示:

<h:form id="form">

    <p:selectOneMenu value="#{exerciseEditorBean.selectedExerciseType}" >
        <f:selectItem itemLabel="Multiple Choice Exercise" itemValue="MultipleChoiceExercise" />  
        <f:selectItem itemLabel="Vocabulary Test" itemValue="VocabularyTest" />  
    </p:selectOneMenu>

    <h:outputText value="Enter Title of your Exercise: " />  
    <h:inputText id="title" value="#{exerciseEditorBean.exerciseTitle}" />

    <h:commandButton value="Next" action="#{exerciseEditorBean.openEditor()}" />

</h:form>

ExerciseEditorBean 是 ViewScoped。

openEditor() 函数然后由 selectedExerciseType 属性决定接下来要显示哪个 Facelet,并返回类似“multipleChoiceEditor.xhtml”的内容。 现在如何将 title 属性传递给这个 Facelet?​​

【问题讨论】:

  • JSF 是为基于 HTTP post 请求的导航而设计的。这意味着当你导航到一个页面时,参数也是以这种方式传递的。我非常不喜欢这个事实,因为它也不允许添加书签。我更喜欢基于带有参数化 URL 的 get 请求进行导航。 IMO URL 应该看起来像/editor/multiplechoice 而不是/editor.xhtml/editor.xhtml?type=multiplechoice。如果你有兴趣,看看 PrettyFaces。 ;-)
  • @siebz0r,您可以为使用&lt;h:button/&gt;&lt;h:link/&gt; 生成的URL 添加书签,并在其中任何一个上方便地使用includeViewParams=true 传递参数。它们都使用 commandXXX 组件生成 GET,而不是普通的 POST
  • @kolossus 这是否是一个漂亮的解决方案还有待商榷 ;-)
  • 在 JSF 中,唯一的 servlet 是 FacesServlet。每次您(错误)输入“servelet”时,您可能都想说“Facelet”。

标签: jsf primefaces navigation parameter-passing


【解决方案1】:

我现在在目标 serverlet 中使用 f:ViewParam,它运行良好,但“multipleChoiceEditor.xhtml?includeViewParams=true”不起作用,但这是另一个问题。感谢讨论!

【讨论】:

    猜你喜欢
    • 2012-06-08
    • 2021-12-21
    • 2011-01-26
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    相关资源
    最近更新 更多