有没有办法如何从Java方法将页面重定向到其他页面?
我只能使用以下方式转发它:
FacesContext.getCurrentInstance().getExternalContext().dispatch("/foo.xhtml");
Run Code Online (Sandbox Code Playgroud)
或使用导航规则faces-config.xml.
你有什么想法?
如何将一个favicon添加到JSF项目并在<link>元素中引用它?
我试过如下:
<h:head>
<link rel="icon" type="image/x-icon" href="images/favicon.ico"/>
...
</h:head>
Run Code Online (Sandbox Code Playgroud)
但是,它没有显示任何图标.
我需要创建一个通用脚本来重启服务:
net stop <service>
net start <service>
Run Code Online (Sandbox Code Playgroud)
问题是我不知道服务的名称.例如," printer spooler"是名称" spooler".
如何找到任何服务的名称?
我正在以这种方式创建HttpSession容器:
@SessionScoped
@ManagedBean(name="userManager")
public class UserManager extends Tools
{
/* [private variables] */
...
public String login()
{
/* [find user] */
...
FacesContext context = FacesContext.getCurrentInstance();
session = (HttpSession) context.getExternalContext().getSession(true);
session.setAttribute("id", user.getID());
session.setAttribute("username", user.getName());
...
System.out.println("Session id: " + session.getId());
Run Code Online (Sandbox Code Playgroud)
我有SessionListener,它应该给我关于创建的会话的信息:
@WebListener
public class SessionListener implements HttpSessionListener
{
@Override
public void sessionCreated(HttpSessionEvent event) {
HttpSession session = event.getSession();
System.out.println("Session id: " + session.getId());
System.out.println("New session: " + session.isNew());
...
}
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能获得该username属性?
如果我正在尝试使用System.out.println("User name: " + …
我通常可以写捷克字符串到表单:

但是在验证之后(以及当我将收集的字符串发送到数据库时)字符串在其他一些字符集中:

h:outputTexts(jméno,příjmení)仍然正常显示,h:inputTexts不是.
我应该在哪里寻找问题?
更新: HTTP响应标头:

解:
request.setCharacterEncoding("UTF-8")in 创建过滤器Filter#doFilter() <f:view contentType="text/html" encoding="UTF-8"/>到主xhtml将这些行添加到hibernate.cfg.xml:
<property name="hibernate.connection.characterEncoding">utf8</property>
<property name="hibernate.connection.useUnicode">true</property>
我正在尝试使用这个jboss指南为我的JSF 2项目添加richfaces .我已经完成了他们在第2.6点中所说的内容,但在重新启动我的tomcat服务器之后,会报告HTTP状态404.
我错过了什么吗?
更新: 当我添加richfaces-components-ui-4.0.0.Final.jar和richfaces-core-impl-4.0.0.Final.jar,并重新启动tomcat服务器时,它会报告:
INFO: Unsanitized stacktrace from failed start...
com.sun.faces.config.ConfigurationException:
Source Document: jar:file:/D:/WORKSPACE/BC/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/PORTAL/WEB-INF/lib/richfaces-core-impl-4.0.0.Final.jar!/META-INF/faces-config.xml
Cause: Unable to create a new instance of 'org.richfaces.resource.ResourceHandlerImpl': java.lang.reflect.InvocationTargetException
at com.sun.faces.config.processor.AbstractConfigProcessor.createInstance(AbstractConfigProcessor.java:293)
....
13.5.2011 8:41:52 com.sun.faces.config.ConfigureListener contextInitialized
SEVERE: Critical error during deployment:
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! com.google.common.base.Function
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:379)
....
13.5.2011 8:41:52 org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener
java.lang.RuntimeException: com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED! com.google.common.base.Function
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292)
....
13.5.2011 8:41:52 org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
13.5.2011 8:41:52 …Run Code Online (Sandbox Code Playgroud) 我可以更改禁用的背景颜色<h:inputText>吗?
我试过这样做:
<h:inputText value="test" disabled="true" styleClass="input"/>
Run Code Online (Sandbox Code Playgroud)
css包含:
input:disabled {background-color:blue;}
input:enabled {background-color:red;}
Run Code Online (Sandbox Code Playgroud)
结果是:

原因,为什么我要改变背景是,因为我已经安装了richfaces,禁用和启用了相同的颜色,都是白色的
谢谢
更新:

HTML:
<td class="width10">Sm?na:</td>
<td class="width15"><input name="bde:j_idt100" value="2011-05-18-S2" size="13" style="background-color: blue; color: red;" disabled="disabled" type="text"><input id="bde:shift" name="bde:shift" type="hidden"></td>
<td><input name="bde:j_idt102" value="ranní" class="input2" size="13" disabled="disabled" type="text"><input name="bde:j_idt103" value="admin" class="input2" size="13" disabled="disabled" type="text"></td>
</tr>
<tr class="rowEven">
<td class="width5"><input id="bde:f1" name="bde:f1" value="F1" tabindex="2" title="Novy pracovnik - vymaze vsechna pole formulare" class="btninput" type="submit"></td>
<td class="width10">Pracovník:</td>
<td class="width15">
<input id="bde:worker" name="bde:worker" class="input" size="13" tabindex="1" onblur="jsf.util.chain(this,event,'mojarra.ab(this,event,\'blur\',\'@this\',\'bde:inputName\')','mojarra.ab(this,event,\'blur\',\'@this\',\'bde:inputSname\')','mojarra.ab(this,event,\'blur\',\'@this\',\'bde:inputDep\')','mojarra.ab(this,event,\'blur\',\'@this\',\'bde:reportErr\')')" type="text"></td>
Run Code Online (Sandbox Code Playgroud)
richfaces之间的图形差异生成代码和HTML:


我正在尝试使用导入CSV文件:ArraylistStringTokenizer
public class Test
{
public static void main(String [] args)
{
List<ImportedXls> datalist = new ArrayList<ImportedXls>();
try
{
FileReader fr = new FileReader("c:\\temp.csv");
BufferedReader br = new BufferedReader(fr);
String stringRead = br.readLine();
while( stringRead != null )
{
StringTokenizer st = new StringTokenizer(stringRead, ",");
String docNumber = st.nextToken( );
String note = st.nextToken( ); /** PROBLEM */
String index = st.nextToken( ); /** PROBLEM */
ImportedXls temp = new ImportedXls(docNumber, note, index);
datalist.add(temp);
// read …Run Code Online (Sandbox Code Playgroud) 在提交表单(ajax调用)后,我正在尝试选择并专注于选择组件ID.
<script>
var myFunc = function() {
document.getElementById('form:#{bean.componentId}').focus();
document.getElementById('form:#{bean.componentId}').select();
};
$(document).ready(function() {
myFunc();
});
</script>
<h:form id="form">
<h:commandButton action="#{bean.save}" onclick="return myFunc();" ...>
<f:ajax execute="@form" render="@form"/>
</h:commandButton>
...
</h:form>
Run Code Online (Sandbox Code Playgroud)
这个解决方案正在运行,但问题是,<f:ajax>称为AFTER onclick,因此在选择组件后渲染表单,并清除焦点.
如何在表单呈现后调用我的函数?
更新:(我试过例子)
onevent="myFunc();"到f:ajax=>会导致刷新页面onevent="myFunc()"到f:ajax=>相同的行为onclick属性f:ajax是oneventattr.=>仍然一样update2(它应该如何工作):