`

jsf中弹出win型对话框

阅读更多
<h:form id="form1">
   <a4j:outputPanel ajaxRendered="true">
    <rich:message id="hmessage" for="infor" style="display:none" />
    <script language="javascript" type="text/javascript">   
           //<![CDATA[   
          try{   
              var msg= document.getElementById( "form1:hmessage").innerHTML.replace(/<.+?>/gim,'');   
             if(msg){   
                  if(msg.length > 0){   
                       alert(msg);   
                   }   
               }   
           }catch(e){}   
           //]]>   
       </script>
   </a4j:outputPanel>
<h:input id="qqq"/>
</h:form>

 

 注意,在底层id号的赋值情况

 FacesUtils.addErrorMessage("form1:qqq", e .getMessage());

package com.cvicse.report.ui.portal.util;

import java.util.ResourceBundle;

import javax.faces.FactoryFinder;
import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;
import javax.faces.application.FacesMessage;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.el.ValueBinding;
import javax.faces.webapp.UIComponentTag;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

public class FacesUtils {
	/**
	 * Get servlet context.
	 * 
	 * @return the servlet context
	 */
	public static ServletContext getServletContext() {
		return (ServletContext) FacesContext.getCurrentInstance()
				.getExternalContext().getContext();
	}

	public static ExternalContext getExternalCpntext() {
		return FacesContext.getCurrentInstance().getExternalContext();
	}

	/**
	 * Get managed bean based on the bean name.
	 * 
	 * @param beanName
	 *            the bean name
	 * @return the managed bean associated with the bean name
	 */
	public static Object getManagedBean(String beanName) {
		Object o = getValueBinding(getJsfEl(beanName)).getValue(
				FacesContext.getCurrentInstance());

		return o;
	}

	/**
	 * Remove the managed bean based on the bean name.
	 * 
	 * @param beanName
	 *            the bean name of the managed bean to be removed
	 */
	public static void resetManagedBean(String beanName) {
		getValueBinding(getJsfEl(beanName)).setValue(
				FacesContext.getCurrentInstance(), null);
	}

	/**
	 * Store the managed bean inside the session scope.
	 * 
	 * @param beanName
	 *            the name of the managed bean to be stored
	 * @param managedBean
	 *            the managed bean to be stored
	 */
	public static void setManagedBeanInSession(String beanName,
			Object managedBean) {
		FacesContext.getCurrentInstance().getExternalContext().getSessionMap()
				.put(beanName, managedBean);
	}

	/**
	 * Get parameter value from request scope.
	 * 
	 * @param name
	 *            the name of the parameter
	 * @return the parameter value
	 */
	public static String getRequestParameter(String name) {
		return (String) FacesContext.getCurrentInstance().getExternalContext()
				.getRequestParameterMap().get(name);
	}

	/**
	 * Add information message.
	 * 
	 * @param msg
	 *            the information message
	 */
	public static void addInfoMessage(String msg) {
		addInfoMessage(null, msg);
	}

	/**
	 * Add information message to a sepcific client.
	 * 
	 * @param clientId
	 *            the client id
	 * @param msg
	 *            the information message
	 */
	public static void addInfoMessage(String clientId, String msg) {
		FacesContext.getCurrentInstance().addMessage(clientId,
				new FacesMessage(FacesMessage.SEVERITY_INFO, msg, msg));
	}

	/**
	 * Add error message.
	 * 
	 * @param msg
	 *            the error message
	 */
	public static void addErrorMessage(String msg) {
		addErrorMessage(null, msg);
	}

	/**
	 * Add error message to a sepcific client.
	 * 
	 * @param clientId
	 *            the client id
	 * @param msg
	 *            the error message
	 */
	public static void addErrorMessage(String clientId, String msg) {
		FacesContext.getCurrentInstance().addMessage(clientId,
				new FacesMessage(FacesMessage.SEVERITY_ERROR, msg, msg));
	}

	/**
	 * Evaluate the integer value of a JSF expression.
	 * 
	 * @param el
	 *            the JSF expression
	 * @return the integer value associated with the JSF expression
	 */
	public static Integer evalInt(String el) {
		if (el == null) {
			return null;
		}

		if (UIComponentTag.isValueReference(el)) {
			Object value = getElValue(el);

			if (value == null) {
				return null;
			} else if (value instanceof Integer) {
				return (Integer) value;
			} else {
				return new Integer(value.toString());
			}
		} else {
			return new Integer(el);
		}
	}

	private static Application getApplication() {
		ApplicationFactory appFactory = (ApplicationFactory) FactoryFinder
				.getFactory(FactoryFinder.APPLICATION_FACTORY);
		return appFactory.getApplication();
	}

	private static ValueBinding getValueBinding(String el) {
		return getApplication().createValueBinding(el);
	}

	private static HttpServletRequest getServletRequest() {
		return (HttpServletRequest) FacesContext.getCurrentInstance()
				.getExternalContext().getRequest();
	}

	private static Object getElValue(String el) {
		return getValueBinding(el).getValue(FacesContext.getCurrentInstance());
	}

	private static String getJsfEl(String value) {
		return "#{" + value + "}";
	}

	public static String getMessageByKey(String key) {
		String messageBundleName = FacesContext.getCurrentInstance()
				.getApplication().getMessageBundle();
		ResourceBundle resourceBundle = ResourceBundle
				.getBundle(messageBundleName);
		try {
			return resourceBundle.getString(key);
		} catch (Exception e) {
			return key;
		}
	}
}

 

分享到:
评论

相关推荐

    JSF中文教程jsf

    在JSF中,**组件** 是UI的基础元素,如按钮、文本输入框等。这些组件可以通过XML(Facelets)或JSP页面进行声明,并且可以组合成更复杂的视图结构。**Facelets** 是JSF推荐的视图定义语言,它比JSP更强大,更易于...

    适用于JSF RI 1.0 beta的弹出窗口程序 编辑

    在JSF RI 1.0 beta版中,开发人员可能遇到的一个常见需求是创建弹出窗口或模态对话框,这些窗口通常用于显示额外的信息、确认操作或收集用户的输入。弹出窗口在Web应用中是一种常见的交互方式,可以提供更好的用户...

    JSF中confirm弹出框的用法示例介绍

    在JavaScript Server Faces (JSF) 中,`confirm` 弹出框是一种常见的方式来与用户进行交互,确认他们是否想要执行某项操作。这种功能在网页应用程序中尤其有用,因为它们可以防止用户意外地删除或修改数据。在JSF中...

    适用于JSF RI 1.0 Final Release的弹出窗口程序

    本文将深入探讨如何在JSF 1.0环境中创建并使用弹出窗口,以及如何将弹出窗口的值传递回父窗口。 1. **创建弹出窗口** - 在JSF中,弹出窗口通常通过JavaScript或jQuery来实现。你可以使用`&lt;h:outputScript&gt;`标签...

    精通JSF中文教程精通JSF中文教程

    Managed Beans是JSF中的核心概念,它们作为业务逻辑的载体,可以被JSF框架自动管理。开发者可以定义属性和方法,实现后端逻辑,并通过EL(Expression Language)在视图层与之交互。 **5. EL表达式** EL是一种简洁的...

    JSF中文教程.zip

    在《JSF中文教程》的.chm文件中,读者可以深入学习到这些概念,通过实例和示例代码了解如何在实际项目中应用JSF。该教程将帮助初学者快速上手JSF,同时为有经验的开发者提供参考,提升他们的JSF开发技能。

    JSF中文教程+JSF参数传递方式

    本教程将深入探讨JSF的核心概念以及如何在JSF应用中传递参数,帮助开发者更好地理解和掌握这一技术。 首先,让我们理解**JSF的基本架构**。JSF的核心组件包括视图、控制器和模型,它们共同构成了MVC(Model-View-...

    jsf 中文帮助文档

    **JSF(JavaServer Faces)** 是Java平台上用于构建用户界面的一个组件模型框架,它简化了Web应用程序的开发。...JSF的中文帮助文档是一个...通过阅读和实践,你可以更好地掌握JSF,构建出高效、易于维护的Web应用程序。

    JSF中文问题解决方法完整版

    在IT行业中,JavaScript框架(JSF,JavaServer Faces)是一种广泛应用的用于构建Web应用程序的UI层技术。这篇博文“JSF中文问题解决方法完整版”提供了关于如何处理JSF框架在处理中文字符时可能出现的问题的解决方案...

    JSF入门(中文pdf)

    在JSF中,UI组件(View)可以直接映射到后端的数据源(Model),并可以通过事件处理(Controller)进行交互。这使得开发者可以更专注于业务逻辑,而无需过多关注底层的HTTP通信细节。 首先,JSF的组件库是其一大...

    JSF帮助文档

    标签“jsf”直接指向JSF技术,意味着文档内容可能涉及JSF的使用、教程、最佳实践或者是解决JSF开发中遇到的问题。由于提供的文件内容主要是邮件头信息和HTML格式的元数据,它们并不直接包含JSF的具体知识点。但是,...

    JSF实战(中文+英文)

    **JSF(JavaServer Faces)实战详解** JavaServer Faces(简称JSF)是Java平台上的一个用于构建Web应用程序的UI框架。...在实际项目中,结合JSF的灵活性和Ajax功能,可以创建出响应迅速、用户体验良好的企业级应用。

    jsf中文使用教程jsf中文使用教程

    5. **国际化支持**:JSF支持多语言,这在“JSF中文使用教程”中可能包含如何设置和使用中文资源的内容。 **学习JSF的关键概念**: 1. **Facelet**:Facelets是JSF的默认视图技术,用于创建和组织用户界面组件。 2. ...

    ajax4jsf中文用户指南

    **Ajax请求的发送**:在JSF页面中,你可以使用Ajax4JSF提供的组件,如`a4j:support`或`a4j:commandButton`,来触发Ajax请求。这些组件可以绑定到特定的事件,当事件发生时,会向服务器发送异步请求。 **决定发送...

    教程与手册(Dhtml手册、 JSF中文教程)

    总的来说,这个压缩包中的资料为学习和掌握Java Web开发,特别是DHTML、JSF和Struts2框架提供了全面的学习资源。通过深入阅读和实践这些教程和手册,开发者可以提升自己的技术水平,更好地应对复杂的Web开发挑战。

    jsf实例jsf实例 JSF学习 JSF jar包 JSF

    jsf实例 JSF学习 JSF jar包 JSF jsf实例 JSF学习 JSF jar包 JSFjsf实例 JSF学习 JSF jar包 JSF jsf实例 JSF学习 JSF jar包 JSF

    JSF中使用BooleanCheckbox实现全选功能

    在JavaServer Faces (JSF)框架中,实现全选功能通常是通过使用BooleanCheckbox组件来完成的。这篇博客文章“JSF中使用BooleanCheckbox实现全选功能”可能详细讲解了如何利用这种组件在用户界面中创建一个可以勾选的...

    jsf第一个例子 jsf架包 jsf实例

    7. **jsf实例**:在实际应用中,JSF实例通常指的是一个运行时的JSF应用程序,它包含了配置、组件、Managed Beans以及它们之间的交互。 在“Login”示例中,我们可能看到以下代码片段: ```xml &lt;!-- login.xhtml --...

    JSF全套(JSF入门教+ LIB+ Ajax4JSF使用手册 )

    3. **JSF的LIB**:JSF的核心库包含了许多内置的组件和实用程序,这些库在JSF应用中是必不可少的。学习这部分,你需要了解如何导入和使用JSF的库,例如`javax.faces.*`和`org.primefaces.*`,以及它们提供的功能,如...

Global site tag (gtag.js) - Google Analytics