0

My application have three beans which are Questions,Answers,AnswerTypes and in xhtml I wanted to load answertypes(which are already available in Db) to and once I click save I get error

sourceId=j_idt4:j_idt8[severity=(ERROR 2), summary=(j_idt4:j_idt8: Validation Error: Value is not valid), detail=(j_idt4:j_idt8: Validation Error: Value is not valid)]

My Coding are

<h:form> 
            <h:outputLabel for="questions" value="Question:" />
            <h:inputText id="questions" value="#{questions.question}"/>
            <h:outputLabel for="answers" value="Answer:" />
            <h:inputText id="answers" value="#{answers.answer}"/>
            <h:outputLabel for="answers" value="Answer Type:" />

            <h:selectOneMenu for="answers" value="#{answers.answerTypeId}">
                <f:selectItems value="#{answers.answeTypesMap.entrySet()}" var="answeTypesMap" 
                itemValue="#{answeTypesMap.key}" itemLabel="#{answeTypesMap.value}" />
            </h:selectOneMenu>

            <h:commandButton value="Save" action="#{utilizerManager.saveQuestions}"/>

    </h:form>

this is XHTML

class Answer{
  private int answerTypeId = 0;
  private HashMap<Integer, String> answeTypesMap;

  public void init(ComponentSystemEvent event) {
    FacesContext facesContext = FacesContext.getCurrentInstance();
    if (!facesContext.isPostback() && !facesContext.isValidationFailed()) {
        AnswerTypes ansTypes = new AnswerTypes();
        setAnsweTypesMap(ansTypes.loadAnswerTypes());
    }
}


}

Class Answer and AnswerTypes Map Loaded

class Question{
 public void saveQuestion(){
    DbConnector.connectToDatabase();
    int autoTempId = DbConnector.getPrimaryKeyLastValue("questions", "questionId");
    questionId = autoTempId+1;
    String insertQuery = "insert into questions(questionId,question,autoId,correctAnswer) values("+questionId+",'"+question+"',"+autoID+","+correctAnswer+")";
    DbConnector.InsertionQuery(insertQuery);
    DbConnector.ClearConnection();
}
}

My questions class

and Finally my UtilizerManager class

class UtilizeManager{
  // I wanted to save answer and then get the aswerId to set questions bean
  public void saveQuestions(){
    answersBean.saveAnswer();
    questionBean.setCorrectAnswer(answersBean.getAnswerId());
    questionBean.saveQuestion();
    }
}

So please be help on this scenario, As per my understand this (Root cause analysis) Error is with

<h:selectOneMenu for="answers" value="#{answers.answerTypeId}">
                <f:selectItems value="#{answers.answeTypesMap.entrySet()}" var="answeTypesMap" 
                itemValue="#{answeTypesMap.key}" itemLabel="#{answeTypesMap.value}" />
            </h:selectOneMenu>

following code path in xhtml please tell me how to solve this that map is HashMap

reason to use such is when saving item I need to get saved Integer and when displaying I need to get displayed Text

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
RezgHansa
  • 45
  • 11
  • No class is designated as a bean class. This could happen out of several other reasons, when for example, a bean is designated with a wrong narrower scope where a broader bean scope is expected. [See](http://stackoverflow.com/a/9069660/1391249) for the details. – Tiny Aug 26 '16 at 04:24
  • @Tiny Thanks a lot it was issue with bean scopes :D once I used application scope it worked as I wanted. – RezgHansa Aug 26 '16 at 05:34

0 Answers0