0
Javafx Scene Builder 2.0を使用してフォームを作成しました。フォームが動作しており、フォーム要素値に変数が設定されています。私はポストデータを受け取り、そのデータをデータベースに挿入するPHPスクリプトを作成しました。データをJavafx製フォームからHTTP POST要求に送信
実際にjavafxフォームデータをHTTP POST経由でPHPスクリプトに送信するには、何か助けが必要です。
ここまでは私のJavaコードです。
Main.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception{
Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
primaryStage.setTitle("Orbis Cob Submit");
primaryStage.setScene(new Scene(root, 800, 600));
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Controller.java
package sample;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.control.*;
import javafx.scene.text.Text;
import java.io.IOException;
import java.io.IOException;
import java.util.Observable;
public class Controller {
//Send Vars
private String sendDataType;
private String sendCobTarget;
private String sendVendor;
private String sendCobName;
private String sendDealerID;
private String sendJobType;
private String sendStartDate;
private String sendEndDate;
private String sendAmount;
private String sendCost;
private String sendDataDescription;
private DataBase db = new DataBase();
//Data list for drop downs
ObservableList<String> dataTypeList = FXCollections.observableArrayList("BK", "BR", "DB", "DEQ", "FI", "MB", "OB", "SAT", "SURN");
ObservableList<String> cobTargetList = FXCollections.observableArrayList("Sales", "Services", "Both");
ObservableList<String> vendorList = FXCollections.observableArrayList("SJO", "OCZ","Inhouse");
ObservableList<String> jobTypeList = FXCollections.observableArrayList("Mail", "Digital");
//Form Elements
@FXML
public ChoiceBox dataType;
@FXML
public ChoiceBox cobTarget;
@FXML
public ChoiceBox vendor;
@FXML
public Button button;
@FXML
public Text message;
@FXML
public TextField cobName;
@FXML
public TextField dealerID;
@FXML
public ChoiceBox jobType;
@FXML
public DatePicker startDate;
@FXML
public DatePicker endDate;
@FXML
public TextField sentAmount;
@FXML
public TextField cost;
@FXML
public TextField dataDescription;
@FXML
private void initialize(){
dataType.setItems(dataTypeList);
cobTarget.setItems(cobTargetList);
vendor.setItems(vendorList);
jobType.setItems(jobTypeList);
button.setOnAction(e -> {
this.sendDataType = dataType.getValue().toString();
this.sendCobTarget = cobTarget.getValue().toString();
this.sendVendor = vendor.getValue().toString();
this.sendCobName = cobName.getText();
this.sendDealerID = dealerID.getText();
this.sendJobType = jobType.getValue().toString();
this.sendStartDate = startDate.getValue().toString();
this.sendEndDate = endDate.getValue().toString();
this.sendAmount = sentAmount.getText();
this.sendCost = cost.getText();
this.sendDataDescription = dataDescription.getText();
//Send Field Data to HTTP POST REQUEST
});
}
}
質問のすべてのフィールドを送信しないように短縮すること以外は、間違ったことはありますか? – jrtapsell
すべてのフィールドを含めるように展開しました。 – jrtapsell