JSF bookmarking issue

I have an h: datatable that displays employee data. I want the user to click on the employee’s name to go to a new page whose URL looks like

employees?id=<some id>

I tried to combine JSP EL with JSF EL, but there is no way out.

+3
source share
2 answers

If you are not yet using JSF 2.0, you can use h:outputLinkin conjunction with <f:param>, #{param}and faces-config.xml.

An example of a base table:

<h:dataTable value="#{bean.employees}" var="employee">
    <h:column>
        <h:outputLink value="employees.jsf">
            <f:param name="id" value="#{employee.id}" />
            <h:outputText value="View employee #{employee.name}" />
        </h:outputLink>
    </h:column>
</h:dataTable>

Basic example faces-config.xml:

<managed-bean>
    <managed-bean-name>employeeManager</managed-bean-name>
    <managed-bean-class>com.example.EmployeeManager</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    <managed-property>
        <property-name>id</property-name>
        <value>#{param.id}</value>
    </managed-property>
</managed-bean>

Basic example com.example.EmployeeManager:

public class EmployeeManager {
    private Long id;
    private Employee employee;

    @PostConstruct
    public void init() {
        this.employee = employeeDAO.find(this.id);
    }
}

@PostConstuct bean . . .

+2

, :

Java EE 6, № 1.

. JSF 2 2 : <h:link /> <h:button />. GET POST. , <f:viewparam />. , JSF 2 . . .

+2

Source: https://habr.com/ru/post/1728618/


All Articles