Current Position:Home > NullPointerException trying to render

NullPointerException trying to render

Update:11-30Source: network consolidation
I have a scenario I am not sure about. I have a command button tag on a JSF page. This tag is binded to a HtmlCommandButton instance field on a backing bean e.g.
<h:commandButton type="button" value="Find"
                                       immediate="false"/>When the page is being rendered for the first time (initial reqest) I would like this button to be rendered depending on a certain condition. So in the constructor of the managed bean I put:
}The problem is I am getting a NullPointerException because the HtmlCommandButton variable offenderFindButton is null. When exactly does this variable get instantiated?
How am I able to conditionally render a HtmlCommandButton if not in the constructor of the bean?
Can someone please help?

The Best Answer

Try the rendered property in the tag itself.
Like this:
1) Define a boolean member in your backing bean and getter and setter for this boolean.
private boolean renderButton = false;
2) Include the rendered property in the button tag:
<h:commandButton id="button1" value="Button" action="next" rendered="#{backBean.renderButton}" ... />
Hope it helps you.
  • NullPointerException trying to render Update:11-30

    Hello, I have a scenario I am not sure about. I have a command button tag on a JSF page. This tag is binded to a HtmlCommandButton instance field on a backing bean e.g. <h:commandButton type="button" value="Find"                    

  • Advise on debugging? Update:10-11

    Hello, Could I ask, does this error mean the Render method cannot loop through the frames of the avi? Because the .avi could not be found? Thank you java.lang.NullPointerException at MyCustomCanvas.render( at MyCustomCanvas.pain

  • UIX-XML BC4J - Unexpected errors using paths and DeltaTree on a particular UIX page Update:10-11

    We are using a PageDescription to dynamically change a UIX tree using the DeltaTree technique described in the Dynamic Structure for For UIX Pages chapter of the UIX Developers Guide. We search for a particular node using PathUtils.FindPathWithNodeID

  • ADS render error Update:10-11

    Hi, Our BC group reviewed every note on SDN regarding  ads rendering problems. I am trying to create an offline PDF form (ready for input - optional), but we are still not able to find a proper solution. ADS service trace (not whole... it is rather l

  • Receive java.lang.NullPointerException (JCA-12563) on SCA with Stored Procedure dbAdapter (SOA Suite 12.1.3) Update:10-11

    Hi, I'm new to the Oracle SOA Suite and have been creating very simple SCA WebServices (async and sync) prototypes to INSERT, UPDATE and Poll Oracle 9i and 11g databases. So far, everything works and passes the tests from EM. I cannot get the Stored

  • Command_link rendered value binding causes NullPointerException Update:10-11

    command_link is put in a data_table. Intiailly, data_table has no rows. The command_link's render attribute is binded to a property of a row bean. e.g. <h:data_table id="resourcesTable"   value="#{mainPubFormBean.resources}"   bindi

  • Validate failure and report java.lang.NullPointerException Update:10-11

    there are three required textinput field in my dialog window . after input data into them, i click button to commit data, meet the validate failure error . report a java.lang.NullPointerException at these three fields bottom. others non-required fiel

  • Java.lang.NullPointerException in ExternalContextImpl.dispatch() Update:10-11

    I have a JSP page that uses JSF/ADF-Faces that throws the following error 15 times whenever the page is refreshed. If I redirect to another page and redirect back the error does not occur. I have a dialogReturnListener() that updates the page with a

  • Java.lang.NullPointerException with rich:pickList Update:10-11

    Hi every Body, I still getting a problem with my <rich:pickList> and really I need help. I got an error when executing the application, I debugged the application and I have notice that the problem cames from the PickList tag. the error is as follow

  • Java.lang.NullPointerException , with no refrence to my own source code.... Update:10-11

    what can cause this exception ? it does not point to any of my own source classes , i works fine in OC4J developer preview but not in standalone 06/10/16 16:44:55.109 web2: Servlet error java.lang.NullPointerException      at com.s