2

I have f:param like below...

<f:param name="NDCID" value="#{selectedMedicationInfoBean.NDCID}"></f:param>
<f:param name="insuranceID" value="#{selectedMedicationInfoBean.insurance.id}"></f:param>

in few cases

#{selectedMedicationInfoBean.insurance.id}

comes null. Can we prevent it? I can't use turnery operator inside JSF Expression.

<f:param name="insuranceID" value="#{selectedMedicationInfoBean.insurance.id=null?'':selectedMedicationInfoBean.insurance.id}">

Is there any other way?


Functional Requirement : On page1 there is a link of detail. That will show detail information on page2. As argument need to pass around 6 parameters. On the bases of those parameters detail page will generate information.

And issue is from those 6 parameters 2 can be null and cause of that below error come on view page1.

java.lang.NullPointerException
com.sun.faces.renderkit.RenderKitUtils.getCommandLinkOnClickScript(RenderKitUtils.java:934)
com.sun.faces.renderkit.html_basic.CommandLinkRenderer.getOnClickScript(CommandLinkRenderer.java:295)
com.sun.faces.renderkit.html_basic.CommandLinkRenderer.renderAsActive(CommandLinkRenderer.java:357)
com.sun.faces.renderkit.html_basic.CommandLinkRenderer.encodeBegin(CommandLinkRenderer.java:165)
javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:788)
org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils.renderChild(RendererUtils.java:433)
org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils.renderChildren(RendererUtils.java:419)
org.apache.myfaces.shared_tomahawk.renderkit.RendererUtils.renderChild(RendererUtils.java:440)
Ketan Bhavsar
  • 5,338
  • 9
  • 38
  • 69
  • What exactly is the functional requirement? So that we can understand better why it's a problem to send an empty/null parameter. – BalusC May 04 '12 at 17:33
  • @BalusC , I have set my display name as 'Guruji' and that means 'A Teacher' but I can say you are my guruji for this JSF. Thanks a lot for your quick response. – Ketan Bhavsar May 04 '12 at 17:45
  • Oh, you're using old JSF 1.2. In the future questions please mention exact JSF impl/version. I'll post an answer. – BalusC May 04 '12 at 17:49

1 Answers1

2

That exception is caused by an old Mojarra 1.2 bug which indeed manifests when the <f:param> value is null. It's been fixed in Mojarra 1.2_05 (or maybe one version before or after, not sure anymore, it's been more than 6 years ago). Just upgrade to latest Mojarra 1.2 which is currently already at 1.2_15.

An alternative is to wrap it in a <c:if>, but that's plain ugly and also won't work if selectedMedicationInfoBean is been declared as the var of some parent UIData component.

<c:if test="${not empty selectedMedicationInfoBean.insurance.id}">
    <f:param name="insuranceID" value="#{selectedMedicationInfoBean.insurance.id}" />
</c:if>

Another alternative is to specify a default value of 0 or -1 instead and handle accordingly in the controller.

<f:param name="insuranceID" value="#{not empty selectedMedicationInfoBean.insurance.id ? selectedMedicationInfoBean.insurance.id : -1}" />

Upgrading is the best option. You don't want to sit with a prehistoric library.

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • But as per http://stackoverflow.com/questions/10418413/jsf-tdatatable-and-cforeach-looks-like-conflict if my link is inside datatable wont it be conflict? – Ketan Bhavsar May 04 '12 at 17:56
  • If `selectMEdicationInfoBean` is definied by its `var` then yes it will cause a problem. You'd really need to upgrade to a newer Mojarra 1.2 version then. – BalusC May 04 '12 at 17:58
  • yeah that's same it come from `var`... :( – Ketan Bhavsar May 04 '12 at 18:01