Pergunta

I have in a seam page for a table rows used a repeater like this:

<a4j:repeat id="r1279186" value="#{PatientList.entities}" var="Patient" rowKeyVar="rowIndex" >
<tr>
<td>
    <a4j:commandButton action="#{PatientAction.inject(Patient)}" id="Button_1279184059161" reRender="Button_1287648925796" limitToList="true" />
</td>
<td  >
    <span >#{Patient.name_fam}</span>
</td>
<td  >
    <span >#{Patient.name_giv}</span>
</td>
    <td>
    <s:link id="Page_1234" action="#{PatientAction.inject(Patient)}"  view="/somewhere/patient_details.seam" rendered="true" target="_blank" propagation="join" title="VIS" limitToList="true" >
    <img src="images/24x24/info.png" title="VIS" alt="VIS}" style="height: 24px;width: 24px;"/>
    </s:link>
</td>
</tr>

PatientAction is a bean, with method called inject, which take a Patient class Object in input. PatientList.entities is a List, the repeater cycles on a var named Patient, the same name of object class.

Before return the page to the client, seam renders the name and surname for each patient (row) in list, and add one button in the first column and one link in the last.

Using the button the action is executed when I click the button, receiving in the parameter of inject the Patient corresponding to the row where I pressed the button. [OK!]

When I use the link (which I use to open a new browser page, maintaining the same conversation) the method inject is called exactly when I click, but the parameter passed is null!! (I can see in debug of my inject method, the Patient coming is null)

Foi útil?

Solução

You cannot pass parameters to an <s:link/> action from a repeat element, as stated in http://docs.jboss.org/seam/2.0.1.GA/reference/en/html/elenhancements.html#d0e22695

Cite:

Use inside iterative components — Components like <c:forEach/> and <ui:repeat/> iterate over a List or array, exposing each item in the list to nested components. This works great if you are selecting a row using a <h:commandButton/> or <h:commandLink/>.

However if you want to use <s:link/> or <s:button/> you must expose the items as a DataModel, and use a <dataTable/> (or equivalent from a component set like <rich:dataTable/>). Neither <s:link/> or <s:button/> submit the form (and therefore produce a bookmarkable link) so a "magic" parameter is needed to recreate the item when the action method is called. This magic parameter can only be added when a data table backed by a DataModel is used."

So, you must use <h:commandLink/> instead of <s:link/>, alternatively you can create a bookmarkable link as follows:

<s:link view="/somewhere/patient.details.xhtml">
    <f:param name="patientId" value="#{Patient.id}" />
    ...
</s:link>

This produces a link like this in HTML: /somewhere/patient_details.seam?patientId=5. Since the patient ID is carried in the link, the patient_details.xhtml page has the needed information to retrieve the data for display.

To do this, you need to put a parameter definition in patient_details.page.xml so that the value is picked up before the page is displayed, for example:

<!-- Here we use an EntityHome component, assuming Patient is a JPA entity.
     When you set the ID of an EntityHome component, it automatically triggers
     an EntityManager.find() call to retrieve the Entity from DB. -->
<param name="patientId" value="#{patientHome.id}" />
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top