在初始化java.util.Date变量为空时,我需要你的帮助.当我正在运行页面时,如果我没有选择任何日期,它会显示nullpointerexception.
代码是:
private java.util.Date date2;
Run Code Online (Sandbox Code Playgroud)
我试图将该变量设为空,但它不起作用>
private java.util.Date date2;
if (date2==null || date2.equals(""))
date2="";
Run Code Online (Sandbox Code Playgroud)
但是,随着初始化:
private java.util.Date date2= new java.util.Date(0,0,0);
Run Code Online (Sandbox Code Playgroud)
上面的代码将给出一个我不想要它的默认值.
我需要你的帮助,在两个日期之间获取字符串中的月份和年份列表.用户将以String格式输入两个日期:
String date1 ="JAN-2015";
String date2 ="APR-2015";
Run Code Online (Sandbox Code Playgroud)
所以结果应该是:
我尝试使用以下代码,但它给了我错误的结果:
List<Date> dates = new ArrayList<Date>();
String str_date ="JAN-2015";
String end_date ="APR-2015";
DateFormat formatter ;
formatter = new SimpleDateFormat("MMM-yyyy");
Date startDate = formatter.parse(str_date);
Date endDate = formatter.parse(end_date);
long endTime =endDate.getTime() ;
long curTime = startDate.getTime();
while (curTime <= endTime) {
dates.add(new Date(curTime));
curTime ++;
}
for(int i=0;i<dates.size();i++){
Date lDate =(Date)dates.get(i);
String ds = formatter.format(lDate);
System.out.println(ds);
}
Run Code Online (Sandbox Code Playgroud) 我在Web应用程序中有一个字体文件"arial.ttf",我只能获取其内容InputStream.
InputStream inputFont = getResourceAsStream("/resources/arial.ttf");
Run Code Online (Sandbox Code Playgroud)
如何基于?创建iTextBaseFontInputStream?该createFont方法不接受它.
BaseFont bf = BaseFont.createFont(inputFont, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
Run Code Online (Sandbox Code Playgroud)
createFont(InputStream,String,boolean)无法在BaseFont中调用createFont(java.lang.String,java.lang.String,boolean).
我需要你的帮助,在字符串之前添加空格,因为我需要将String值格式化为页面中的特定位置.例如:
System.out.println(" Hello Word!!");
Run Code Online (Sandbox Code Playgroud)
以上将在String之前给出10个空格,我手工编写它们,但是除了添加手动空格之外还有其他方法来指定String之前的空格吗?
我有以下对话框:
<h:form id="r1">
<p:commandButton value="Basic" type="button" onclick="PF('dlg1').show();" />
<p:dialog header="Basic Dialog" widgetVar="dlg1">
<h:outputText id="test" value="Welcome to PrimeFaces" />
</p:dialog>
</h:form>
Run Code Online (Sandbox Code Playgroud)
关闭对话框后如何刷新JSF页面?
我需要您的帮助来添加自定义字体“arial.ttf”,该字体存储FontFactory.register在 iText中的方法中我的项目的资源文件夹下。
Windows资源管理器项目中字体路径如下:
public_html\resources\fonts\arial.ttf
引用字体的代码是:
FontFactory.register("/resources/fonts/arial.ttf", "my_bold_font");
Font myBoldFont = FontFactory.getFont("my_bold_font");
Run Code Online (Sandbox Code Playgroud)
但是,当我运行 Java 方法时,它总是给我错误:
java.io.IOException: 找不到 /resources/fonts/arial.ttf 作为文件或资源。
我尝试了不同的路径,例如:
/public_html/resources/fonts/arial.ttf
../resources/fonts/arial.ttf
/fonts/arial.ttf
/arial.ttf
但结果是找不到文件。那么如何引用文件呢?
我需要你帮助设置单元格底部边框的长度.目前,它显示单元格的底部边界太长,我需要缩短它.我试图改变表的宽度,但它没有正确.
以下是代码:
Paragraph tableParagraph = new Paragraph();
tableParagraph.setAlignment(Element.ALIGN_LEFT);
PdfPTable table55 = new PdfPTable(2);
table55 = new PdfPTable(new float[] { 6, 6 });
table55.setWidthPercentage(90f);
table55.getDefaultCell().setBorder(PdfPCell.NO_BORDER);
PdfPCell cel2a = new PdfPCell(new Paragraph("Total of Net Profit ", font));
PdfPCell cel2b = new PdfPCell(new Paragraph("100.000" + " USD ", font));
cel2a.setBorder(Rectangle.NO_BORDER);
cel2b.setBorder(Rectangle.BOTTOM);
cel2a.setLeading(1f, 1.5f);
cel2b.setLeading(1f, 1.5f);
table55.addCell(cel2a);
table55.addCell(cel2b);
Run Code Online (Sandbox Code Playgroud) 我需要你的助手并帮助在Java中获取对象的值,然后将输出转换为String Array,以便将其传递给过程.这是我的Java类:
public class PendingRequests {
private String requestDate; //Getter & Setter
private String requestNo; //Getter & Setter
private String employeeName; //Getter & Setter
}
Run Code Online (Sandbox Code Playgroud)
在bean中我定义了一个名为"selectedRequests"的List:
private List<PendingRequests> selectedRequests;
Run Code Online (Sandbox Code Playgroud)
selectedRequests有值,我需要从中获取requestNo的值,然后将其转换为String Array.通过我的尝试,我只能使用以下代码在控制台中打印它们:
for(Object obj : selectedRequests){
System.out.println("Obj = "+((PendingRequests)obj).getRequestNo());
Run Code Online (Sandbox Code Playgroud)
但这是正确的方式,接下来我该怎么办?
我需要你的帮助,以便id="mytable"在从方法调用函数后刷新html中的div .目前,我使用以下行调用完整页面.
在我的java方法中,我使用下面的行来调用javascript方法:
RequestContext.getCurrentInstance().execute("autoRefresh()");
Run Code Online (Sandbox Code Playgroud)
HTML代码:
<script type="text/javascript">
function autoRefresh() {
window.location.reload();
}
</script>
<div id='mytable'>
<h1 id='My Table'>
<table></table>
</h1>
</div>
Run Code Online (Sandbox Code Playgroud) 在显示阿拉伯语内容以及在我尝试创建的PDF示例中从右到左开始书写时,我需要您的帮助。这是示例代码:
public static void main(String[] args) throws IOException {
try {
BaseFont ArialBase = BaseFont.createFont("C:\\Users\\dell\\Desktop\\arialbd.ttf", BaseFont.IDENTITY_H, true);
Font ArialFont = new Font(ArialBase, 20);
Document document = new Document(PageSize.LETTER);
PdfWriter.getInstance(document, new FileOutputStream("C:\\Users\\dell\\Desktop\\HelloWorld.pdf"));
document.setMargins(72f, 72f, 72f, 0f);
document.open();
document.add(new Paragraph("?????? ??????????,",ArialFont));
document.close();
System.out.println("PDF Completed");
} catch (DocumentException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
使用上面的代码,阿拉伯文本将显示如下:
الموقعالإ¥„كتروني,
身份不明,文字从左到右。那么我该如何解决呢?
java ×8
itext ×4
fonts ×2
ajax ×1
arabic ×1
arraylist ×1
arrays ×1
date ×1
dialog ×1
inputstream ×1
javascript ×1
jquery ×1
jsf ×1
page-refresh ×1
pdf ×1
pdfptable ×1
primefaces ×1
text-align ×1
xhtml ×1