下面是我在JSF中检索请求参数映射的方法
FacesContext context = FacesContext.getCurrentInstance();
Map<String, String> requestMap = context.getExternalContext().getRequestParameterMap();
Run Code Online (Sandbox Code Playgroud)
然而requestMap就是immutable这样,我不能编辑它.有没有办法向Request Parameter Map添加更多参数?有可能吗?
我有这个f:viewParam,我尝试绑定验证,并转换userId成Player和我得到了一个意想不到的结果.
<f:metadata>
<f:viewParam name="userId" value="#{myBean.selectedPlayer}" converter="pConverter"
converterMessage="Bad Request. Unknown User" required="true"
requiredMessage="Bad Request. Please use a link from within the system" />
</f:metadata>
<h:body>
<p:messages id="msgs"/>
<h:form>
<ul>
<li><a href="index2.xhtml?userId=1">Harry</a></li>
<li><a href="index2.xhtml?userId=2">Tom</a></li>
<li><a href="index2.xhtml?userId=3">Peter</a></li>
</ul>
</h:form>
<h:form>
<h:panelGrid columns="2" rendered="#{not empty myBean.selectedPlayer}">
<h:outputText value="Id: #{myBean.selectedPlayer.id}"/>
<h:outputText value="Name: #{myBean.selectedPlayer.name}"/>
</h:panelGrid>
</h:form>
<h:form id="testForm">
<h:inputText value="#{myBean.text}"/>
<p:commandButton value="Switch" update=":msgs testForm"/>
<h:outputText value="#{myBean.text}" rendered="#{not empty myBean.text}"/>
</h:form>
</h:body>
Run Code Online (Sandbox Code Playgroud)
我的转换器看起来像这样
@FacesConverter(value="pConverter")
public class PConverter implements Converter …Run Code Online (Sandbox Code Playgroud) 我见过人们在JSF中使用方括号,我不确定我是否理解它的正确用法.所以也许JSF大师可以帮助我理解它
我可以说我有这个
#{bean.x}
Run Code Online (Sandbox Code Playgroud)
和x是二维数组(x [] []),如何x[0]使用EL 显示?我想在这种情况下我需要使用方括号.我想我用#{bean.x[0]},但我得到了例外.
2.第二种情况是从BalusC代码Pass Argument到复合组件action属性
<composite:interface>
<composite:attribute name="bean" type="java.lang.Object" />
<composite:attribute name="action" type="java.lang.String" />
<composite:attribute name="property" type="java.lang.String" />
</composite:interface>
<composite:implementation>
<h:commandButton value="Remove" action="#{cc.attrs.bean[cc.attrs.action]}">
<f:setPropertyActionListener target="#{cc.attrs.bean[cc.attrs.property]}" value="Somestring" />
</h:commandButton>
</composite:implementation>
Run Code Online (Sandbox Code Playgroud)
我理解代码正在做什么并且它工作得很漂亮,但如果有人能解释在这种情况下方括号的用途我会很感激.非常感谢你
如果我有这样的事情
@Entity
public class Facility {
...
@ManyToOne
@JoinColumn(name="CUSTOMER_FK")
private Customer customer;
...
}
Run Code Online (Sandbox Code Playgroud)
我@NameQuery喜欢这样吗
@NamedQuery(name="Facility.findByCustomerId", query="select c from Facility c where c.customer=:customer_fk")
Run Code Online (Sandbox Code Playgroud)
或者像这样
@NamedQuery(name="Facility.findByCustomerId", query="select c from Facility c where c.CUSTOMER_FK=:customer_fk")
Run Code Online (Sandbox Code Playgroud) 我使用的是JSF 2.0 btw
我有一个属性X类型Integer,默认值为0.在我的JSF页面中,我创建了一个组件,如果它X是0,我希望它被禁用,否则启用.
<h:selectBooleanCheckbox disabled="#{X}"/>
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误
Cannot convert 0 of type class java.lang.Integer to class java.lang.Boolean
Run Code Online (Sandbox Code Playgroud) 当我在一个托管的构造函数内部并试图与其他bean的其他方法联系时,我得到了java.lang.NullPointerException.是否有某种规范不允许托管bean这样做?
@ManagedProperty(value="#{document}")
private DisplayListController document;
@EJB
DocumentSBean sBean;
public NewUserController() {
document.list();
}
Run Code Online (Sandbox Code Playgroud)
上面我只是做常规豆注射,没什么花哨的.document是一个SessionScoped托管bean,其方法list()只返回一个String.NewUserController是一个RequestScoped托管bean.
当用户第一次登录时通知,不是那么难,只需要数据库扫描,我可以处理.然而,当朋友发送对简档X的请求或评论时,发送通知,并且即使在用户X没有做出任何请求时也几乎立即在另一端接收.是民意调查吗?不喜欢它,因为页面永远不会刷新自己.它一定是别的吗?任何人都有任何想法?也许网络推送?
简单的一段代码dataTable.CentralFeed是SessionScoped Bean,PostComment是RequestScoped Bean
<h:form id="table">
<h:dataTable value="#{CentralFeed.profileComments}" var="item">
<h:column>
<h:outputText value="#{item.comment}"/><br/>
<h:inputTextarea value="#{item.newComment}" rows="2"/><br/>
<h:commandButton value="Post" action="#{PostComment.postReply(item)}" />
</h:column>
</h:dataTable>
</h:form>
Run Code Online (Sandbox Code Playgroud)
内 CentralFeed.java
private List<NewsFeed> profileComments = null;
public List<NewsFeed> getProfileComments() {
PhaseId currentPhaseId = FacesContext.getCurrentInstance().getCurrentPhaseId();
profileComments = scholarBean.findProfileCommentsByUserId(getSelectedUser().getId());
//model = new ListDataModel<NewsFeed>(profileComments);
return profileComments;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是getProfileComments()被召唤了很多.currentPhaseId将告诉我们该方法被调用的阶段.当页面首次加载时,在第6阶段 - getProfileComment约5次接听电话RENDER_RESPONSE.页面有一个inputTextarea,所以我输入了一些内容,然后单击Post(commandButton).然后再通过阶段1-> 4 再getProfileComment调用12次.每个阶段调用此方法3-4次.然后,在属性newComment获取调用的setter方法(所以setNewComment()得到调用),getProfileComment再次调用get调用 …
首先,我的框架是带有JSF,托管bean,EJB和JPA的Java EE 6.我编写了一个简单的程序来查询数据库中的信息.因此,当我单击一个按钮时,它会触发一个事件到托管bean,其中事件侦听器方法将访问EJB方法.EJB方法将对select实体进行简单查询.如果数据库在I之前或期间关闭select,我会收到异常
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet successfully received from the server was 51,460 milliseconds ago. The last packet sent successfully to the server was 0 milliseconds ago.
Error Code: 0
Run Code Online (Sandbox Code Playgroud)
如何防止此异常?肯定是try, catch在这里,但不知道在哪里放.当我em.createNamedQuery还是em.remove,我试图抓住com.mysql.jdbc.exceptions.jdbc4.CommunicationsException,但我得到了一个错误说:Exception com.mysql.jdbc.exceptions.jdbc4.CommunicationsException is never thrown in body of corresponding try statement.
以下是我的代码,我会在哪里捕获异常?
这是我的 EJB
@Stateless
@LocalBean
public class DocumentSBean {
@PersistenceContext …Run Code Online (Sandbox Code Playgroud) 我很奇怪是有一个Web服务或数据库,让我们以编程方式检查用户输入是否是有效的ISBN号,然后将其存储在数据库中.或者是否有一种算法允许程序员这样做