Results 1 to 5 of 5
  1. #1
    gmjord is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    Hi.

    I am trying to write a jsf application that simply generates 2 random numbers, has the user multiply the numbers together and then displays a page to tell the user if they got the correct answer or not.

    The page that displays the 2 randomly generated numbers display ok but when I type in the answer and hit the submit button I get the following error:

    javax.el.PropertyNotWritableException: /mathGreeting.xhtml @24,61 value="#{multiply.userAnswer}": The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    The error happens at the line that is red

    Here is my first web page

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html lang="en"
    xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core">

    <h:head>
    <h:outputStylesheet library="css" name="default.css"/>
    <title>Multiply two Numbers Facelets Application</title>
    </h:head>
    <h:body>
    <h:form>
    <h:graphicImage value="#{resource['images:multiply.gif']}"
    alt="Multiplication Symbol"/>
    <h2>
    Hi, my name is Mitch. I want you to multiply the following two Numbers:
    #{multiply.operandA} and #{multiply.operandB}.
    Can you do it?
    </h2>
    <p>
    <h:inputText id="userNo"
    title="Type your answer:"
    value="#{multiply.userAnswer}">
    </h:inputText>
    <h:commandButton id="submit" value="Submit"
    action="response"/>
    </p>
    <h:message showSummary="true" showDetail="false"
    style="color: #d20005;
    font-family: 'New Century Schoolbook', serif;
    font-style: oblique;
    text-decoration: overline"
    id="errors1"
    for="userNo"/>
    </h:form>
    </h:body>
    </html>
    *************************
    Here is my managed bean

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package hello;

    import java.io.Serializable;
    import java.util.Random;
    import javax.faces.bean.ManagedBean;
    import javax.faces.bean.SessionScoped;

    /**
    *
    * @author Mitch Jordan
    */
    @ManagedBean
    @SessionScoped
    public class Multiply implements Serializable {

    private static final long serialVersionUID = 5443351151396868724L;
    private long operandA;
    private long operandB;
    private long userAnswer;

    public Multiply() {

    Random randomGR = new Random();
    this.operandA = new Integer(randomGR.nextInt(10));
    this.operandB = new Integer(randomGR.nextInt(10));
    System.out.println("a: " + operandA);
    System.out.println("b: " + operandB);

    }

    public long getOperandA() {
    return operandA;
    }

    public void setOperandA(int operandA) {
    this.operandA = operandA;
    }

    public long getOperandB() {
    return operandB;
    }

    public void setOperandB(int operandB) {
    this.operandB = operandB;
    }

    public long getUserAnswer() {
    return userAnswer;
    }

    public void setUserAnswer(int userAnswer) {
    this.userAnswer = userAnswer;
    }

    public String getResponse() {
    if (userAnswer == calculateProduct()) {
    return "Yay! You got it!";
    } else {
    return "Sorry, the correct answer is: " + calculateProduct();
    }
    }

    public long calculateProduct() {
    return operandA * operandB;
    }
    }
    **********************

    Thanks for any help that you can give to me!!

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    Quote Originally Posted by gmjord View Post
    I am trying to write a jsf application ...
    Moved from New to Java.

    Please go through the Guide For New Members and BB Code List - Java Programming Forum - Learn Java Programming and format your post accordingly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    note how getUserAnswer() and setUserAnswer() have different types - long and int.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    gmjord is offline Member
    Join Date
    Aug 2013
    Posts
    4
    Rep Power
    0

    Default Re: The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    Quote Originally Posted by gimbal2 View Post
    note how getUserAnswer() and setUserAnswer() have different types - long and int.

    Thanks! That did the trick!

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,365
    Rep Power
    6

    Default Re: The class 'hello.Multiply' does not have a writable property 'userAnswer'.

    Remember: programming is an act of the utmost precision. You have to write and inspect the code with care to do it correctly.

    PS: also follow mr. Burke's advice, if you would be so kind. If you make the effort to create a proper post, you will get better help faster.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Writable cell without coping of new excel sheet
    By tpr245 in forum Forum Lobby
    Replies: 1
    Last Post: 11-16-2012, 10:23 PM
  2. Replies: 0
    Last Post: 08-04-2011, 06:16 PM
  3. Replies: 0
    Last Post: 01-25-2011, 07:02 AM
  4. PDF - Editable/Writable
    By ananddevaraj in forum Java Servlet
    Replies: 0
    Last Post: 06-05-2010, 11:46 AM
  5. Replies: 0
    Last Post: 06-25-2009, 06:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •