0

I work with jsf and icefaces, I have a problem, the action on the button does not work. Here's the code: main.xhtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets">
<head>
    <title>MainPage</title>
    <link rel="stylesheet" href="css/graphic.css"/>
    <link rel="stylesheet" href="css/style.css"/>
</head>
<body>
<div class="graphic">
    <ui:include src="pages/graphic.xhtml" />
</div>
<div class="form">
    <ui:include src="pages/form.xhtml"/>
</div>

<h:link outcome="starter">Go to starter page</h:link>
</body>
</html>

form.xtml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
        PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ace="http://www.icefaces.org/icefaces/components" xml:lang="en"
      lang="en"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:a="http://xmlns.jcp.org/jsf/passthrough"
      xmlns:ui="http://java.sun.com/jsf/facelets"
>
<div class="x-value">
    <p>Выберите X:</p>
    <h:form id="x">
        <h:selectOneRadio value="#{data.x}" >
            <f:selectItem itemValue="-5" itemLabel="-5"/>
            <f:selectItem itemValue="-4" itemLabel="-4"/>
            <f:selectItem itemValue="-3" itemLabel="-3"/>
            <f:selectItem itemValue="-2" itemLabel="-2"/>
            <f:selectItem itemValue="-1" itemLabel="-1"/>
            <f:selectItem itemValue="0" itemLabel="0"/>
            <f:selectItem itemValue="1" itemLabel="1"/>
            <f:selectItem itemValue="2" itemLabel="2"/>
            <f:selectItem itemValue="3" itemLabel="3"/>
        </h:selectOneRadio>
    </h:form>
</div>
<div class="y-value">
    <p>Выберите Y:</p>
    <h:inputText id="y" name="y"  value="#{data.y}" a:placeholder="Value in [-3..5]"
                 converterMessage="Y must be number..."
                 validatorMessage="Y must be number between -3 and 5 inclusive"
                 required="true" requiredMessage="Y is required" maxlength="6">
        <f:validateDoubleRange minimum="-3" maximum="5"/>
    </h:inputText>
</div>

<!--TODO: fix slider [IT IS JUST NOT SHOWING ON THE PAGE]-->
<div class="r-value">
    <p>Выберите R:</p>
    <h:form>
        <ace:sliderEntry value="#{data.r}" />
    </h:form>

</div>

<div>
    <h:commandButton type="submit" value="Submit" action="#{data.submit}"/>
</div>
</html>

MainBean.java

import lombok.Getter;
import lombok.Setter;

import javax.faces.annotation.ManagedProperty;
import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;
import java.io.Serializable;
import java.util.ArrayList;

@ManagedBean(name = "data", eager = true)
@ApplicationScoped
@Getter
@Setter
public class MainBean implements Serializable {
    double x = 0;
    double y = 0;
    double r = 1;
    ArrayList<Double> List = new ArrayList();
    @ManagedProperty(value = "#{DbBean}")
    DB db;

    public void submit() {
        System.out.println("==============================");
        List.add(x);
        System.out.println(List);
        db.pushInDB(x, y, r, getResult());

    }

    public boolean getResult() {
        return сheckSquare(x, y, r) || сheckQuarterCircle(x, y, r) || сheckTriangle(x, y, r);
    }

    private boolean сheckSquare(double x, double y, double r) {
        return x >= -r && x <= 0 && y >= 0 && y <= r / 2;
    }

    private boolean сheckQuarterCircle(double x, double y, double r) {
        return (x <= 0) && (y <= 0) && ((x * x + y * y) <= r * r);
    }

    private boolean сheckTriangle(double x, double y, double r) {
        return x >= 0 && x <= r && y >= 0 && y <= r / 2 && (y <= -x / 2 + r / 2);
    }

    public double getX() {
        return x;
    }

    public double getY() {
        return y;
    }

    public double getR() {
        return r;
    }

    public void setX(int x) {
        this.x = x;
    }

    public void setY(int y) {
        this.y = y;
    }

    public void setR(int r) {
        this.r = r;
    }

}

This should output to the console:

<h:commandButton value="Submit" action="#{data.submit}"/>

I also tried to connect third-party pages in different ways, for example via <ui:define>, but this also failed. I will be grateful for any help.

BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452
Ckaf
  • 43
  • 5

0 Answers0