如果我有@ManagedBean这个@SessionScoped,为什么我会使用@StatefulEJB?我之前用过购物车并保持会话状态,但由于托管bean将在用户会话期间保存,我可以在那里存储状态,然后调用SLSB以获取业务逻辑.那是对的吗?如果是,那么有状态的ejbs将留给更具体的应用程序,例如何时需要交易等?
在下面的代码片段中,可能看起来它应该发出一些编译错误,但它不会:
class Outer {
public static class Inner {
static String obj = "Inner";
}
static Optional Inner = new Optional();
//The (inner) class name and the object name are same.
}
class Optional {
String obj = "Optional";
}
public class Main {
public static void main(String[] args) {
System.out.println(Outer.Inner.obj);
//Refers to the string inside the optional class
}
}
Run Code Online (Sandbox Code Playgroud)
该类中Outer有一个名为static的静态类Inner.另外,它声明了一个对象(静态)类Optional(static Optional Inner = new Optional();)
这个对象和类名(在类中Outer)是相同的Inner.程序显示 …
我有一个关于POJO中List的初始化的问题,因为它遵循下一个代码:
public class Person {
//other fields...
private List<String> friends=new ArrayList<>();
public List<String> getFriends() {
return friends;
}
public void setFriends(List<String> friends) {
this.friends = friends;
}
}
Run Code Online (Sandbox Code Playgroud)
或者它是这样的更好,并在其他类中具有初始化(例如Bean(JSF))
public class Person {
//other fields...
private List<String> friends;
public List<String> getFriends() {
return friends;
}
public void setFriends(List<String> friends) {
this.friends = friends;
}
}
Run Code Online (Sandbox Code Playgroud)
所以我的问题是什么方法更好?
我有一个<p:dataTable>懒惰的负载.在其中两列中,<p:selectOneMenu>每列都有一个.
第一列包含国家/地区列表,第二列包含数据库中的状态列表.
我想第二个菜单显示在只有那些状态(包含州列表的)每一行对应于该国在第一菜单中的数据表的每一行数据表.
在编辑模式下,当其菜单中的国家/地区更改时,应在其当前行的菜单中填充与该国家/地区对应的状态.
如何在数据表的每一行中加载与其国家/地区对应的状态列表?
数据表中的这两列是不完整的,因为我对如何实现这一点没有一个确切的想法.
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.state.country.countryName}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu value="#{row.state.country}">
<f:selectItems var="country"
value="#{cityBean.selectedCountries}"
itemLabel="#{country.countryName}"
itemValue="#{country}"/>
<p:ajax update="states" listener="#{cityBean.getStates}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
<p:column>
<p:cellEditor>
<f:facet name="output">
<h:outputText value="#{row.state.stateName}"/>
</f:facet>
<f:facet name="input">
<p:selectOneMenu id="states">
<f:selectItems var="state"
value="#{cityBean.selectedStates}"
itemLabel="#{state.stateName}"
itemValue="#{state}"/>
</p:selectOneMenu>
</f:facet>
</p:cellEditor>
</p:column>
Run Code Online (Sandbox Code Playgroud)
cityBean.selectedCountries检索所有必需的国家,但cityBean.selectedStates也从数据库中检索所有不必要的状态,并且应该修改这些状态以仅检索与另一个菜单中的国家相对应的那些状态.
我怎么能从这里开始?
如何将标题字体颜色更改为白色和填充绿色?这些是我正在使用的类:
import static org.apache.poi.ss.usermodel.CellStyle.*
import static org.apache.poi.ss.usermodel.IndexedColors.*
import org.apache.poi.hssf.usermodel.*
import org.apache.poi.hssf.usermodel.HSSFWorkbook
import org.apache.poi.ss.usermodel.Cell
import org.apache.poi.ss.usermodel.CellStyle
import org.apache.poi.ss.usermodel.Row
import org.apache.poi.ss.usermodel.Sheet
import org.apache.poi.ss.usermodel.Workbook
import org.apache.poi.ss.usermodel.Font
Run Code Online (Sandbox Code Playgroud)
这是代码,我相信它必须插入.
Font headerFont = wb.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD)
CellStyle headerStyle = wb.createCellStyle()
headerStyle.setFont(headerFont)
cellMOPID.setCellStyle(headerStyle)
cellType.setCellStyle(headerStyle)
cellStatus.setCellStyle(headerStyle)
cellState.setCellStyle(headerStyle)
cellStartDate.setCellStyle(headerStyle)
cellEndDate.setCellStyle(headerStyle)
cellDesc.setCellStyle(headerStyle)
Run Code Online (Sandbox Code Playgroud) MySQL Workbench是一款出色的工具.但是,工具提示真的让我感到恼火,因为它隐藏了图表中的对象,并没有为我显示任何有用的信息.
我无法禁用工具提示,任何想法禁用它?
[我在OS X Mavericks上使用V 6.0]

