0

I have a problem with the JSF selectOneMenu.

Here is my menu:

<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
  xmlns:ui="http://java.sun.com/jsf/facelets"
  xmlns:f="http://java.sun.com/jsf/core"
  xmlns:h="http://java.sun.com/jsf/html">

    <ui:composition template="./../WEB-INF/templates/templateLC.xhtml">

        <ui:define name="headtags">
            <title>Title</title>
        </ui:define>

        <ui:define name="left">
            <ui:include src="./../WEB-INF/templates/userCenterNavigation_left.xhtml"/>
        </ui:define>

   <ui:define name="content">

<h:form>
     <table>
        <tr>
           <td>Kategorie:</td>
           <td><h:selectOneMenu value="#{zbnEditController.zbnCategory}">
               <f:selectItems value="#zbnEditController.zbnCategoryMap}"/>
               </h:selectOneMenu>
           </td>
        </tr>
      </table>
      <br />
      <h:commandButton value="Hinzufügen" action="#{zbnEditController.doSave()}" />
      <h:commandButton value="Abbrechen" action="index.xhtml?faces-redirect=true" />
</h:form>

This is a part of my template:

<h:head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <h:outputStylesheet name="/css/newCssLayout.css"/>   
    <ui:insert name="headtags" />
</h:head>

This is my Bean with the Map property:

@Named
@SessionScoped
public class ZbnEditController implements Serializable {

@Inject
private ZbnCategoryService zbnCategoryService;

.
.
.

private Map<String,ZbnCategory> zbnCategoryMap = new HashMap<>();

//Getter & Setters...

public void doSave(){

    //persist Entity Code
}

public void loadZbnCategoryMap(){

    getZbnCategoryMap().clear();
    List<ZbnCategory> zbnCategoryList = zbnCategoryService.getAllZbnCategorys();

    for(ZbnCategory zbnCategoryInList : zbnCategoryList){
        zbnCategoryMap.put(zbnCategoryInList.getZbnCategoryName(), zbnCategoryInList);
    }
}
}

Before the page is rendered, a Controller, calls loadZbnCategoryMap() and fills the map with the String and the object.

There are no nested forms, no ui component has a rendered=false attribute and I included the "h:head" tag instead of "head".

If I use the code above and click the commandButton, the doSave() method IS NOT called. If I remove the h:selectOneMenu, everything works fine.

I don´t know how I can solve this problem. Can someone help please?

Rallenaldo
  • 107
  • 8
  • Next time when command link/button is not invoked, head to http://stackoverflow.com/q/2118656 You should have learnt about a setting to see development stage messages, and a component to see conversion/validation errors directly. The actual conversion error message you got is in turn an excellent search keyword. Here's another related reading: http://stackoverflow.com/q/6848970 – BalusC Jun 10 '16 at 10:17

1 Answers1

0

I somehow "solved" the problem. It seems, that h:selectOneMenu has problems with saving objects to a bean.

Found a workaround that I save a String to the bean and just before persisting the Object, I use that String to load the entity from the database.

Rallenaldo
  • 107
  • 8