早上大家,我有一个关于JSF导航和用于导航的问题。我的导航工作正常,直到我将三个.xhtml文件放入子文件夹。我将Home.xhtml,A.xhtml,B.xhtml和C.xhtml都放在同一个文件夹中。将A,B和C.xhtml放入子文件夹A,B和C,然后从Home.xhtml导航到A.xhtml,然后导航到B.xhtml,我收到此错误:“/ A / B / B在ExternalContext中找不到.xhtml作为资源“。显然页面堆叠在URL中,但我不确定原因。
我的豆子:
@ManagedBean(name="company")
@SessionScoped
public class CompanyBean implements Serializable {
private static Map<String, Object> companyValue;
public String value;
boolean temp;
public static Map<String, Object> getCompanyValues() {
return companyValue;
}
public boolean getTemp() {
if (Env.isProd()==true)
{
return true;
}
return false;
}
public void setTemp()
{
temp=Env.isProd();
}
public static void setCompanyValues(Map<String, Object> companyValues) {
CompanyBean.companyValue = companyValues;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public CompanyBean()
{
companyValue=new LinkedHashMap<String, Object>();
companyValue.put("Select Company", "choose");
companyValue.put("AE", "AE/AE.xhtml");
companyValue.put("BP", "BP/BP.xhtml");
companyValue.put("CBK", "CBK/CBK.xhtml");
}
public Map<String,Object> getCompanyValue() {
return companyValue;
}
public void navigate(ValueChangeEvent event)
{
String page= event.getNewValue().toString();
try {
FacesContext.getCurrentInstance().getExternalContext().redirect(page);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
我的jsf代码:
<h:form>
<h:selectOneMenu value="#{company.value}" valueChangeListener="#{company.navigate}" onchange="this.form.submit()">
<f:selectItems value="#{company.companyValue}" />
</h:selectOneMenu>
</h:form>
很抱歉,如果这已经回答,因为它是早上,我半醒。
答案 0 :(得分:1)
您在A.xhtml上使用相对路径到B.xhtml
我建议你使用绝对网址(当然是相对于网络应用程序)
无论您采取何种行动:
改变这个:
public CompanyBean()
{
companyValue=new LinkedHashMap<String, Object>();
companyValue.put("Select Company", "choose");
companyValue.put("AE", "AE/AE.xhtml");
companyValue.put("BP", "BP/BP.xhtml");
companyValue.put("CBK", "CBK/CBK.xhtml");
}
to(参见前面的正斜杠):
public CompanyBean()
{
companyValue=new LinkedHashMap<String, Object>();
companyValue.put("Select Company", "choose");
companyValue.put("AE", "/AE/AE.xhtml");
companyValue.put("BP", "/BP/BP.xhtml");
companyValue.put("CBK", "/CBK/CBK.xhtml");
}