我希望在这篇文章中,我可以得到人们对JSF页面和支持bean之间接口的最佳实践的看法.
我永远无法解决的一件事是我的支持豆的结构.此外,我从未找到关于这个主题的好文章.
什么属性属于哪个支持bean?何时适合向给定bean添加更多属性,而不是创建新bean并将属性添加到其中?对于简单的应用程序,考虑到将一个bean注入另一个bean所涉及的复杂性,为整个页面只有一个支持bean是否有意义?支持bean是否应该包含任何实际的业务逻辑,还是应该严格包含数据?
随意回答这些问题以及可能出现的任何其他问题.
至于减少JSF页面和支持bean之间的耦合,我从不允许JSF页面访问任何支持bean属性的属性.例如,我从不允许以下内容:
<h:outputText value="#{myBean.anObject.anObjectProperty}" />
Run Code Online (Sandbox Code Playgroud)
我总是需要这样的东西:
<h:outputText value="#{myBean.theObjectProperty}" />
Run Code Online (Sandbox Code Playgroud)
支持bean值为:
public String getTheObjectProperty()
{
return anObject.getAnObjectProperty();
}
Run Code Online (Sandbox Code Playgroud)
当我循环遍历集合时,我使用包装类来避免向下钻取到数据表中的对象.
一般来说,这种方法对我来说是"正确的".它避免了视图和数据之间的任何耦合.如果我错了,请纠正我.
我想onclick在锚点上更改属性的值.我想将其设置为包含JavaScript的新字符串.(该字符串由服务器提供给客户端JavaScript代码,它可以包含您可以onclick在HTML 中的属性中放置的任何内容.)以下是我尝试过的一些内容:
attr("onclick", js)不适用于Firefox和IE6/7.setAttribute("onclick", js)Firefox和IE8,但不是IE6/7.onclick = function() { return eval(js); }不起作用因为您不允许使用return传递给的代码eval().任何人都有建议将onclick属性设置为使其适用于Firefox和IE 6/7/8?另请参阅下面我用来测试它的代码.
<html>
<head>
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var js = "alert('B'); return false;";
// Set with JQuery: doesn't work
$("a").attr("onclick", js);
// Set with setAttribute(): at least works with Firefox
//document.getElementById("anchor").setAttribute("onclick", js);
});
</script>
</head>
<body>
<a href="http://www.google.com/" id="anchor" onclick="alert('A'); return false;">Click</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 我试着到处寻找使用Flex vs. Flash的优缺点的简明列表.
来自编程背景,我非常喜欢Flex.它很容易上手,因为它可以使用flash类,为什么我要使用Flash而不使用flex?
柔性:
优点:
缺点:
闪
优点:
缺点:
如果我错过了迄今所说的任何内容,请纠正我.
我刚开始在空闲时间探索Scala.
我不得不说到目前为止我印象非常深刻.Scala位于JVM之上,与现有Java代码无缝集成,并具有Java不具备的许多功能.
除了学习新语言之外,切换到Scala有什么缺点?
我已经在Android开发人员上阅读了Android UI技巧2,它告诉人们如何多次在另一个布局文件中包含布局,并为这些布局提供不同的ID.但是,此处的示例是覆盖布局ID,而不是此布局中视图的ID.例如,如果workspace_screen.xml如下所示:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView android:id="@+id/firstText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="first"/>
<TextView android:id="@+id/secondText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="second"/>
Run Code Online (Sandbox Code Playgroud)
我在另一个布局文件中包含了三次.我最终得到三个带有id firstText的TextView,还有另外三个带有secondText的TextView?是不是有碰撞?如何在findViewById的第三个包含布局中找到secondText TextView?我应该在findViewById方法中输入什么?
我正在尝试为JSF找到一个实用的单元测试框架.
我知道JSFUnit,但这对我来说非常不切实际.我需要在我的项目中包含大约10个JAR,并跳过许多其他的箍以使其运行.
我意识到 - 由于需要模拟平台和客户端 - 单元测试Web应用程序很困难.但有更好的方法吗?
这是我的问题.我正在尝试调用页面:foo.php?docID = bar并将PDF返回到屏幕,该屏幕在数据库中存储为BLOB.
以下是我的代码中实际返回PDF的部分:
$docID = isset($_REQUEST['docID']) ? $_REQUEST['docID'] : null;
if ($docID == null){
die("Document ID was not given.");
}
$results = getDocumentResults($docID);
if (verifyUser($user, $results['ProductId'])){
header('Content-type: application/pdf');
// this is the BLOB data from the results.
print $results[1];
}
else{
die('You are not allowed to view this document.');
}
Run Code Online (Sandbox Code Playgroud)
这在Firefox中运行得非常好.
但是,在IE中,它根本没有显示任何内容.如果我在另一个页面(即google.com),并输入网址转到此页面,它会说已经完成,但我仍然会在屏幕上显示google.com.
我检查了来自firefox和IE的响应的标题.它们完全相同.
有没有人有什么建议?需要更多信息?
编辑:如果它有帮助,这里是响应标题和内容的第一行:
HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 349930
Content-Type: application/pdf
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Server: …Run Code Online (Sandbox Code Playgroud) 当我遇到一段对我来说没有意义的代码时,我正在阅读精彩的" Scala编程"一书:
def above(that: Element): Element = {
val this1 = this widen that.width
val that1 = that widen this.width
elem(this1.contents ++ that1.contents)
}
Run Code Online (Sandbox Code Playgroud)
注意第2和第3行:
val this1 = this widen that.width
Run Code Online (Sandbox Code Playgroud)
似乎我应该能够用以下内容替换它:
val this1 = this.widen that.width
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试编译此更改时,它会给出以下错误:
错误:';' 预期,但'.' 找到.
val this1 = this.widen that.width ^
为什么这种语法不可接受?
Hibernate和EJB3相对于彼此有什么优缺点?
我找到了这篇文章,但它没有真正解决我的问题.如果我对这两种技术没有任何特殊的联系,那会导致我选择一种技术吗?或者是否有我想要同时使用它们的情况?
谢谢,扎克
编辑:回应评论:我对EJB3了解不多.我只是想了解它是否适用于我的公司.如果EJB3不能与Hibernate相媲美,请解释原因.
java ×5
scala ×3
jsf ×2
android ×1
apache-flex ×1
attributes ×1
comparison ×1
flash ×1
flex3 ×1
hibernate ×1
https ×1
include ×1
javascript ×1
jpa ×1
jquery ×1
jsfunit ×1
junit ×1
layout ×1
onclick ×1
orm ×1
pdf ×1
php ×1
syntax ×1
traits ×1
unit-testing ×1