views:

23

answers:

0

Hi guys, I'm currently struggling with request parameters in JSF 2 and Icefaces 2 (shouldn't make a difference to only JSF 2) and would like to ask you about the recommended way to handle / process parameters.

The problem I encounter occurs when using an ice:dataTable. Every time I hit the submit button (or fire a row selection event by clicking on a row) it reloads all the data (which is specified by the value attribute of the data table). Unfortunately it doesn't takes care of request parameters. The used data depends on a request parameter (i.e. update.html?projectId=42).

Let me show you a simplified version of the source code: Backing bean

// ...
private Project project;
private String projectId;

public void addIteration() {
    System.out.println("+++additeration");
}

public void setProjectId(String projectId) {
    System.out.println("+++setProjectId");

    this.projectId = projectId;

    if (!loadRequiredData()) {
        throw new RuntimeException("Can't find project / your not allowed to do that!");
    }
}

private boolean loadRequiredData() {
    // method loading information from the database based on the
    // projectId attribute.
    // returns true if successful, false otherwise
}

public Collection<Iteration> getIterations() {
    // Get the iterations from the project variable.
    // The project variable will be initialized by setProjectId method,
    // which will automatically be called when the id parameter is set
    // see xhtml file
}

public void rowIterationSelectionListener(RowSelectorEvent event) {
    System.out.println(event.getRow());
}

public Project getProject() {
    return project;
}

public String getProjectId() {
    return projectId;
}

// ...

projectDetails.xhtml

<!-- ... -->
<f:metadata>
    <f:viewParam id="projectId" name="id" value="#{projectDetails2Controller.projectId}" />
</f:metadata>
<!-- ... -->
<ice:form>

    <ice:dataTable value="#{projectDetails2Controller.iterations}" var="item">

        <ice:column>
            <ice:rowSelector selectionListener="#{projectDetails2Controller.rowIterationSelectionListener}" />

            <ice:outputText value="#{item.name}" styleClass="iterationName" />
            <ice:outputText value="#{item.id}" styleClass="iterationId" visible="false" />
        </ice:column>

    </ice:dataTable>

    <ice:commandButton value="Add iteration" action="#{projectDetails2Controller.addIteration}" />

</ice:form>
<!-- ... -->

Is this the right way to handle request parameters or is there a better way? Also, if I remove the data table the button click doesn't result in an error.

Kind regards,

Ben