0

I am trying to set up 2 chained select boxes using JSF and PrimeFaces. I have created them as in the example on the official site, however:

  1. When i enter the page using the new button(no existing record to be displayed) the change event will return a 500 error from the controller
  2. When i enter the page using the edit button(there is an existing record) the change event will not return a 500 error, however the id from the select is not mapped to the record.

Any help would be appreciated.

Relevant code bits below:

<?xml version="1.0" encoding="UTF-8"?>
<ui:composition 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"
            xmlns:p="http://primefaces.org/ui"
            xmlns:o="http://omnifaces.org/ui"
            template="/WEB-INF/templates/page.xhtml">

<f:metadata>
    <o:viewParam name="userUploadedWorkId" value="#{userUploadedWorkController.userUploadedWork}"
                 converter="#{userUploadedWorkConverter}"
                 converterMessage="Solicitare eronata. Va rugam sa navigati in aceasta pagina dintr-o lista de lucrari"/>
</f:metadata>

<ui:define name="bread-crumb">
    <p:menuitem value="Lucrarile mele" outcome="user-uploaded-work-list?faces-redirect=true"/>
    <p:menuitem
            value="#{userUploadedWorkController.userUploadedWork.id eq null ? 'Lucrare noua' : userUploadedWorkController.userUploadedWork.title}"
            url="#"/>
</ui:define>

<ui:define name="page-content">

    <h:form>
        <p:panelGrid columns="2" columnClasses="right-aligned,raw" id="user-uploaded-work-details">
            <f:facet name="header">Detalii lucrare</f:facet>

            <p:outputLabel value="Titlu" for="uuwTitle"/>
            <p:inputText id="uuwTitle" value="#{userUploadedWorkController.userUploadedWork.title}" required="true"
                         style="width: 400px"/>


            <p:outputLabel value="Capitol" for="chapter"/>
            <p:selectOneMenu style="width: 400px" required="true" id="chapter" value="#{userUploadedWorkController.userUploadedWork.criterion eq null?'':userUploadedWorkController.userUploadedWork.criterion.chapter.id}" effect="fade">  
                <f:selectItem itemLabel="Select One" itemValue="" />  
                <f:selectItems value="#{chapters}" var="ch" itemLabel="#{ch.name}" itemValue="#{ch.id}"/> 
                <p:ajax update="uuwCriterion" listener="#{userUploadedWorkController.chapterChange}"/> 
            </p:selectOneMenu>            

            <p:outputLabel value="Criteriu" for="uuwCriterion"/>
            <p:selectOneMenu style="width: 400px" required="true" id="uuwCriterion" value="#{userUploadedWorkController.userUploadedWork.criterion eq null?'':userUploadedWorkController.userUploadedWork.criterion.id}" effect="fade">  
                <f:selectItem itemLabel="Select One" itemValue="" />  
                <f:selectItems value="#{userUploadedWorkController.criteria}" var="criterion" itemLabel="#{criterion.name}" itemValue="#{criterion.id}"/>  
            </p:selectOneMenu>     


            <f:facet name="footer">
                <p:message for="uuwTitle"/>
                <p:message for="uuwCriterion"/>
                <p:message for="uuwChapter"/>

                <p:commandButton action="#{userUploadedWorkController.save}" value="Salveaza atribute" process="@form"
                                 update="@form :messages" icon="ui-icon-disk"/>
                <p:button outcome="user-uploaded-work-list?faces-redirect=true" value="Lista lucrari"
                          icon="ui-icon-arrowreturnthick-1-e"/>
            </f:facet>
        </p:panelGrid>

    </h:form>

</ui:define>

The managed bean:

@Named
@ViewScoped
public class UserUploadedWorkController implements Serializable {
private static final long serialVersionUID = -4736897416993974840L;

@Inject
private OrganizationalChartService service;

private UserUploadedWork userUploadedWork = new UserUploadedWork();

private List<Criterion> criteria;

public UserUploadedWork getUserUploadedWork() {
    return userUploadedWork;
}

public void setUserUploadedWork(UserUploadedWork userUploadedWork) {
    this.userUploadedWork = userUploadedWork;
}

@PostConstruct
public void init() {
    criteria = service.findAllCriteria();
}

public List<Criterion> getCriteria() {
    return criteria;
}

public void setCriteria(List<Criterion> criteria) {
    this.criteria = criteria;
}

public String save() {
    userUploadedWork.setCriterion(service.findById(Criterion.class, userUploadedWork.getCriterion().getId()));
    userUploadedWork.setUser(service.findBySimpleProperty(User.class, "email", LoginController.getRequest().getUserPrincipal().getName()));
    userUploadedWork = service.merge(userUploadedWork);
    Messages.addFlashGlobalInfo("Salvare efectuata cu succes");
    return "user-uploaded-work-list?faces-redirect=true";
}


public void chapterChange() {
    if (userUploadedWork.getChapter() != null
            && userUploadedWork.getChapter().getId() != null) {
        criteria = service.findCriteriaByChapter(userUploadedWork.getChapter().getId());
    } else {
        criteria = new ArrayList<Criterion>();
    }
}
}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I am using DeltaSpike also, so it should have CDI – user2492802 Jun 21 '13 at 09:24
  • 1
    500 error means that an exception is thrown. Please lookup and post the stacktrace. Or at least the ajax response if there's no stacktrace. The exception message is also in ajax response. – BalusC Jun 21 '13 at 12:11
  • Actually i managed to solve the 500 error, but the value sent from the combo is still not mapping to the model..... i'm a bit at a loss why – user2492802 Jun 21 '13 at 12:59

0 Answers0