5 Replies - 1080 Views - Last Post: 12 October 2012 - 10:16 AM

#1 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

RIA Client

Posted 12 October 2012 - 05:40 AM

Hello there! Can somebody please show me, how to convert JSP to something more "sexy" (I.E. flex, javaFX ...)
For example in this sample project, I've got xhtml files:
addFilm.xhtml:
<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./WEB-INF/template1.xhtml"
                xmlns:h="http://java.sun.com/jsf/html">

    <ui:define name="content">
        <h:form>
            <h:panelGrid columns="3">
                Title: <h:inputText id="title" value="#{addFilm.title}"/>
                <h:message for="title"/>
                Year: <h:inputText id="year" value="#{addFilm.year}"/>
                <h:message for="year"/>
                <h:commandButton value="add" action="#{addFilm.perform}"/>
            </h:panelGrid>
        </h:form>
    </ui:define>

</ui:composition>



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

    <ui:define name="content">
        <h:dataTable value="#{filmManager.films}" var="film">
            <h:column>
                <f:facet name="header">Title</f:facet>
                #{film.title}
            </h:column>
            <h:column>
                <f:facet name="header">Year</f:facet>
                #{film.year}
            </h:column>
        </h:dataTable>
    </ui:define>

</ui:composition>



and then java classes:

AddFilmManager.java:
package films;

import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;

@Named("addFilm")
@RequestScoped
public class AddFilmManagedBean {

    @NotNull
    private String title;
    @Pattern(regexp = "\\d\\d\\d\\d")
    private String year;
    @EJB
    private FilmManagerSessionBean filmManager;

    public AddFilmManagedBean() {
    }

    public String perform() {
        Film f = new Film(title, year);
        filmManager.addFilm(f);
        return "showFilms";
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }
}



Film.java:
package films;

import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQuery;

@Entity
@NamedQuery(name = "Film.findAll", query = "SELECT f FROM Film f")
public class Film implements Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String title;
    @Column(name = "year2")
    private String year;

    public Film() {
    }

    public Film(String title, String year) {
        this.title = title;
        this.year = year;
    }

    public Long getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getYear() {
        return year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    @Override
    public int hashCode() {
        return id != null ? id.hashCode() : 0;
    }

    @Override
    public boolean equals(Object object) {
        if (!(object instanceof Film)) {
            return false;
        }
        Film other = (Film) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "films.Film[ id=" + id + " ]";
    }
}



FilmManagerSessionBean.java:
package films;

import java.util.List;
import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.inject.Named;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

@Stateless
@Named("filmManager")
public class FilmManagerSessionBean {

    @PersistenceContext
    private EntityManager em;
    @Inject
    private RecommendationService recommendation;

    public void addFilm(Film film) {
        em.persist(film);
    }

    public List<Film> getFilms() {
        TypedQuery<Film> q = em.createNamedQuery("Film.findAll", Film.class);
        List<Film> films = q.getResultList();
        recommendation.recommend(films);
        return films;
    }
}



RecommendationService.java:
package films;

import java.util.Collections;
import java.util.List;

public class RecommendationService {

    public void recommend(List<Film> films) {
        Collections.shuffle(films);
    }
}



I just want to know, how should I.E. flex page that should do the same as addFilm.xhtml look like...both will be run at the same local machine btw. If anybody would be so kind and could post any advice, I'd be glad :)

Is This A Good Question/Topic? 0
  • +

Replies To: RIA Client

#2 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: RIA Client

Posted 12 October 2012 - 09:06 AM

You can't just convert JSF to JavaFX (or Flex). It will require a complete re-write for the front-end (and probably middle tier). I suggest looking through the documentation or finding some tutorials to ease the transition.
Was This Post Helpful? 0
  • +
  • -

#3 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: RIA Client

Posted 12 October 2012 - 09:41 AM

@blackcompe: I know that :) I just wanted somebody to show me, how that frontend should look like (especially that part that communicates with backend)...I've expected, that those classes are not so difficult and large, so it should be easy to rewrite it for someone who has some experiences with that...
Was This Post Helpful? 0
  • +
  • -

#4 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: RIA Client

Posted 12 October 2012 - 09:57 AM

Well, sorry I can't help you more, but you're not likely to find that kind of expertise in this forum. In fact, I highly doubt anyone is willing to to take the time to show you how to port the code, especially when there are plenty of good tutorials out of there. Firstly, no one writes complex code for free (that doesn't solve a common problem). Secondly, from what I've heard, JavaFX code isn't intuitive, so those classes probably are difficult for someone with no experience to digest, which is why you're better off starting from scratch. I'm just being realistic. You can try your luck at StackOverflow's JavaFX forum. Plenty of experts there.

This post has been edited by blackcompe: 12 October 2012 - 09:59 AM

Was This Post Helpful? 1
  • +
  • -

#5 Dworza  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 6
  • View blog
  • Posts: 172
  • Joined: 13-February 11

Re: RIA Client

Posted 12 October 2012 - 10:14 AM

Ok sorry, I've thought that this shouldn't be so hard to help me :)
To react to that your assertion "no one writes complex code for free" - as you can see - this code I've posted is for study purposes only and so should be the code I've requested :)

I was looking for FLEX tutorials only, but I didn't get it, so I've thought that maybe if I'd see the transformation of code for JSP to FLEX, I'd get it...nevermind... :)

Nevertheless thank you for link to JavaFX forum..I didn't get any idea that forum like this even exists at DIC :)
Was This Post Helpful? 0
  • +
  • -

#6 blackcompe  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1155
  • View blog
  • Posts: 2,535
  • Joined: 05-May 05

Re: RIA Client

Posted 12 October 2012 - 10:16 AM

Yup. Good luck with everything.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1