我有一个简单的bean,它有一些相互关联的属性.例如,这个bean有一个叫做discountRate的属性,另一个叫做discountValue.discountRate是应用于销售的折扣百分比(%).discountValue是应用于销售的折扣价值($).由于用户可以通知百分比或值,并且我需要在数据库中存储这两个值,因此JavaFX双向绑定可以解决问题,但是,正如您可以想象的那样,这些值是相关的但不相同.我尝试解决这个问题,在双方创建绑定:
public class ExampleBean{
private ObjectProperty<BigDecimal> discountValue;
private ObjectProperty<BigDecimal> discountRate;
public BigDecimal getDiscountvalue() {
return discountValueProperty().getValue();
}
public void setDiscountValue(BigDecimal discountvalue) {
this.discountValueProperty().set(discountvalue);
}
public ObjectProperty<BigDecimal> discountValueProperty() {
if(discountValue==null){
discountValue=new SimpleObjectProperty<BigDecimal>(new BigDecimal("0.00"));
discountRate=new SimpleObjectProperty<BigDecimal>(new BigDecimal("0.00"));
configureDiscountBinding();
}
return discountValue;
}
private void configureDiscountBinding(){
discountValue.bind(Bindings.createObjectBinding(new Callable<BigDecimal>() {
@Override
public BigDecimal call() throws Exception {
return getDiscountRate().multiply(getTotalValue()).divide(new BigDecimal("100"));
}
}, discountRateProperty()));
discountRate.bind(Bindings.createObjectBinding(new Callable<BigDecimal>() {
@Override
public BigDecimal call() throws Exception {
return getDiscountValue().multiply(new BigDecimal("100")).divide(getTotalValue());
}
}, discountValueProperty()));
} …
Run Code Online (Sandbox Code Playgroud) 我创建了一个报告并将其导出为文本文件,以便在矩阵打印机中打印,但是,作业的结果是一个空白页面.我在ubuntu中做了同样的事情并且打印正确.这是一个Java bug吗?
这是我向您展示问题的示例代码:
public class PrintError extends Application {
public static void main(String args[]) {
launch(args);
}
public void start(Stage stage) throws PrintException {
PrinterJob printerJob = PrinterJob.createPrinterJob();
printerJob.showPrintDialog(stage);
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(new Copies(printerJob.getJobSettings().getCopies()));
printRequestAttributeSet.add(new JobName("test", Locale.getDefault()));
DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
Doc mydoc = new SimpleDoc(ClassLoader.class.getResourceAsStream("/should-be-printed.txt"), flavor, null);
DocPrintJob job = getPrintService(printerJob.getPrinter().getName()).createPrintJob();
job.print(mydoc, printRequestAttributeSet);
}
private PrintService getPrintService(String name) {
for (PrintService printService : java.awt.print.PrinterJob.lookupPrintServices()) {
if (name.equalsIgnoreCase(printService.getName())) {
return printService;
}
}
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
此示例在JavaFx …
我有一些困难要改变一些TableView行的外观.该行应显示带有笔划和红色的文本.实际上,我可以用红色显示它,但仍然不能做中风.这是我用来改变行外观的css类:
.itemCancelado {
-fx-strikethrough: true;
-fx-text-fill: red;
}
Run Code Online (Sandbox Code Playgroud)
当用户将项目标记为已取消时,将添加此样式类:
public class ItemCanceladoCellFactory implements Callback<TableColumn, TableCell> {
@Override
public TableCell call(TableColumn tableColumn) {
return new TableCell<ItemBean, Object>() {
@Override
public void updateItem(Object item, boolean empty) {
super.updateItem(item, empty);
setText(empty ? "" : getItem().toString());
setGraphic(null);
int indice=getIndex();
ItemBean bean=null;
if(indice<getTableView().getItems().size())
bean = getTableView().getItems().get(indice);
if (bean != null && bean.isCancelado())
getStyleClass().add("itemCancelado");
}
};
}
}
Run Code Online (Sandbox Code Playgroud)
此处还有另一个问题,标记为已取消的行仅在用户从可观察列表中添加或删除元素时更改颜色.有没有办法可以强制更新TableView?
我将ItemBean类更改为使用BooleanProperty并且它部分解决了:
public class ItemBean {
...
private BooleanProperty cancelado = new SimpleBooleanProperty(false);
...
public Boolean getCancelado() …
Run Code Online (Sandbox Code Playgroud) 我正在使用基于我使用Jhipster开发的AngularJS网站的Ionic Framework开发一个Android应用程序.由于我已经在我的Web应用程序中运行了服务器代码,因此我选择Ionic作为UI工作并在需要时调用服务器,但我在开发环境中遇到了一些问题.
我正在使用以这种方式配置的Apache CORS过滤器:
private void initCORSFilter(ServletContext servletContext, EnumSet<DispatcherType> disps) {
FilterRegistration.Dynamic corsFilter = servletContext.addFilter("cors", new CorsFilter());
Map<String, String> parameters = new HashMap<>();
parameters.put("cors.allowed.origins", "http://localhost:3000");
parameters.put("cors.allowed.headers", "x-auth-token, x-requested-with, Content-Type, Accept, cache-control, x-csrf-token, Origin, Access-Control-Request-Method, Access-Control-Request-Headers");
parameters.put("cors.allowed.methods", "POST, PUT, GET, DELETE");
parameters.put("cors.exposed.headers", "Access-Control-Allow-Origin, Access-Control-Allow-Credentials");
parameters.put("cors.support.credentials", "true");
corsFilter.setInitParameters(parameters);
corsFilter.addMappingForUrlPatterns(disps, true, "/*");
}
Run Code Online (Sandbox Code Playgroud)
然后我使用angular-csrf-cross-domain插件来帮助跨域csrf请求:
.config(function ($urlRouterProvider,csrfCDProvider) {
$urlRouterProvider.otherwise('/');
//enable CSRF
csrfCDProvider.setHeaderName('X-CSRF-TOKEN');
csrfCDProvider.setCookieName('CSRF-TOKEN');
});
Run Code Online (Sandbox Code Playgroud)
然后我尝试向我的本地服务器发送一个帖子请求:
angular.module('consamiApp')
.factory('Register', function ($resource) { …
Run Code Online (Sandbox Code Playgroud) 我需要在屏幕上显示需要5秒的信息消息,在此期间,用户无法关闭对话框.规范明确指出对话框不应该有任何按钮.有没有办法我可以用对话框没有按钮的方式使用JoptionPane.showMessageDialog?
我正在开发一个Ionic应用程序,我面临以下问题:
Unexpected token ILLEGAL
Run Code Online (Sandbox Code Playgroud)
奇怪的是,它只发生在我用Genymotion模拟器运行Android 5和bellow时,使用离子cordova运行android.如果我在Android 6及更高版本中运行相同的代码,则应用程序可以正常运行.
控制台说问题接近'{'字符:
我尝试重写这段代码,但它只是将错误更改为另一行,如果我删除所有空格.
这里奇怪的是它只发生在模拟器中运行时,所以我怀疑项目配置中的某些东西,比如webpack.
离子版:3.19.0 cordova-android:^ 6.2.3
这是我的package.json
{
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/common": "5.0.1",
"@angular/compiler": "5.0.1",
"@angular/compiler-cli": "5.0.1",
"@angular/core": "5.0.1",
"@angular/forms": "5.0.1",
"@angular/http": "5.0.1",
"@angular/platform-browser": "5.0.1",
"@angular/platform-browser-dynamic": "5.0.1",
"@ionic-native/camera": "^4.4.2",
"@ionic-native/core": "4.3.2",
"@ionic-native/date-picker": "^4.4.2",
"@ionic-native/facebook": "^4.4.2",
"@ionic-native/globalization": "^4.4.2",
"@ionic-native/google-plus": "^4.4.2",
"@ionic-native/onesignal": "^4.4.2",
"@ionic-native/splash-screen": "4.3.2",
"@ionic-native/status-bar": "4.3.2",
"@ionic/storage": "^2.1.3",
"@ngx-translate/core": "^9.0.1",
"@ngx-translate/http-loader": "^2.0.0",
"cordova-android": "^6.2.3",
"cordova-plugin-camera": …
Run Code Online (Sandbox Code Playgroud) 我正在创建一个充满输入字段的动态数据表.有时,当用户在某些输入中插入值时,应更新特定单元格,并且仅更新此单元格.我认为这可能很简单,但却没有成功.我要更新的单元格是"valor total",当其他两个单元格的值发生变化时,应更新此单元格:
EDITED
我试过f:带有完整id的ajax并得到"具有id的组件:lancamentoNF:popupLancamentoNF:tabelaItensNF:0:找不到valorTotalItem".更改为p:ajax并且没有错误发生但它没有更新!!
<h:panelGroup id="painelItensNF" layout="block" styleClass="hrgi-div-form aba-lancamento-nf clearfix" style="overflow:auto;">
<h:panelGroup layout="block" style="width: 1700px;">
<p:dataTable id="tabelaItensNF" value="#{modeloTabelaDinamicaItemNF.itens}" var="itemEmbrulhado" styleClass="tabelaDinamica" height="174" style="width: 100%;" rowIndexVar="indice">
... (some columns)
<p:column style="width: 5%"
headerText="quantidade">
<hrgi:spinner id="quantidadeItem"
value="#{itemEmbrulhado.item.produto.detalheTributavel.quantidade}"
dinheiro="false"
fator="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?0.01:1}"
local="pt-BR" min="0.00" width="70">
<p:ajax event="change"
update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem"
listener="#{controladorPopupLancamentoNF.calcularValorTotalItem(itemEmbrulhado)}" global="false" />
<f:convertNumber
maxFractionDigits="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?2:0}"
minFractionDigits="#{itemEmbrulhado.item.produto.detalheTributavel.unidadeFracionada?2:0}"
locale="pt-BR"
for="quantidadeItem"/>
</hrgi:spinner>
</p:column>
<p:column style="width: 5%"
headerText="valor unitario">
<hrgi:spinner id="valorUnitarioItem"
value="#{itemEmbrulhado.item.produto.detalheTributavel.valorUnitario}"
dinheiro="true" fator="0.01" local="pt-BR" min="0.00" width="70">
<p:ajax event="change"
update="lancamentoNF:popupLancamentoNF:tabelaItensNF:#{indice}:valorTotalItem"
listener="#{controladorPopupLancamentoNF.calcularValorTotalItem(itemEmbrulhado)}" global="false"/>
<f:convertNumber type="currency" currencyCode="BRL" currencySymbol="R$ "
maxFractionDigits="10" minFractionDigits="2" locale="#{cc.attrs.local}"
for="valorUnitarioItem"/>
</hrgi:spinner> …
Run Code Online (Sandbox Code Playgroud) 我在主持一个我在Heroku中创建的简单网站时遇到了一些问题.该网站使用Mezzanine创建并使用whitenoise和gunicorn.问题是:我在一些静态资源中遇到404错误,比如css和js.您可以在http://blrg-advogados.herokuapp.com上查看问题.
这是Procfile内容:
web: python manage.py collectstatic --noinput; gunicorn --workers=4 site_advogados.wsgi 0.0.0.0:$PORT
Run Code Online (Sandbox Code Playgroud)
wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "site_advogados.settings")
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
Run Code Online (Sandbox Code Playgroud)
这是settings.py的一部分:
ALLOWED_HOSTS = ['*']
DEBUG = False
PROJECT_APP_PATH = os.path.dirname(os.path.abspath(__file__))
PROJECT_APP = os.path.basename(PROJECT_APP_PATH)
PROJECT_ROOT = BASE_DIR = os.path.dirname(PROJECT_APP_PATH)
CACHE_MIDDLEWARE_KEY_PREFIX = PROJECT_APP
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
MEDIA_URL = STATIC_URL + "media/"
MEDIA_ROOT = os.path.join(PROJECT_ROOT, *MEDIA_URL.strip("/").split("/"))
ROOT_URLCONF …
Run Code Online (Sandbox Code Playgroud) 我用公共和私有RSA密钥创建了一个JKS文件.当我使用外部路径(如c:/file.jks)加载此文件时,程序就像魅力一样执行.但是,如果我尝试从类路径加载此相同的文件,我得到此异常:
java.io.IOException: Invalid keystore format
Run Code Online (Sandbox Code Playgroud)
这是用于加载jks的代码:
KeyStore keyStore = KeyStore.getInstance("JKS");
InputStream stream=this.getClass().getResourceAsStream("/lutum.jks") ;
keyStore.load(stream,passe);
Run Code Online (Sandbox Code Playgroud)
唯一的区别是我在外部加载时使用FileInputStream和完整路径.我做错了什么?
我正在从IceFaces变为PrimeFaces(我真的想改为RichFaces,但导致新版本中出现错误,我不会)并且我正在努力实现正确的primefaces autoComplete.根据他的手册,我只需要实现一个返回对象列表的方法,在这种情况下需要一个转换器.
我正在返回的列表是javax.faces.model.SelectItem的列表,我真的不明白为什么我需要为此创建一个转换器,但让我们继续.我创建了一个简单的转换器来测试,但是primefaces无法识别我的转换器并在浏览器中返回此错误:
/resources/components/popups/popupBuscaPessoa.xhtml @ 35,41 itemLabel ="#{pessoa.label}":类'java.lang.String'没有属性'label'.
这是我的转换课程(只是为了测试):
public class ConversorSelectItem implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (value!=null && value.isEmpty())
return null;
SelectItem selectItem=new SelectItem();
selectItem.setLabel(value);
return selectItem;
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object object) {
return ((SelectItem)object).getLabel();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我尝试使用p:autocomplete的地方:
<p:autoComplete value="#{modeloPopupBuscaPessoa.itemSelecionado}"
completeMethod="#{controladorSugestaoPessoa.atualizarSugestoes}"
var="pessoa" itemLabel="#{pessoa.label}" itemValue="#{pessoa.value}"
converter="#{conversorSelectItem}"/>
Run Code Online (Sandbox Code Playgroud)
我做错什么了吗?是否有SelectItem的默认转换器?有没有更简单的方法来实现这个转换器?
java ×5
javafx ×3
java-8 ×2
javafx-2 ×2
jsf-2 ×2
primefaces ×2
android ×1
angularjs ×1
classpath ×1
converters ×1
cordova ×1
cors ×1
csrf ×1
data-binding ×1
django ×1
encryption ×1
gunicorn ×1
heroku ×1
ionic3 ×1
jks ×1
joptionpane ×1
jsf ×1
label ×1
mezzanine ×1
printing ×1
python ×1
swing ×1
tableview ×1
typescript ×1