我有复杂的查询,创建一个临时表,可能需要5秒钟才能运行或更多.这似乎在同时在类似的表上运行另一个事务时导致死锁.我不能在本地复制,但在生产中我能够每隔几天发生一次.(我记录了mysql错误)
查询非常复杂(显示在页面底部); 但你不需要理解逻辑; 只是它从一堆表和连接中选择,可能需要一段时间才能运行.
我还有一个插入许多相同表的事务.我偶尔会遇到一个mysql错误1213: Deadlock found when trying to get lock; try restarting transaction.
这是交易的伪代码
START TRANSACTION
INSERT INTO phppos_sales
INSERT MANY RECORDS INTO phppos_sales_items
INSERT MANY RECORDS INTO phppos_sales_items_taxes
INSERT MANY RECORDS INTO phppos_sales_payments
END TRANSACTION
Run Code Online (Sandbox Code Playgroud)
How do I go about resolving this deadlock? I tried changing isolation level to READ UNCOMMITTED but mysql settings wouldn't allow for this; and I need to make this work in a variety of environments where I don't have control of …
这是我的标记:
<h:commandLink value="#{partial}" action="#{hello.setCurrentPartial(partial)}">
<f:ajax render="include" listener="#{hello.renderFragments}"/>
</h:commandLink>
Run Code Online (Sandbox Code Playgroud)
我试图在Mojarra-2.2.8(wildfly 8.2.0.Final内置)和MyFaces-2.2.7(按照此处的指导安装)中运行此页面.令人惊讶的是,当点击链接时,mojarra hello.renderFragments首先调用,然后hello.setCurrentPartialMyFaces采用相反的顺序,即hello.setCurrentPartial首先调用.
所以我的问题是在JSF Spec中是否有动作调用顺序和ajax监听器的定义.如果定义了订单,哪个实现是正确的?
从像a这样的迭代组件中删除行时<p:dataTable>,如果删除了最后一页中的所有行,则需要将当前页面重置为其前一页面.这是不幸的是没有自动在<p:dataTable>有LazyDataModel<T>.
语言上,如果一个数据表包含11页,每页10行,并且第11页上的所有行,即最后一行都被删除,它应该自动获得第10页(即前一页),但这不会自动发生(当前页面保持静止(第11个),就像数据表本身被清空一样),除非在关联的辅助bean中的某处显式编码.
非正式地,相应的伪代码段看起来如下所示.
if (rowCount <= (ceiling)((first + 1) / pageSize) * pageSize - pageSize) {
first -= pageSize;
}
Run Code Online (Sandbox Code Playgroud)
first页面偏移(以...开头0)在哪里,pageSize表示每页的行数,并rowCount指示关联的数据存储/数据库中的总行数.
实际上:
@Override
public List<Entity> load(int first, int pageSize, List<SortMeta> multiSortMeta, Map<String, Object> filters) {
// ...
int rowCount = service.getRowCount();
setRowCount(rowCount);
// ...
if (pageSize <= 0) {
// Add an appropriate FacesMessage.
return new ArrayList<Entity>();
} else if (first >= pageSize …Run Code Online (Sandbox Code Playgroud) 以下是一个转换器,主要用于修剪前导和尾随空格,并用一个空格替换句子中的单词或文本之间的多个空格.现在修改转换器以null使用"不可用" 替换或清空字符串(如果需要,可以动态本地化).
@FacesConverter(forClass = String.class)
public class StringTrimmer implements Converter {
@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
return Boolean.TRUE.equals(component.getAttributes().get("skipConverter")) ? value : value == null ? null : value.trim().replaceAll("\\s+", " ");
}
@Override
public String getAsString(FacesContext context, UIComponent component, Object value) {
return Boolean.TRUE.equals(component.getAttributes().get("skipConverter")) ? value == null ? null : value.toString() : value == null || ((String) value).trim().length() == 0 ? "Not available" : ((String) value).trim().replaceAll("\\s+", " ");
}
}
Run Code Online (Sandbox Code Playgroud)
由于未调用转换器,因此当模型值null基于 …
jsf ×6
java ×2
jsf-2.2 ×2
mysql ×2
primefaces ×2
ajax ×1
apache-poi ×1
arraylist ×1
converter ×1
datatable ×1
ejb ×1
java-ee-6 ×1
jsf-2 ×1
managed-bean ×1
myfaces ×1
null ×1
php ×1
string ×1
transactions ×1