• Post Reply Bookmark Topic Watch Topic
  • New Topic

Websphere 7 to 8 Conversion issue with SelectItem nulls vs. empty String

 
Mike Antrim
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all, First post so forgive me if I didn't do this right, and apologies if this has already been answered, but I can't find it if it has.

We're converting servers from WAS 7 to WAS 8.5. When nothing was selected from a SelectItem in WAS 7, we got a null returned. In WAS 8.5, we're now getting a empty String (""). I added debug lines to display the values. It looks like the Setter is where the change occurs.

Code:
public void setSearchStatusCode(String searchStatusCode) {
this.searchStatusCode = searchStatusCode;
log.error("DTO Set Status = " + searchStatusCode);[/code] }
JSF (1.2):
<h:selectOneMenu id="searchStatusCode"
value="#{searchStatusBean.searchStatusDTO.searchStatusCode}"
styleClass="selectOneMenu" style="width: auto" >
<f:selectItem itemValue="" itemLabel="ALL" />
<f:selectItems value="#{searchStatusBean.statusCodeList}" />
</h:selectOneMenu>

WAS 7:
DTO Set Status = null
WAS 8.5:
DTO Set Status =

I added other debugging and the value is "" when the screen is initially rendered, but after clicking on a Search button, the setter is invoked and I don't see any way to intervene (other than changing the setter itself).

This is causing null pointer exceptions. Our app has 115 screens with 900+ SelectItems on them, so I hope there's some quick and global change that can be done.

I tried creating a converter but that is having no impact because when it's invoked the value is already null.

public class EmptyToNullConverter implements Converter {
private final static Logger logger = Logger.getLogger(EmptyToNullConverter.class);

public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {

if (value == null || value.trim().length() == 0) {
if (component instanceof HtmlSelectOneMenu) {
((EditableValueHolder) component).setSubmittedValue(null);
}
return null;
}
return value;
}

public String getAsString(FacesContext facesContext, UIComponent component, Object value) {

if (component instanceof HtmlSelectOneMenu) {
((EditableValueHolder) component).setSubmittedValue(null);
if (value == null || value.equals("")) {
return null;
}
else {
return value.toString();
}
}
else {
return (value == null) ? null : value.toString();
}
}

Thanks for your help.
 
Tim Holloway
Bartender
Posts: 18412
58
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the JavaRanch, Mike!

In most cases, when your question is server-specific, we recommend that you ask in the forum dedicated to that server, but let's start off with general JSF issues and see if that helps.

Incidentally, your message editor has a "Code" button that can be used to make Java code, XML, and other pre-formatted text easier to read!

JSF is an HTML-based technology (at least when the default rendering subsystems are in use!), and HTML is a text form, not a binary form, so the concept of "NULL" on the client side (HTML) doesn't exist. The way things usually work is that if you RENDER a JSF View from a null string, the page will render the null string as "" going out, and the HTML form POST back to JSF will send back "" instead of NULL, since there's no way to tell whether the original rendered property was "" or NULL and, as I said, HTML needs text.

How WAS might have managed to get NULL values to come in is a puzzle to me.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!