NetBeans utilita – Tvorba formulářů z DB
- Foowie
- Člen | 269
Plugin do Netbeans(6.9.x) pro snadnou tvorbu formulářových prvků z dat z databáze.
Howto:
- Stáhněte a nainstalujte plugin
- Přidejte do Services(Okno pod menu) – Databases potřebné připojení k databázi
- V místě kde chcete vytvořit „továrničku“ na Form přemístěte
kurzor,
Alt+Insert
(Ctrl-I
on Mac),AppForm from DB ...
- Vyberte databázové spojení a tabulku
- …
Funguje na MySQL a PG .) Na ostatních to možná taky bude fungovat, ale těžko říct jak :)
Ukázka:
`CREATE TABLE IF NOT EXISTS `zakazky` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`zakaznik` varchar(1000) DEFAULT NULL,
`fasada_id` int(11) NOT NULL,
`baze_id` int(11) DEFAULT NULL,
`slozeni_id` int(11) DEFAULT NULL,
`struktura_id` int(11) DEFAULT NULL,
`odstin` varchar(400) DEFAULT NULL,
`datum` datetime NOT NULL,
`vytvoril` int(11) DEFAULT NULL,
`stav` int(11) NOT NULL,
`v_k2` int(1) NOT NULL DEFAULT '0',
`baleni5` int(11) NOT NULL DEFAULT '0',
`baleni25` int(11) NOT NULL DEFAULT '0',
`baleni30` int(11) NOT NULL DEFAULT '0',
`zrnitost` varchar(10) DEFAULT NULL,
`registroval_id` int(11) DEFAULT NULL,
`datum_registrace` datetime DEFAULT NULL,
`datum_vyrobeni` datetime DEFAULT NULL,
`datum_fakturace` datetime DEFAULT NULL,
`vyfakturoval_id` int(11) DEFAULT NULL,
`datum_zruseni` datetime DEFAULT NULL,
`datum_navedeni_k2` datetime DEFAULT NULL,
`navedl_k2` int(11) DEFAULT NULL,
`zrusil` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fasada_id` (`fasada_id`),
KEY `baze_id` (`baze_id`),
KEY `slozeni_id` (`slozeni_id`),
KEY `struktura_id` (`struktura_id`),
KEY `stav` (`stav`),
KEY `registroval_id` (`registroval_id`),
KEY `vyfakturoval_id` (`vyfakturoval_id`),
KEY `vytvoril` (`vytvoril`),
KEY `navedl_k2` (`navedl_k2`),
KEY `zrusil` (`zrusil`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
ALTER TABLE `zakazky`
ADD CONSTRAINT `zakazky_ibfk_1` FOREIGN KEY (`fasada_id`) REFERENCES `fasada` (`id`),
ADD CONSTRAINT `zakazky_ibfk_10` FOREIGN KEY (`vyfakturoval_id`) REFERENCES `users` (`id`),
ADD CONSTRAINT `zakazky_ibfk_11` FOREIGN KEY (`vytvoril`) REFERENCES `users` (`id`),
ADD CONSTRAINT `zakazky_ibfk_12` FOREIGN KEY (`navedl_k2`) REFERENCES `users` (`id`),
ADD CONSTRAINT `zakazky_ibfk_13` FOREIGN KEY (`zrusil`) REFERENCES `users` (`id`),
ADD CONSTRAINT `zakazky_ibfk_5` FOREIGN KEY (`stav`) REFERENCES `zakazky_stav` (`id`),
ADD CONSTRAINT `zakazky_ibfk_6` FOREIGN KEY (`baze_id`) REFERENCES `fasada_baze` (`id`),
ADD CONSTRAINT `zakazky_ibfk_7` FOREIGN KEY (`slozeni_id`) REFERENCES `fasada_slozeni` (`id`),
ADD CONSTRAINT `zakazky_ibfk_8` FOREIGN KEY (`struktura_id`) REFERENCES `fasada_struktura` (`id`),
ADD CONSTRAINT `zakazky_ibfk_9` FOREIGN KEY (`registroval_id`) REFERENCES `users` (`id`);
A výsledek:
protected function createComponent($name) {
$form = new AppForm($this, $name);
$form->addHidden('id');
$form->addText('zakaznik', 'Zakaznik')
->addRule(Form::MAX_LENGTH, null, 1000);
$form->addSelect('fasada_id', 'Fasada id', array() /* TODO: Pairs from [fasada.id] */)
->addRule(Form::FILLED);
$form->addSelect('baze_id', 'Baze id', array() /* TODO: Pairs from [fasada_baze.id] */)->setPrompt("");
$form->addSelect('slozeni_id', 'Slozeni id', array() /* TODO: Pairs from [fasada_slozeni.id] */)->setPrompt("");
$form->addSelect('struktura_id', 'Struktura id', array() /* TODO: Pairs from [fasada_struktura.id] */)->setPrompt("");
$form->addText('odstin', 'Odstin')
->addRule(Form::MAX_LENGTH, null, 400);
$form->addDateTimePicker('datum', 'Datum')
->addRule(Form::FILLED)
->addRule(Form::MAX_LENGTH, null, 19);
$form->addSelect('vytvoril', 'Vytvoril', array() /* TODO: Pairs from [users.id] */)->setPrompt("");
$form->addSelect('stav', 'Stav', array() /* TODO: Pairs from [zakazky_stav.id] */)
->addRule(Form::FILLED);
$form->addCheckbox('v_k2', 'V k2');
$form->addText('baleni5', 'Baleni5')
->addRule(Form::FILLED)
->addRule(Form::INTEGER)
->addRule(Form::MAX_LENGTH, null, 11);
$form->addText('baleni25', 'Baleni25')
->addRule(Form::FILLED)
->addRule(Form::INTEGER)
->addRule(Form::MAX_LENGTH, null, 11);
$form->addText('baleni30', 'Baleni30')
->addRule(Form::FILLED)
->addRule(Form::INTEGER)
->addRule(Form::MAX_LENGTH, null, 11);
$form->addText('zrnitost', 'Zrnitost')
->addRule(Form::MAX_LENGTH, null, 10);
$form->addSelect('registroval_id', 'Registroval id', array() /* TODO: Pairs from [users.id] */)->setPrompt("");
$form->addDateTimePicker('datum_registrace', 'Datum registrace')
->addRule(Form::MAX_LENGTH, null, 19);
$form->addDateTimePicker('datum_vyrobeni', 'Datum vyrobeni')
->addRule(Form::MAX_LENGTH, null, 19);
$form->addDateTimePicker('datum_fakturace', 'Datum fakturace')
->addRule(Form::MAX_LENGTH, null, 19);
$form->addSelect('vyfakturoval_id', 'Vyfakturoval id', array() /* TODO: Pairs from [users.id] */)->setPrompt("");
$form->addDateTimePicker('datum_zruseni', 'Datum zruseni')
->addRule(Form::MAX_LENGTH, null, 19);
$form->addDateTimePicker('datum_navedeni_k2', 'Datum navedeni k2')
->addRule(Form::MAX_LENGTH, null, 19);
$form->addSelect('navedl_k2', 'Navedl k2', array() /* TODO: Pairs from [users.id] */)->setPrompt("");
$form->addSelect('zrusil', 'Zrusil', array() /* TODO: Pairs from [users.id] */)->setPrompt("");
$form->addSubmit('submitButton', 'Odeslat')->onClick[] = callback($this, 'submit' . $name);
$form->addSubmit('cancelButton', 'Storno')->onClick[] = callback($this, 'cancel' . $name);
return $form;
}
Editoval Foowie (15. 12. 2011 10:52)
- Ondřej Brejla
- Člen | 746
Pokud by si s tím souhlasil, tak bychom to mohli časem zařadit do
NetBeans Nette Framework Pluginu jako další tab pro Alt+Insert
generátor Create component...
, protože to k tomu
docela pásne.
- Ondřej Brejla
- Člen | 746
To by chtělo dynamic scaffolding…nad ním jsem nedávno přemýšlel, ale pak jsem byl líný ;-) A tohle na škodu určitě nebude, občas, někdy se to třeba hodí.
- mlady
- Člen | 24
redhead napsal(a):
To ano, ale podle mě je lepší si to dělat dynamicky v php, pak něco změníš v db a budeš muset znova generovat ten formulář (nebo ho upravovat). A myslet furt na nějaký změny…
Tento plugin by podľa mňa mal slúžiť na prvotné vytvorenie formulára. Keď budeš robiť zmeny v databáze tak už si ten formulár updatneš ručne.
- crempa
- Člen | 198
Dynamic scaffolding muze byt prima vec, problem vsak prijde hned jak
potrebujes zacit definovat podrobnejsi validacni pravidla, nejlepe ruzne
provazana s vlastnimy callbacky apod.
Na ukazkovem blogiskovem systemu to pak vypada uzasne, ale v nejake robustnejsi
aplikaci to spise prekazi a snizuje citelnost kodu… takze tento plugin celkem
vitam, idealni by bylo zanest podporu nejake syntaxe pro validaci primo do
komentaru v databazi a pak z toho jen generovat formular a validaci na strane
modelu…
Kazdopadne to jest moje zkusenot, mozna to jde ale udelat chytre a stale
v duchu KISS :-)
- Honza Marek
- Člen | 1664
Bylo by super, kdyby se nějaký scaffolding objevil v nette netbeans pluginu. Jen prosím bez nějakých dibi::fetchPairs…
- Ondřej Brejla
- Člen | 746
Tak nějaký hezký scaffold napiš :-) A pokud možno bez závislostí na dibi, ormionu a všech možných externích knihovnách ;-)
- Vyki
- Člen | 388
Asi něco špatne, vůbec se nevygeneruje. Vyberu tabulku dám OK a pak vyskočí toto:
A java.lang.NumberFormatException exception has occurred.
Please report this at http://www.netbeans.org/community/issues.html,
including a copy of your messages.log file as an attachment.
The messages.log file is located in your C:\Users\Vyki\.netbeans\6.9\var\log folder.
Moje NB:
Product Version: NetBeans IDE 6.9.1 (Build 201007282301)
Java: 1.6.0_20; Java HotSpot(TM) Client VM 16.3-b01
System: Windows 7 version 6.1 running on x86; Cp1250; cs_CZ (nb)
Userdir: C:\Users\Vyki\.netbeans\6.9
A v LOGU je toto:
java.lang.NumberFormatException: For input string: "10) unsigne"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.netbeans.modules.php.nette.generators.form.MySQLColumnMetaDataDriver.getMetaData(MySQLColumnMetaDataDriver.java:32)
at org.netbeans.modules.php.nette.generators.form.ColumnFactory.createTable(ColumnFactory.java:43)
at org.netbeans.modules.php.nette.generators.form.FormGenerator.invoke(FormGenerator.java:62)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.invokeSelected(GenerateCodePanel.java:162)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.listMouseReleased(GenerateCodePanel.java:125)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.access$200(GenerateCodePanel.java:63)
at org.netbeans.modules.editor.codegen.GenerateCodePanel$3.mouseReleased(GenerateCodePanel.java:111)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:137)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
[catch] at java.awt.EventDispatchThread.run(Unknown Source)
Sorry za SPAM
Editoval Vyki (8. 9. 2010 21:04)
- Martin
- Člen | 171
Ahoj. Zkusil jsem použít na tabulku, kde mám enum. Nevím, zda plugin spadl proto (předpokládám), nebo proto, že mám nejnovější vývojový build NetBeans 201103260400.
-- Adminer 3.1.0 MySQL dump
SET NAMES utf8;
SET foreign_key_checks = 0;
SET time_zone = 'SYSTEM';
SET sql_mode = 'NO_AUTO_VALUE_ON_ZERO';
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`email` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`password` char(32) COLLATE utf8_czech_ci NOT NULL,
`name` varchar(100) COLLATE utf8_czech_ci NOT NULL,
`role` enum('admin','editor','predplatitel') COLLATE utf8_czech_ci NOT NULL DEFAULT 'predplatitel',
PRIMARY KEY (`id`),
UNIQUE KEY `email` (`email`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci;
java.lang.NumberFormatException: For input string: "'admin','editor','predplatitel'"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.netbeans.modules.php.nette.generators.form.MySQLColumnMetaDataDriver.getMetaData(MySQLColumnMetaDataDriver.java:31)
at org.netbeans.modules.php.nette.generators.form.TableMetaDataFactory.createTableMetaData(TableMetaDataFactory.java:35)
at org.netbeans.modules.php.nette.generators.form.FormGenerator.invoke(FormGenerator.java:63)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.invokeSelected(GenerateCodePanel.java:171)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.listKeyReleased(GenerateCodePanel.java:140)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.access$100(GenerateCodePanel.java:66)
at org.netbeans.modules.editor.codegen.GenerateCodePanel$3.keyReleased(GenerateCodePanel.java:115)
at java.awt.AWTEventMulticaster.keyReleased(Unknown Source)
at java.awt.Component.processKeyEvent(Unknown Source)
at javax.swing.JComponent.processKeyEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
[catch] at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:148)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Editoval Martin (1. 4. 2011 10:22)
- kralik
- Člen | 230
Ahoj,
skvělá komponenta.
bohužel pokud je použita na tabulku jenž obsahuje hodnoty „enum“ tak komponenta spadne a nepomůže tedy s vytvořením form.
autor to určitě updatí
dobrá práce
EDIT: problém nastává i v případě pokud je hodnota typu např. „Decimal (10,2)“
Editoval kralik (15. 4. 2011 14:03)
- kralik
- Člen | 230
Ahoj, tak jsem zkoušel vytvořit form z DB a píše to problém s ENUM
<script>
java.lang.NumberFormatException: For input string: "'yes','no'"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at org.netbeans.modules.php.nette.generators.form.MySQLColumnMetaDataDriver.getMetaData(MySQLColumnMetaDataDriver.java:31)
at org.netbeans.modules.php.nette.generators.form.TableMetaDataFactory.createTableMetaData(TableMetaDataFactory.java:35)
at org.netbeans.modules.php.nette.generators.form.FormGenerator.invoke(FormGenerator.java:63)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.invokeSelected(GenerateCodePanel.java:162)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.listMouseReleased(GenerateCodePanel.java:125)
at org.netbeans.modules.editor.codegen.GenerateCodePanel.access$200(GenerateCodePanel.java:63)
at org.netbeans.modules.editor.codegen.GenerateCodePanel$3.mouseReleased(GenerateCodePanel.java:111)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
[catch] at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:137)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
</script>