0

I want to pass the "title" parameter in the following listing dynamicaly to another jsf Facelet, depending on the selection of the selectOneMenu. My first approach looks like this:

<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>

The ExerciseEditorBean is ViewScoped.

The openEditor() function then decides by the selectedExerciseType attribute which Facelet to show next and returns something like "multipleChoiceEditor.xhtml". How can I now pass the titel attribute to this Facelet?

hFonti
  • 187
  • 1
  • 4
  • 11
  • JSF is designed for navigation based on HTTP post requests. This means that when you navigate to a page, parameters are also passed in this way. I very much dislike that fact since it also disallows bookmarking. I prefer to navigate based on get requests with parameterized URLs. IMO an URL should look like `/editor/multiplechoice` instead of `/editor.xhtml` or `/editor.xhtml?type=multiplechoice`. If you're interested, take a look at PrettyFaces. ;-) – siebz0r Jan 11 '13 at 17:16
  • @siebz0r, you can bookmark URLs generated with `` or `` and conveniently pass params with `includeViewParams=true` on either of them. They both generate GETs as against the stock POST with the commandXXX components – kolossus Jan 11 '13 at 19:35
  • See [this answer](http://stackoverflow.com/questions/4317684/when-should-i-use-houtputlink-instead-of-hcommandlink) – kolossus Jan 11 '13 at 19:41
  • @kolossus Whether this is a pretty solution is up for debate ;-) – siebz0r Jan 11 '13 at 20:56
  • In JSF, the only servlet is the `FacesServlet`. You perhaps meant to say "Facelet" everytime you (mis)typed "servelet". – BalusC Jan 12 '13 at 11:26
  • @BalusC thanks for the correction. I'm sorry, I'm new to JSF and sometimes I mess up the terminology. – hFonti Jan 12 '13 at 17:00

1 Answers1

0

I now use the f:ViewParam in the target servelet, which works well except, that "multipleChoiceEditor.xhtml?includeViewParams=true" does not work, but this is another issue. Thanks for the discussion!

hFonti
  • 187
  • 1
  • 4
  • 11