Reputation: 24679
I am trying to pass two parameters i.e. (nomComposantARejouer
, typeFileARejouer
) to an action method (gestionnaireMessagesController.rejouerMessage
) using the setPropertyActionListener
(we use jsf 1.2).
Here is the relevant jsp code:
<h:column>
<h:columnHeaderFacet>
<h:columnHeader value="#{msgs['pilotage.coordinateur.libelle.rejouer']}" />
</h:columnHeaderFacet>
<h:commandLink id="rejouer"
value="#{msgs['pilotage.coordinateur.libelle.rejouer']}"
action="#{gestionnaireMessagesController.rejouerMessage}">
<f:setPropertyActionListener
target="#{gestionnaireMessagesController.nomComposantARejouer}"
value="#{gestionnaireMessagesController.nomComposant}" />
<f:setPropertyActionListener
target="#{gestionnaireMessagesController.typeFileARejouer}"
value="#{gestionnaireMessagesController.typeFile}" />
</h:commandLink>
</h:column>
However, I always get a NPE because both parameters are null when used in the action method:
public String rejouerMessage() {
log.debug("-->"+nomComposantARejouer);//null
ParamResultatMessagesDTO message= (ParamResultatMessagesDTO) messagesTableau.getRowData();
log.debug("MessageId: " + message.getMessageId());
try {
Pager p = Pager.getInstance();
ParamRejouerMessageDTO prm = new ParamRejouerMessageDTO();
prm.setMessageId(message.getMessageId());
prm.setFileGet(nomsFilesMap.get(nomComposantARejouer).get(typeFileARejouer));
prm.setFilePut(nomsFilesMap.get(nomComposantARejouer).get("TASKQ"));
RejouerMessageService serv = (RejouerMessageService) this.getService(ServiceCst.REJOUER_MESSAGE_SERVICE);
serv.rejouerMessage(prm);
} catch (BusinessException e) {
this.addMessage(e);
} catch (ServiceException e) {
this.addMessage(e);
}
return chargerPage(); // TODO Navigation case.
}
I am not sure what I am getting wrong. Can anyone please help?
FYI, the variables nomComposant
and typeFile
can be displayed without problem and are not null.
Also ignore the h:columnHeaderFacet tags. They are inhouse tags that I've renamed.
Upvotes: 0
Views: 4536
Reputation: 1108852
You're basically doing:
gestionnaireMessagesController.setNomComposantARejouer(gestionnaireMessagesController.getNomComposant());
gestionnaireMessagesController.setTypeFileARejouer(gestionnaireMessagesController.getTypeFile());
during the invoke action phase of the form submit. Both properties are in the same bean instance and copied shortly before action method is invoked. This makes no sense. You seem to be expecting that the value
is evaluated during the request of displaying the form. You seem to be thinking that <f:setPropertyActionListener>
sets a request parameter. This is not true. The <f:param>
is the only which does that.
So, this should do,
<f:param
name="nomComposantARejouer"
value="#{gestionnaireMessagesController.nomComposant}" />
<f:param
name="typeFileARejouer"
value="#{gestionnaireMessagesController.typeFile}" />
in combination with the following on <managed-bean>
of gestionnaireMessagesController
in faces-conig.xml
:
<managed-property>
<property-name>nomComposantARejouer</property-name>
<value>#{param.nomComposantARejouer}</value>
</managed-property>
<managed-property>
<property-name>typeFileARejouer</property-name>
<value>#{param.typeFileARejouer}</value>
</managed-property>
(you can if necessary remove ARejouer
so that it reuses the same property)
Upvotes: 2
Reputation: 1732
I have often encountered this problem , it occours when there are two f:setPropertyActionListener
.
You try in this way:
<h:commandLink id="rejouer"
value="#{msgs['pilotage.coordinateur.libelle.rejouer']}"
action="#{gestionnaireMessagesController.rejouerMessage}"> <f:param
name="nomComposant"
value="#{gestionnaireMessagesController.nomComposant}" />
<f:param name="typeFile"
value="#{gestionnaireMessagesController.typeFile}" />
</h:commandLink>
Read this link: http://www.coderanch.com/t/211274/JSF/java/Passing-param-commandLink
Upvotes: 1