- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在实现一个简单的 CRUD 应用程序时遇到问题,我几乎阅读了在 google、stackoverflow 和 roseindia 中找到的所有项目,但我的问题仍然存在。我制作了这个简单的 facelet:
<ui:composition template="./../../templates/adminTemplate.xhtml">
<ui:define name="tope">
<h1>Ingreso de Noticias</h1>
</ui:define>
<ui:define name="content">
<h:form id="newsForm">
<h:panelGrid columns="2">
<h:outputLabel value="Lugar: "/>
<h:inputText value="#{noticiasBean.entity.lugar}"/>
<h:outputLabel value="Fecha: "/>
<h:inputText value="#{noticiasBean.entity.fecha}">
<f:convertDateTime pattern="dd/MM/yyyy HH:mm"/>
</h:inputText>
<h:outputLabel value="Autor: "/>
<h:inputText value="#{noticiasBean.entity.autor}"/>
<h:outputLabel value="PreTítulo: "/>
<h:inputText value="#{noticiasBean.entity.pretitulo}"/>
<h:outputLabel value="Título: "/>
<h:inputText value="#{noticiasBean.entity.titulo}"/>
<h:outputLabel value="Comentario: "/>
<h:inputText value="#{noticiasBean.entity.comentario}"/>
<h:outputLabel value="Cuerpo: "/>
<h:inputTextarea value="#{noticiasBean.entity.cuerpo}"/>
</h:panelGrid>
<h:commandButton value="Guardar" action="#{noticiasBean.create}"/>
</h:form>
<h:messages style="color: red;"/>
</ui:define>
</ui:composition>
这是管理模板:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:p="http://primefaces.org/ui">
<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="./../resources/css/default.css" rel="stylesheet" type="text/css" />
<link href="./../resources/css/cssLayout.css" rel="stylesheet" type="text/css" />
<h:outputStylesheet name="primeStyles.css" library="css"/>
<title>Facelets Template</title>
</h:head>
<h:body>
<p:layout fullPage="true">
<p:layoutUnit position="north" size="70" resizable="true" closable="true" collapsible="true">
<ui:insert name="tope"> Sección de Administración</ui:insert>
</p:layoutUnit>
<p:layoutUnit position="south" size="70">
<ui:insert> Pie de página </ui:insert>
</p:layoutUnit>
<p:layoutUnit position="west" size="160" header="Menu" resizable="true" collapsible="true">
<h:form id="formMenu">
<p:panelMenu style="width: 158px;">
<p:submenu label="Home">
<p:menuitem value="Admin" action="/admin/admin"/>
<p:menuitem value="Salir" action="#{loginController.logout}"/>
</p:submenu>
<p:submenu label="Contenido">
<p:menuitem value="Cargar Noticia" action="/admin/noticias/Create"/>
</p:submenu>
</p:panelMenu>
</h:form>
</p:layoutUnit>
<p:layoutUnit position="center">
<ui:insert name="content">
Aqui va el contenido
</ui:insert>
</p:layoutUnit>
</p:layout>
</h:body>
这里是 managedBean:
@ManagedBean(name="noticiasBean")
@RequestScoped
public class NoticiasBean {
private NoticiaJpaController jpaController = null;
private DataModel items = null;
private Noticia entity;
/**
* Creates a new instance of NoticiasBean
*/
public NoticiasBean() {
System.out.println("Instanciado el bean");
}
private NoticiaJpaController getJpaController() {
if(jpaController == null){
jpaController = new NoticiaJpaController(Utils.getEntityManagerFactory());
}
return jpaController;
}
public Noticia getEntity() {
if(entity == null){
entity = new Noticia();
}
return entity;
}
public String prepareCreate() {
entity = new Noticia();
return "Create";
}
public String create() {
System.out.println("Llegó al método create");
try {
getJpaController().create(entity);
String mensaje = "Noticia creada exitósamente";
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, mensaje, mensaje);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
return prepareCreate();
} catch (Exception e) {
String mensaje = "Error de Persistencia";
FacesMessage facesMsg = new FacesMessage(FacesMessage.SEVERITY_INFO, mensaje, mensaje);
FacesContext.getCurrentInstance().addMessage(null, facesMsg);
return null;
}
}
public String prepareList() {
recreateModel();
return "List";
}
public DataModel getItems() {
if (items == null) {
items = new ListDataModel(getJpaController().findNoticiaEntities());
}
return items;
}
private void recreateModel() {
items = null;
}
这是 web.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<description>Usado para evitar que ingresen sin estar autenticado</description>
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESION</param-name>
<param-value>false</param-value>
</context-param>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/faces/index.xhtml</location>
</error-page>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>faces/index.xhtml</welcome-file>
</welcome-file-list>
如您所见,没有什么特别的,但每次我按下 h:commandButton 以保存数据时,总是返回到相同的页面 Create.xhtml,没有任何错误消息,也没有将信息保存在数据库中,更糟糕的是,丢失了对样式文件 syle.css 的引用。
最佳答案
经过多次阅读和调查,我解决了阅读此问题 information来自@BalusC。我从不在我的 facelet 中使用两个 h:form 元素,所以我不知道为什么现在可以工作。只是我更改了 Primefaces 的 p:commandButton 和“voila”的 h:commandButton,现在一切正常。
关于JSF 2.0 commandButton 什么也不做,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12628873/
当我使用 PrimeFaces 时 p:commandButton 我没有看到输入的验证消息(默认的 h: 或 PrimeFaces p: 的。)例如 当我使用默认命令按钮时 我确实看到了验证。
当鼠标指针悬停在另一个命令按钮上时,我需要显示一个 primefaces 命令按钮,但只有在非常必要时我才能使用 div。如果可能的话,使用 onmuseover 事件会更好,例如: 最佳答案 如
要求是在单击按钮时打开一个新窗口/选项卡。新窗口应重定向到新 URL 或新页面。我尝试过以下代码: 但这会再次打开当前页面。如何设置在新窗口/选项卡中打开新页面或网址? 最佳答案 试试这个: XHT
出于与此问题无关的原因,我已在我的应用程序中将 h:commandButton 完全替换为 a4j:commandLink。从那时起,我在 IE8 中看到了一些奇怪的副作用,例如失去焦点的选择菜单和无
style to
有谁知道如何将相同的样式从命令按钮放到所有命令链接? 我希望所有链接都这样显示(覆盖链接样式并使用按钮样式): 普通按钮: 悬停按钮: 按下的按钮: 我目前的 primefaces 主题是 开始 最佳
我想在 backingbean 中执行一个函数,在存在验证错误的表单中使用命令按钮。 使用代码示例,我想调用函数“resiCon.cancel()”,而不管表单上是否存在验证错误。 你能帮帮我吗?
我的问题是。我有一个primefaces 对话框(模态窗口)。它里面有一个命令按钮。当我打开对话框并单击命令按钮时,对话框外部和后面的输入也会被验证。我只想处理对话框内的输入。 重要的是,我将对话框添
我使用 Primefaces 轮播组件来显示项目列表。我想做的是在每个轮播项目上显示一个命令按钮,它会触发 bean 上的方法来确认或拒绝条目。 现在它只适用于轮播的第一个条目。单击另一个条目不会调用
我正在使用来自JSF的命令按钮。我不知道为什么我不能调用我的javascript函数。当我单击按钮时,不会显示任何警报。 我的Javascript函数: function checkPassword
我想制作一个导航到不同 URL 的按钮,并在 URL 中传递一些请求参数。 outputLink 有效,但我想要一个按钮,commandButton 看起来不错但我可以传递参数。 有解决办法吗? 最佳
我遇到了 commandButton 的问题,它仅在提交类型时才起作用。有人可以看看并告诉我是否有解决方案吗?下面的代码非常简单,并且确实有说明我需要的建议。不执行方法 test()。方法 runSu
在我的 xhtml 中,在 内标签我有多个面板,a4j:jsFunction 和 rich:popupPanel 以及 rich:panel。在我的 rich:panel 中,我有一些文本区域。然后
我想要一个代码来取消选中工作簿中所有工作表的所有名为“CheckBox1”的复选框。不幸的是,我当前的代码不起作用,我不确定为什么 - 它只适用于事件工作表。 Private Sub CommandB
我正在使用 Primefaces 使我的应用程序更加美观。我注意到 p:commandButton 和 h:commandButton 的工作方式不同。 p:commandButton 调用该方法并且
对于以下代码,我收到此错误 Method or Data Member not found. Private Sub Workbook_Open() Dim ws1 As Worksheet:
我是 JSF 和 RichFaces 的新手。我有一个应该调用 bean 方法的按钮。当我使用 它工作正常,但是当我点击 没有任何反应。 我的bean代码: public class LoginB
我正在使用 JSF,我想像 h:outputFormat 一样参数化命令按钮的文本。 有点像 此刻的我 但这让我在每次有参数时将所有存储为属性的文本一分为二 有什么提示吗? 最佳答案 我们使用
嗨,我有一个问题一直想问。我说的是不同类型的 type 标签。我读了一点,但大多数页面只有不同标签的名称,仅此而已。这样的 CommandButton、forms 或 tags 的范围是什么?使用标记
我有一个 Primefaces 命令按钮 自定义CSS类 .mybutton{ margin-left: 10px; margin-bottom: 10px; widt
我有两个命令按钮,当我点击输入时,第一个提交。如果用户点击回车,我真的只想提交第二个按钮。有任何想法吗? 最佳答案 我意识到这个问题很老,但也许有人看到不同的解决方案仍然很有趣。 您可以使用 Prim
我是一名优秀的程序员,十分优秀!