我知道Application-Scope持久存在于多个用户之间,因此我们应该确保所有ApplicationScoped ManagedBeans都是线程安全的.
我也明白,我们不需要关心RequestScoped ManagedBean的线程安全性.这是因为它仅针对一个HTTP请求而持续,并且如果被引用则针对每个请求进行新实例化.
但我不太清楚为什么我们应该担心SessionScoped ManangedBean的线程安全性.即使它在多个请求中持续存在,每个用户都可以获得自己的实例,对吧?
那么,为什么我们需要在SessionScoped ManagedBeand的情况下担心线程安全,这也适用于ViewScoped ManagedBean吗?ViewScope在同一视图的两个连续请求中持续存在,对吧?
我正在运行以下问题.
我有一些Managed Beans,目前在两个JSF应用程序之间共享.由于我不想将代码复制并粘贴到两者中(未来会更多),我将这个共享的托管bean放在JAR库中.我关注过这个博客:http://jsflive.wordpress.com/2011/03/24/custom-component-library/
好吧,即使我把faces-config.xml放在JAR/META-INF/@ManagedBean中,@ ViewScoped也不起作用.我无法理解为什么,但如果我在faces-config.xml(JAR,而不是WAR)中注册bean,这个问题就会消失.
我可以忍受这个,但令我惊讶的是,没有为JAR库中的这个托管bean调用@PostConstruct注释.我没有收到任何错误,警告或其他.我想豆子正在加载,但他们的注释没有被处理.
谁有人面对这个?
我的环境:Glassfish 3.1.1(build 12)JSF 2.1.3
提前致谢.
有人可以告诉我如何在组件的值中使用否定复选框来启用和禁用它吗?
当bean中的属性值(somevalue)为false时,我必须禁用一个复选框.
像
<h:selectBooleanCheckbox id="smthing" disabled="#{!somevalue}"></h:selectBooleanCheckbox>
Run Code Online (Sandbox Code Playgroud)
对于豆类财产
boolean somevalue;
Run Code Online (Sandbox Code Playgroud)
应该是残缺但它不起作用.也许我做错了什么.
也有人可以澄清一下,如果没有为布尔值赋值,那么情况就是如此.
我想在选择第一个SelectOnMenu的任何项目时更新第二个SelectOneMenu.就像现在一样,我从ManagedBean获取SelectOneMenus的值.我想我将使用AJAX(jquery)将参数发送到ManagedBean.
<h:form>
<div class="center">
<h:panelGrid id="editTable" columns="2" styleClass="center">
...
<h:outputText value="#{msg.timetable_list_category}" />
<h:selectOneMenu class="category">
<f:selectItems value="#{categoryBackingBean.categorys}" var="c"
itemLabel="#{c.category_Name}" itemValue="#{c.id}" />
</h:selectOneMenu>
<h:outputText value="#{msg.timetable_list_seminarblock}" />
<h:selectOneMenu class="seminarblock">
<f:selectItems value="#{seminarblockBackingBean.seminarblocks}" var="s"
itemLabel="#{s.seminarblock_Name}" itemValue="#{s.seminarblock_Id}" />
</h:selectOneMenu>
...
</h:panelGrid>
...
</div>
</h:form>
Run Code Online (Sandbox Code Playgroud) 我有这种JSF Beans结构:
@ManagedBean
@ViewScoped
public class ViewBeany implements Serializable {
....
@ManagedProperty(value='#{sessionBeany})
transient private SessionBeany sessionBeany;
...
public getSessionBeany() { ... };
public setSessionBeany(SessionBeany sessionBeany) { ... };
}
Run Code Online (Sandbox Code Playgroud)
原因transient是会话bean有一些非Serializable成员,不能成为Serializable.
这会有用吗?
如果没有,我如何解决无法序列化SesionBeany但必须将其作为托管属性保存在视图范围内的bean的问题?
谢谢!
当有数据在几个页面中重复时(参考示例)我可以加载到一个托管bean中,并在同一页面中使用多个托管bean.它的影响是什么?
我试图强调一个使用身份验证的相当简单的JSF Web应用程序,jMeter从不调用与按下的按钮关联的动作方法(在托管bean中).多个用户的身份验证(从CSV文件加载)完美运行(或者我认为).我将测试计划减少到最低限度,以便尝试调试这种情况.我有一个登录,一个带有commandLink的简单页面,其动作是ManagedBean中的一个方法(带有requestScope).
我的xpath提取器值是://input [@id ='javax.faces.ViewState']/@ value
我也试过一个正则表达式提取器,使用表达式id = \"javax.faces.ViewState \"value = \"(.+?)\与其中任何一个,它似乎工作正常(我曾经有一些viewState相关问题.
在他的POST请求(包含javax.faces.ViewState)上,我有$ {jsfViewState}作为值(jsfViewState是一个用户定义的变量,它保存从前一个GET方法保存的viewState).
带有commandLink的页面是(注意我故意硬编码了这个值,以便更容易地识别问题):
<h:body>
<ui:composition template="/template/template.xhtml">
<ui:define name="content">
<c:set value="Category" target="#{menu}" property="title"/>
<ui:repeat value="#{category.list}" var="cat">
<h:form id="categoryForm">
<h:commandLink id="btnOrd" action="#{product.placeOrder(1)}">COMPRAR</h:commandLink>
</h:form>
<br/>
</ui:repeat>
</ui:define>
</ui:composition>
</h:body>
Run Code Online (Sandbox Code Playgroud)
managedBean:
@Named("product")
@RequestScoped
public class ProductMBean {
@Inject
private ProductEBean productEBean;
@Inject
private UserProductEBean userProductEBean;
public List<Product> getList(){
return productEBean.findAll();
}
private void addMessage(FacesMessage message){
FacesContext.getCurrentInstance().addMessage(null, message);
}
public String placeOrder(long id){
userProductEBean.createNewOrder(id);
Product product = productEBean.findById(id);
addMessage(new FacesMessage(FacesMessage.SEVERITY_INFO, "Your order of …Run Code Online (Sandbox Code Playgroud) 我有一个CDI托管bean,我想将请求参数设置为托管属性:
import javax.inject.Named;
import javax.enterprise.context.RequestScoped;
@Named
@RequestScoped
public class ActivationBean implements Serializable {
@ManagedProperty(value="#{param.key}")
private String key;
@ManagedProperty(value="#{param.id}")
private Long id;
// Getters+setters
Run Code Online (Sandbox Code Playgroud)
domain/activate.jsf?key=98664defdb2a4f46a527043c451c3fcd&id=5但是,URL是永远不会设置和保留的属性null.
这是怎么造成的,我该如何解决?
我知道我可以从ExternalContext下面手动抓取它们:
Long id = Long.parseLong(FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("id"), 10);
String key = FacesContext.getCurrentInstance().getExternalContext().getRequestParameterMap().get("key");
Run Code Online (Sandbox Code Playgroud)
但是,我宁愿使用注射剂.
jsf cdi managed-bean http-request-parameters managed-property
我可以将表达式传递给JSF 2 passthrough-attributes吗?以下代码无效.#{country.isoCode}不评估表达式.
<h:selectOneMenu value="#{bean.selectedCountry}" styleClass="selectlist">
<f:selectItems
value="#{bean.countries}" var="country"
itemLabel="#{country.countryName}"
pt:data-icon="flag flag-#{country.isoCode}"/>
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
我正在使用命名空间
xmlns:pt="http://xmlns.jcp.org/jsf/passthrough"
Run Code Online (Sandbox Code Playgroud)
和bootstrap-select.属性"data-icon"用于显示图像.看到:
http://silviomoreto.github.io/bootstrap-select/#data-icon
渲染输出:
<i class="glyphicon flag flag-"></i>
Run Code Online (Sandbox Code Playgroud) 我正在尝试设置自己的JSF标记库.因此,我创建了一个带有支持接口的复合组件作为蓝图,为该组件构建支持bean.
public interface CompLogin {
String getUsername();
void setUsername(String username);
String getPassword();
void setPassword(String password);
String validateLogin();
default String getPasswordWatermark() {
return "Passwort";
}
default String getUsernameWatermark() {
return "Loginname:";
}
default String getLoginButtonValue() {
return "Login";
}
}
Run Code Online (Sandbox Code Playgroud)
所以我有登录网站的密码,用户名和验证方法.另外,O想要为Inputtext水印和Button提供一些默认的namings.如果执行人员想要改变它,他可以.
我使用自己的JSF标记在真实应用程序的Backing bean中实现了这个接口.
@Named
@RequestScoped
public class Login implements Serializable, CompLogin {
private String username;
private String password;
@Override
public String getUsername() {
return username;
}
@Override
public void setUsername(String username) {
this.username = username;
}
@Override
public String getPassword() { …Run Code Online (Sandbox Code Playgroud)