0

I am using NetBeans for a Web Application in Java EE.

I have one controller for an absence entity class (absenceController) and one controller for an employee entity class (employeeController).

I am able to get to the employee creation page via any page controlled by absenceController:

<h:commandLink action="#{absenceController.prepareCreate}"
    value="#{bundle.ListAbsenceCreateLink}"/>

I am able to get to the absence creation page via any page controlled by employeeController:

<h:commandLink action="#{employeeController.prepareCreate}"
    value="#{bundle.ViewEmployeeCreateLink}" />

When I want to set up a new absence instance, I need the employee to be set in advance so I am trying to reach the absence creation page from an employee view page (called Tasks.xhtml), sending the employee instance as a parameter.

In MVC .NET I would have used an Html.ActionLink a bit like this:

Html.ActionLink("Report Absence for employee"
, "Create"
, "Absence"
, new { employeeid = employee.Id } // <- I would only be able to send the id
, null)

In Java, this is the closest I've got:

<h:commandLink action="/absence/create"
        value="#{bundle.TasksEmployeeCreateAbsenceLink}"  >
    <f:setPropertyActionListener target="#{absenceController.selected.employee}"
            value="#{employeeController.selected}" />
</h:commandLink>

The folder structure is shown below:

Web Tree Structure

I know the action tag is not correct, but is there some way to change it to get the desired result please?

Ali
  • 109
  • 7
  • Must it be a GET or POST request? Did you consider the idempotence of such a request? – BalusC Sep 07 '14 at 20:02
  • It would be a GET. I'm sorry if I'm misunderstanding idempotence - It would be OK to call more than once because an employee may have many absences. – Ali Sep 07 '14 at 20:35

2 Answers2

0

One way of achieving what I needed was to use navigation rules. (As in the comments, there are better way of achieving this since JSF 2.x)

I added the following to faces-config.xml (within <application></application> section):

    <navigation-rule>
        <from-view-id>/employee/Tasks.xhtml</from-view-id>
            <navigation-case>
                    <from-action>absence/create</from-action> 
                    <from-outcome>absence/create</from-outcome>
                    <to-view-id>/absence/Create.xhtml</to-view-id>
            </navigation-case>
    </navigation-rule>  
Ali
  • 109
  • 7
  • Navigation rules are sooo JSF 1.x. Are you sure you're reading up to date resources while learning JSF? Exactly the same could in JSF 2.x be achieved by just `action="/absence/Create.xhtml"` or even `action="/absence/Create"` if you've properly mapped the `FacesServlet` on `*.xhtml`. Yet better, just lowercase that XHTML filename so that you can ultimately keep using a clean all-lowercased `action="/absence/create"`. – BalusC Sep 08 '14 at 07:33
  • @BalusC I did try all of those things yesterday, but they did not work... Please could you elaborate on "properly mapped the `FacesServlet` on `*.xhtml`." Is there another configuration file I should be checking? Thank you for your help with this, it's much appreciated. – Ali Sep 08 '14 at 16:32
  • Apparently you're actually using JSF 1.x. Nevermind then. I just wouldn't expect that these days, certainly not since XHTML is being used which is typically the default for JSF 2.x. – BalusC Sep 08 '14 at 16:40
  • Apparently it's running in 1.x fallback modus. Wrong faces-config version perhaps? – BalusC Sep 08 '14 at 19:28
  • @BalusC Oh my, have just got home and retried all your suggestions. It was the case of the 'C' after all. Thanks so much for pointing me in the right direction. – Ali Sep 08 '14 at 19:58
0

I am using JSF 2.2, so all I needed to do was use the correct case in Create:

<h:commandLink action="/absence/Create"
    value="#{bundle.TasksEmployeeCreateAbsenceLink}"  >
        <f:setPropertyActionListener target="#{absenceController.selected.employee}"
            value="#{employeeController.selected}" />
</h:commandLink>
Ali
  • 109
  • 7