我创建了一个JSF页面和一个带有视图范围的bean。我无法通过<h:textarea>
在bean中设置值。下面是我的代码(Bean和XHTML)
Bean类:
@ManagedBean
@ViewScoped
//@SessionScoped
public class ItemDetailsBean {
private CmsItemEJBDTO item;
private CmsItemEJBDTO detailItem;
private CmsCartEJB cart;
private int quantity;
private int itemId;
private boolean question = false;
private String userItemQuery;
public ItemDetailsBean() {
itemId = 0;
quantity = 1;
}
@EJB
private ShopManagerRemote shopManager;
@ManagedProperty(value="#{loginBean}")
private LoginBean login;
@ManagedProperty(value="#{shoppingCart}")
private ShoppingCart shoppingCart;
@PostConstruct
public void init(){
if(login.getProfile()!=null){
question=true;
}else{
question=false;
}
}
public String getUserItemQuery() {
System.out.println("getUserItemQuery => "+userItemQuery);
return userItemQuery;
}
public void setUserItemQuery(String userItemQuery) {
System.out.println("setUserItemQuery(String userItemQuery) => "+userItemQuery);
this.userItemQuery = userItemQuery;
}
public void submitItemQuestion(){
try{
System.out.println("Queston::::::: " + userItemQuery);
if(userItemQuery!=null){
shopManager.saveItemQuestion(shoppingCart.getShop().getShopId(), itemId, login.getProfile(), userItemQuery);
}else{
System.out.println("UserItemQuery is null............");
}
}catch(Exception e){
System.out.println("Exception while submitting item question");
e.printStackTrace();
}
}
public boolean isQuestion() {
System.out.println("question in isQuestion() = "+ question);
return question;
}
public void setQuestion(boolean question) {
System.out.println("question in setQuestion(boolean question) = "+ question);
this.question = question;
}
}
XHTML代码:
<div class="category-tab shop-details-tab"><!--category-tab-->
<div class="col-sm-12">
<ul class="nav nav-tabs">
<li class="active"><a href="#details" data-toggle="tab">Ask Question</a></li>
</ul>
<h:commandButton action="#{itemDetailsBean.askItemQuestionListner}" value="Ask Question" id="dialogbtn" styleClass="btn btn-primary btn-detault" style="float:right;" >
<f:param name="itemId" value="#{itemDetailsBean.itemId}"></f:param>
<f:param name="question" value="true"></f:param>
<f:ajax execute="@this" update= "question" />
</h:commandButton>
</div>
<h:panelGroup>
<p:panel rendered="#{itemDetailsBean.question}">
<div class="col-sm-7" id="question">
<h1>Enter Your Questions Here!!!</h1>
<h:inputTextarea value="#{itemDetailsBean.userItemQuery}" />
<h:commandButton styleClass="btn btn-primary btn-detault" value="Submit Answer" >
<f:param name="itemId" value="#{itemDetailsBean.itemId}"></f:param>
<f:ajax execute="@this" render="@form" listener="#{itemDetailsBean.submitItemQuestion()}" ></f:ajax>
</h:commandButton>
</div>
</p:panel>
</h:panelGroup>
</div>
textarea
标记始终调用getUserItemQuery()
方法。请帮我解决一下。
答案 0 :(得分:0)
将inputTextArea和commandButton包装在表单中。
<h:form>
<h:inputTextarea value="#{itemDetailsBean.userItemQuery}" />
<h:commandButton styleClass="btn btn-primary btn-detault" value="Submit Answer" >
<f:param name="itemId" value="#{itemDetailsBean.itemId}"></f:param>
<f:ajax execute="@form" render="@form" listener="#{itemDetailsBean.submitItemQuestion()}" ></f:ajax>
</h:commandButton>
</h:form>