[
https://issues.apache.org/jira/browse/WW-4168?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13734609#comment-13734609
]
Greg Huber commented on WW-4168:
--------------------------------
Bruce,
This was a recent mod done by Lukasz as the checkboxlist was not rendering
correctly. Also, if I switch back to the standard theme I do not get the npe.
.....Sorry, I will explain how I do the list so forgive me!
The backing variables for the checkbox list start off as a string in my db
(which can be null in its initial state), and are split to a string[] to match
the available plugins:
eg:
db >> defaultPluginsArray = "Convert Line Breaks,Smilies"
bean class:
if (db.getDefaultPlugins() != null) {
defaultPluginsArray = StringUtils.split(db.getDefaultPlugins(), ",");
}
/**
* Gets the default plugins array. >>>> bean.defaultPluginsArray on
<s:checkboxlist below
*
* @return the default plugins array
*/
public String[] getDefaultPluginsArray() {
return defaultPluginsArray;
}
Then I have available plugins as a list. These will be "Convert Line Breaks"
and "Smilies"
/**
* Gets the plugins list. >>>> pluginsList on <s:checkboxlist below
*
* @return the plugins list
*/
public List<EventEntryPlugin> getPluginsList() {
return pluginsList;
}
>>>> listKey="name" listValue="name" on <s:checkboxlist below
#1 EventEntryPlugin.getName() = Convert Line Breaks
#2 EventEntryPlugin.getName() = Smilies
The checkbox list then checks the two values and if they match it shows whether
or not its selected.
<s:checkboxlist list="pluginsList" name="bean.defaultPluginsArray"
listKey="name" listValue="name" />
However, if the initial state in the db of bean.defaultPluginsArray = null, we
get the npe.
In your example that you used to test it, make sure the backing variable in
s:checkboxlist name == null.
I could possible modify the example but I don't use maven and checkig out
form_tags example gives lots of errors.
Cheers Greg
> NullPointerException on Checkboxlist
> -------------------------------------
>
> Key: WW-4168
> URL: https://issues.apache.org/jira/browse/WW-4168
> Project: Struts 2
> Issue Type: Bug
> Components: Plugin - Java Templates
> Affects Versions: 2.3.15.1
> Environment: tomcat/centos 5
> Reporter: Greg Huber
> Assignee: Bruce Phillips
> Priority: Minor
> Fix For: 2.3.16
>
>
> Hello,
> I am getting null pointer exceptions on line :
> Caused by: java.lang.NullPointerException
> at template.events.CheckboxListHandler.isChecked(CheckboxListHandler.java:125)
> at template.events.CheckboxListHandler.generate(CheckboxListHandler.java:80)
> at org.apache.struts2.views.java.DefaultTheme.renderTag(DefaultTheme.java:120)
> at
> org.apache.struts2.views.java.JavaTemplateEngine.renderTemplate(JavaTemplateEngine.java:95)
> at org.apache.struts2.components.UIBean.mergeTemplate(UIBean.java:572)
> at org.apache.struts2.components.UIBean.end(UIBean.java:526)
> we need to check for if(nameValues)!=null
> ie:
> {code:java}
> private Boolean isChecked(Map<String, Object> params, String itemKeyStr) {
> Boolean checked = false;
> if (itemKeyStr != null) {
> String[] nameValues = (String[]) params.get("nameValue");
> if(nameValues)!=null // need this <<<<<<<<<<
> for (String value : nameValues) {
> if (checked = value.equalsIgnoreCase(itemKeyStr))
> { break; }
> }
> }
> }
> return checked;
> }
> {code}
> Cheers Greg
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira