Results 1 to 5 of 5

Thread: JSF / Java EE - Why

  1. #1
    Join Date
    Oct 2008
    Posts
    35

    JSF / Java EE - Why

    Now I have worked a little with JSF, and will like to hear about from someone who can actually give a good reason that I should spend more 5min on this framework.

    As a simple case examples, I have created a quiz. It requires user input, data persistence between requests (session), and error messages. While I have added something localization.

    To show my quiz there must be a good set of code. The code base itself as to which variable is to put in a backing bean to be stored in request or session. It requires a lot of silly tests on a string result.

    But let's look at some code. To demonstrate:
    Code:
    <f:view> 
    <f:loadBundle var="locale" basename="website.resources.Locali 
    zation" /> 
    <h:form id="quiz"> 
    <div> 
    <p> 
    <strong> 
    Question <h:outputText value="#{Quiz.questionIndex + 1}" /> / 
    <h:outputText value="#{Quiz.numQuestions}" /> 
    </strong> 
    </p> 
    <h:outputText 
    styleClass="error" 
    rendered="#{Quiz.response == 'failure' && Quiz.allowingTries}" 
    value="#{locale['Quiz.WrongA 
    nswer']}" /> 
    <h:outputText 
    styleClass="error" 
    rendered="#{!Quiz.allowingTries}& 
    quot; 
    value="To Many Attemps (Max 3)" /> 
    <h:outputText 
    styleClass="approved" 
    rendered="#{Quiz.response == 'complete'}" 
    value="#{locale['Quiz.Comple 
    ted']}" /> 
    <h:panelGroup rendered="#{Quiz.response != 'complete' && Quiz.allowingTries}"> 
    <p> 
    <h:outputText value="#{Quiz.question}" /> = 
    <h:inputText  styleClass="field" value="#{Quiz.answer}" /> 
    </p> 
    <p> 
    <h:commandButton action="#{Quiz.answerQuestion}&quo 
    t; value="Answer" /> 
    </p> 
    </h:panelGroup> 
    </div> 
    </h:form> 
    </f:view>
    Like so additionally requires a class behind, but a lot of unnecessary code because of the java bean model.
    Code:
    package website.quiz; 
    
    import java.util.*; 
    
    public class Quiz 
    { 
    private final int MAX_TRIES = 3; 
    private List<QuizQuestion> questions = new ArrayList<QuizQuestion>(); 
    private int questionIndex = 0; 
    private QuizQuestion currentQuestion; 
    private String answer; 
    private String response; 
    private int numTries; 
    private boolean canTry = true; 
    
    public Quiz() 
    { 
    questions.add(new QuizQuestion("2 + 2","4")); 
    questions.add(new QuizQuestion("2 - 2","0")); 
    questions.add(new QuizQuestion("2 * 2","4")); 
    questions.add(new QuizQuestion("2 / 2","1")); 
    questions.add(new QuizQuestion("2^2","4&qu 
    ot;)); 
    
    currentQuestion = questions.get(questionIndex); 
    } 
    
    public boolean isAllowingTries() 
    { 
    return canTry; 
    } 
    
    public void setAllowingTries(boolean canTry) 
    { 
    // read only 
    } 
    
    public String getResponse() 
    { 
    return response; 
    } 
    
    public void setResponse(String response) 
    { 
    // read only 
    } 
    
    public QuizQuestion getQuestion() 
    { 
    return currentQuestion; 
    } 
    
    public void setQuestion(QuizQuestion question) 
    { 
    // read only 
    } 
    
    public String getAnswer() 
    { 
    // always return blank 
    return ""; 
    } 
    
    public void setAnswer(String answer) 
    { 
    this.answer = answer; 
    } 
    
    public int getQuestionIndex() 
    { 
    return questionIndex; 
    } 
    
    public void setQuestionIndex(int questionIndex) 
    { 
    // read only 
    } 
    
    public int getNumQuestions() 
    { 
    return questions.size(); 
    } 
    
    public void setNumQuestions(int size) 
    { 
    // read only 
    } 
    
    public String answerQuestion() 
    { 
    if(numTries == MAX_TRIES) 
    { 
    canTry = false; 
    return "continue"; 
    } 
    
    if(currentQuestion.getAnswer().equalsIgnor 
    eCase(answer)) 
    { 
    if(questionIndex == (questions.size() - 1)) 
    { 
    response = "complete"; 
    return response; 
    } 
    
    currentQuestion = questions.get(++questionIndex); 
    
    response = "continue"; 
    return response; 
    } 
    else 
    { 
    numTries++; 
    response = "failure"; 
    return response; 
    } 
    } 
    }
    And here comes the navigation rules in faces-config. So xml ending up being handwritten.
    Code:
    <navigation-rule> 
    <from-view-id>quiz.jsf</from-view 
    -id> 
    <navigation-case> 
    <from-action>#{Quiz.answerQuestion} 
    </from-action> 
    <from-outcome>failure</from-outc 
    ome> 
    <to-view-id>quiz.jsp</to-view-id 
    > 
    <redirect /> 
    </navigation-case> 
    <navigation-case> 
    <from-action>#{Quiz.answerQuestion} 
    </from-action> 
    <from-outcome>continue</from-out 
    come> 
    <to-view-id>quiz.jsp</to-view-id 
    > 
    <redirect /> 
    </navigation-case> 
    <navigation-case> 
    <from-action>#{Quiz.answerQuestion} 
    </from-action> 
    <from-outcome>complete</from-out 
    come> 
    <to-view-id>quiz.jsp</to-view-id 
    > 
    <redirect /> 
    </navigation-case> 
    </navigation-rule>
    If I go for example. Will update my JSF with a new kind of response. should I

    - Update my Backing Bean with getters and Setters for all the possible variables that are needed to determine what is displayed in the View.

    - Update my front end (JSP / JSF / HTML) with some not particularly flexible tags, which additionally requires that there are actually built into the logic of View (which is reasonable conflicting with MVC concept)

    - Update my faces-config.xml *sigh*

    And as I said, then made up much of the standing of Strings which tosses back and forth, so the possibility of strong types and refractoring are virtually non-existent.

    In PHP or ASP.NET would be created above with half as many lines of code, and that there would be no need to update an XML file folders POST requests back and forth, as this largely can be automated by a Front Controller, which Zend (PHP) and ASP.NET MVC (ASP.NET) is built.

    In addition, it is much simpler to write the rules, and that there is support for GET mapping on a much simpler way.

    To finish with, it can also be said that the server must be restarted for each small change, and such. Tomcat (which I use) does not have virtual directory options, so if I change a CSS value in Eclipse, I * still * residual server and recompile everything.

    Overall, it seems incredibly stupid, not very developer friendly, and has no features as PHP or ASP.NET does not have.

    We talked about Refractoring in another thread on the topic, but I can only see that there is LESS refractoring in this one in ASP.NET because everything is a string-based compared with Managed Beans, etc.

    It is virtually impossible to make anything that involved user input without having to change the faces-config. While I certainly do not think my little pills by Web.config in ASP.NET or zend_config in PHP.

    So if there is anyone who has some good knowledge for making it worthwhile even to learn the technology so that themselves.

    Being able to support it is not an argument I am much interested in. So I could just as well use my time to learn Cobol.

  2. #2
    Join Date
    Oct 2008
    Posts
    35

    Re: JSF / Java EE - Why

    But I would guess it is actually a niche technology, and probably do not, some Web developers working with it daily

    (Despite the many web developers who are here.)

  3. #3
    Join Date
    May 2008
    Posts
    2,297

    Re: JSF / Java EE - Why

    Niche? Hmm... Reason for you to find a few JSF developers here is enough because JSF developers do not hang out that in some places, partly because those who do not bother to talk labor. If you want to talk enterprise development go elsewhere.

  4. #4
    Join Date
    Oct 2008
    Posts
    35

    Re: JSF / Java EE - Why

    Now, I think so its good we can dispel the myth that Java is the only one who made Enterprise Development in. PHP is used for many super-size pages, and ASP.NET as well.

    I see virtually no sides in Java EE, taken when they go down and show a 500 lines useless stack trace.

  5. #5
    Join Date
    May 2008
    Posts
    2,297

    Re: JSF / Java EE - Why

    Quote Originally Posted by Gap meer View Post
    Now, I think so its good we can dispel the myth that Java is the only one who made Enterprise Development in.
    I do not say that enterprise only be made in JSF. I guess the JSF is primarily used for the enterprise.


    Quote Originally Posted by Gap meer View Post
    I see virtually no sides in Java EE, taken when they go down and show a 500 lines useless stack trace.
    Perhaps because it is not something you advertise with? Our users know nothing about our products that have a Java front-end, unless they are curious.

Similar Threads

  1. Replies: 4
    Last Post: 04-09-2013, 11:04 PM
  2. Setting Of Java to The Point At Manual Java
    By winni in forum Software Development
    Replies: 4
    Last Post: 10-01-2011, 10:05 PM
  3. Java Programming using Adventnet SNMP Java API
    By ROCKING_Suhas in forum Software Development
    Replies: 5
    Last Post: 17-07-2010, 06:52 AM
  4. Link List Example in Java Sample program in Java
    By trickson in forum Software Development
    Replies: 2
    Last Post: 04-08-2009, 08:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,829,047.03506 seconds with 16 queries