Using P:CommandButton in PrimeFaces - jsf

Originally I have this form for user input and do a search.
<h:form id="wordForm">
<h:panelGrid columns="4">
<h:inputText id="word" "
value="#{wordController.word}" />
<h:message for="word" />
<h:commandButton id="search" value="search"
action="#{wordController.search}" />
</h:panelGrid>
</h:form>
Now I want to use PrimeFaces for autocomplete feature, and this is my new form with Autocomplete. How can I replace the new form with the above form?
<h:form>
<p:growl id="msgs" showDetail="true" />
<h:panelGrid columns="2" cellpadding="5">
<p:autoComplete id="wordForm" value="#{autoCompleteView.query}"
completeMethod="#{autoCompleteView.completeQuery}" var="query"
itemLabel="#{query.displayName}" itemValue="#{query}"
converter="queryConverter" forceSelection="true" />
<p:commandButton value="search" oncomplete="PF('dlg').show()" **action="#{wordController.search}"** />
</h:panelGrid>
</h:form>
More specifically, I think I still need to somehow use "action="#{wordController.search}" in P:CommandAction button so that I don't need to change anything else in backend. But How do I pass the query parameter to the "wordController.word" variable? Because now "action="#autoCompleteView.query" takes the user input.
How can I modify this without significant change to current bean code? Do I have to unify the original search bean WordController with the new AutocompleteView bean? because now the user input is accepted into AutoCompleteView bean.
AutoCompleteView.java
#ManagedBean
public class AutoCompleteView {
private Query query;
#ManagedProperty("#{queryService}")
private QueryService service;
private List<Query> selectedQueries;
public List<Query> completeQuery(String query) {
System.out.println(query);
List<Query> allQueries = service.getQueries();
List<Query> filteredQueries = new ArrayList<Query>();
for (int i = 0; i < allQueries.size(); i++) {
Query skin = allQueries.get(i);
if(skin.getName().toLowerCase().contains(query)) {
filteredQueries.add(skin);
}
}
return filteredQueries;
}
public void onItemSelect(SelectEvent event) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Item Selected", event.getObject().toString()));
}
public Query getQuery() {
return query;
}
public void setQuery(Query query) {
this.query = query;
}
public void setService(QueryService service) {
this.service = service;
}
public List<Query> getSelectedQueries() {
return selectedQueries;
}
public void setSelectedQueries(List<Query> selectedQueries) {
this.selectedQueries = selectedQueries;
}
}
Edited per suggestion:
#Named
#RequestScoped
public class WordController {
private String word;
// For AutoComplete suggestions
private Query selectedQuery;
#Inject
private QueryService service;
#Inject
private Word wordObject;
public void search() {
if (word != null && !word.isEmpty()) {
wordObject.searchWord(word);;
...
}else {
System.out.println("Query can't be null!");
}
}
public List<Query> completeQuery(String query) {
List<Query> allQueries = service.getQueries();
List<Query> filteredQueries = new ArrayList<Query>();
for (int i = 0; i < allQueries.size(); i++) {
Query skin = allQueries.get(i);
if(skin.getName().toLowerCase().contains(query)) {
filteredQueries.add(skin);
}
}
return filteredQueries;
}
public String getWord() {
return word;
}
public void setWord(String word) {
this.word = word;
}
public Query getSelectedQuery() {
return selectedQuery;
}
public void setSelectedQuery(Query selectedQuery) {
this.selectedQuery = selectedQuery;
}
}
Question: Originally, my 'word' is filled through an "h:inputText" in JSF view and search() is called in JSF:
<h:commandButton id="search" value="Search!" action="#{wordController.search}" />
Now, how do I get "selectedQuery" from completeQuery() method, and then use it to fill "word" and then call search() method?

Related

Passing additional Objects to commandLink

I want to use the same View for different states of a bean. Therefore I need to Inject/pass/whatever get the current bean I want to modify, but I always get null.
I already tried it with , with #Inject, and the other solutions given in How can I pass selected row to commandLink inside dataTable or ui:repeat?
The View:
import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import org.primefaces.PrimeFaces;
import de.auticon.beans.Mitarbeiter;
import de.auticon.beans.Skill;
#Named(value = "skillView")
#ViewScoped
public class SkillView implements Serializable {
private static final long serialVersionUID = -3256509521249071048L;
private Mitarbeiter employee;
private Skill skill = new Skill();
private List<String> expertises = new ArrayList<String>();
#PostConstruct
public void init() {
List<Expertise_String> expertiseObjects = Queries.findAllExpertises();
for (Expertise_String singleExpertise : expertiseObjects) {
expertises.add(singleExpertise.getExpertise() + " - " + singleExpertise.getFullNameString());
}
}
//Here employee is null, but I need the new/existing employee
public void addSkill() {
employee.getSkills().add(skill);
PrimeFaces.current().dialog().closeDynamic(null);
}
public void closeDialog() {
PrimeFaces.current().dialog().closeDynamic(null);
}
public Skill getSkill() {
return skill;
}
public void setSkill(Skill skill) {
this.skill = skill;
}
public Mitarbeiter getEmployee() {
return employee;
}
public void setEmployee(Mitarbeiter employee) {
this.employee = employee;
}
}
XHTML from which it is called for existing employees:
<h:form id="form">
<p:panelGrid columns="2" styleClass="ui-noborder">
<p:menu toggleable="true">
<p:submenu label="Verwaltung">
<p:menuitem>
<p:commandButton value="Mitarbeiter anlegen" action="#{adminView.addNewEmployee}" icon="pi pi-users"
process="#this :form:skillsDialog">
<p:ajax event="dialogReturn" listener="#{mitarbeiterView.update}" update=":form, :form:table"/>
</p:commandButton>
</p:menuitem>
</p:submenu>
</p:menu>
<p:dataTable id="table" var="row" value="#{mitarbeiterView.mitarbeiter}" liveResize="true" resizableColumns="true">
<p:column headerText="Skillset">
<p:commandLink update=":form:skillsDialog, :form:skillsDetails" oncomplete="PF('skillsDialog').show()" title="Detail"
styleClass="ui-icon pi pi-search">
<f:setPropertyActionListener value="#{row}" target="#{mitarbeiterView.selectedEmployee}" />
</p:commandLink>
<p:commandLink action="#{adminView.openNewSkillDialog(row)}" title="add" styleClass="ui-icon pi pi-plus">
<!-- <f:setPropertyActionListener value="#{row}" target="#{skillView.employee}" /> -->
</p:commandLink>
</p:column>
</p:dataTable>
</p:panelGrid>
<p:dialog id="skillsDialog" header="Skillsheet von #{mitarbeiterView.selectedEmployee.vorname} #{mitarbeiterView.selectedEmployee.name}"
showEffect="fade" widgetVar="skillsDialog" modal="true" resizable="true">
<p:outputPanel id="skillsDetails">
<p:dataTable var="skillRow" value="#{mitarbeiterView.selectedEmployee.skills}">
<p:column headerText="Skill">
<h:outputText value="#{skillRow.name}" />
</p:column>
<p:column headerText="Ausprägung">
<h:outputText value="#{skillRow.expertise} - #{skillRow.expertiseString.fullName}" />
</p:column>
<p:column headerText="Beschreibung">
<h:outputText value="#{skillRow.description}" />
</p:column>
</p:dataTable>
</p:outputPanel>
</p:dialog>
</h:form>
Second XHTML, for new employees:
<h:form id="newForm">
<h3>Skillsheet</h3>
<p:panelGrid id="skillPanel" columns="2" cellpadding="5" styleClass="ui-noborder">
<p:column style="width:50px">
<p:commandButton id="openAddSkill" process="#this" action="#{adminView.openNewSkillDialog}"
title="Neuer Skill" icon="pi pi-plus">
<!-- <f:setPropertyActionListener target="#{skillView.employee}" value="#{newEmployeeView.newEmployee}"/> -->
<p:ajax event="dialogReturn" update=":newForm :newForm:skillPanel"/>
</p:commandButton>
</p:column>
</p:panelGrid>
<p:commandButton value="Hinzufügen" id="addSkill" icon="pi pi-plus" action="#{skillView.addSkill()}"/>
</h:form>
AdminView.java:
#Named(value = "adminView")
#ViewScoped
public class AdminView implements Serializable {
private static final long serialVersionUID = 5252224062484767900L;
#Inject
private SkillView skillView;
public void addNewEmployee() {
Map<String, Object> options = new HashMap<String, Object>();
options.put("id", "newEmployeeDialogID");
options.put("widgetVar", "newEmployeeDialogVar");
options.put("resizable", false);
options.put("modal", false);
PrimeFaces.current().dialog().openDynamic("/dialogs/newEmployee", options, null);
}
public void openNewSkillDialog(Mitarbeiter employee) {
Map<String, Object> options = new HashMap<String, Object>();
options.put("resizable", true);
options.put("modal", false);
options.put("contentWidth", 420);
PrimeFaces.current().dialog().openDynamic("/dialogs/skill", options, null);
skillView.setEmployee(employee);
}
}
Skill.java:
public class Skill {
#NotNull(message = "Skill fehlt")
private String name;
#NotNull(message = "Bitte Ausprägung angeben")
private short expertise;
private String description;
private String expertiseFullname;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public short getExpertise() {
return expertise;
}
public void setExpertise(short expertise) {
this.expertise = expertise;
}
public String getExpertiseFullname() {
return expertiseFullname;
}
public void setExpertiseFullname(String expertiseFullname) {
this.expertiseFullname = expertiseFullname;
}
public void setExpertise(String fullName) {
try {
this.expertise = Short.valueOf(fullName.substring(0, fullName.indexOf(" - ")));
} catch (Exception e) {
this.expertise = 0;
}
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
Mitarbeiter.java:
public class Mitarbeiter {
private int id;
#NotNull(message = "Nachname fehlt")
private String name;
#NotNull(message = "Vorname fehlt")
private String vorname;
private Date entryDate;
private List<Skill> skills = new ArrayList<Skill>();
private int expertise;
public Mitarbeiter() {
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getVorname() {
return vorname;
}
public void setVorname(String vorname) {
this.vorname = vorname;
}
public List<Skill> getSkills() {
return skills;
}
public void setSkills(List<Skill> skills) {
this.skills = skills;
}
public int getExpertise() {
return expertise;
}
public void setExpertise(int expertise) {
this.expertise = expertise;
}
MitarbeiterView.java:
#Named(value = "mitarbeiterView")
#ViewScoped
public class MitarbeiterView implements Serializable {
private static final long serialVersionUID = 7924178697538784022L;
#Inject
MitarbeiterService mitarbeiterService;
private List<Mitarbeiter> mitarbeiter;
private Mitarbeiter selectedEmployee;
#PostConstruct
public void init() {
SessionConfig.initSession();
new Commons();
updateMitarbeiter();
}
private void updateMitarbeiter() {
mitarbeiter = new ArrayList<Mitarbeiter>();
List<EmployeeDTO> dtos = Queries.findAllEmployees();
for (EmployeeDTO employeeDTO : dtos) {
mitarbeiter.add(mitarbeiterService.convertToMitarbeiter(employeeDTO));
}
}
public void update() {
updateMitarbeiter();
PrimeFaces.current().ajax().update("form:table");
}
public List<Mitarbeiter> getMitarbeiter() {
return mitarbeiter;
}
public void setMitarbeiter(List<Mitarbeiter> mitarbeiter) {
this.mitarbeiter = mitarbeiter;
}
public void setSelectedEmployee(Mitarbeiter selectedEmployee) {
this.selectedEmployee = selectedEmployee;
}
public Mitarbeiter getSelectedEmployee() {
return selectedEmployee;
}
NewEmployeeView.java:
#Named(value = "newEmployeeView")
#ViewScoped
public class NewEmployeeView implements Serializable {
private static final long serialVersionUID = 789108010781037452L;
#ManagedProperty(value = "#{mitarbeiter}")
private Mitarbeiter newEmployee = new Mitarbeiter();
#PostConstruct
public void init() {
}
public Mitarbeiter getNewEmployee() {
return newEmployee;
}
public void setNewEmployee(Mitarbeiter mitarbeiter) {
this.newEmployee = mitarbeiter;
}
Calling adSkill() from the first XHTML should have the selected employee from the Datatable. In the second case, it should have a freshly created, "empty" employee, which I already provide.
I think that major cause of your problems is that skillView bean is #RequestScoped meaning that it is being constructed and destroyed on each request and thus your employee is being reinitialized/reset to null every time. Check out this accepted answer for details.
Hints that might lead you to solution:
put debug lines in at least init() and setEmployee(..) methods of skillView and observe behaviour,
change scope of skillView to #ViewScoped which will preserve employee object across multiple Ajax requests

Passing parameters in JSF and PrimeFaces

I am studying a PrimeFaces AutoComplete demo. I shortenied it from the full showcase demo. http://www.primefaces.org/showcase/ui/input/autoComplete.xhtml
AutoCompleteBean.java
#ManagedBean
public class AutoCompleteBean {
private Query query;
private List<Query> queries = new ArrayList<Query>();
#PostConstruct
public void init() {
queries.add(new Query(0, "Afterdark", "afterdark"));
queries.add(new Query(1, "Afternoon", "afternoon"));
queries.add(new Query(2, "Afterwork", "afterwork"));
queries.add(new Query(3, "Aristo", "aristo"));
}
public List<Query> completeQuery(String query) {
List<Query> filteredQueries = new ArrayList<Query>();
for (int i = 0; i < queries.size(); i++) {
Query skin = queries.get(i);
if(skin.getName().toLowerCase().contains(query)) {
filteredQueries.add(skin);
}
}
return filteredQueries;
}
public void onItemSelect(SelectEvent event) {
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Item Selected", event.getObject().toString()));
}
public Query getQuery() {
return query;
}
public void setQuery(Query query) {
this.query = query;
}
}
Query.java
public class Query {
private int id;
private String displayName;
private String name;
public Query() {}
public Query(int id, String displayName, String name) {
this.id = id;
this.displayName = displayName;
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDisplayName() {
return displayName;
}
public void setDisplayName(String displayName) {
this.displayName = displayName;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
#Override
public String toString() {
return name;
}
}
I omitted a Convert class, which I think is not that relevant.
search.xhtml
<h:form>
<p:growl id="msgs" showDetail="true" />
<h:panelGrid columns="2" cellpadding="5">
<p:autoComplete id="queryPojo" value="#{autoCompleteView.query}"
completeMethod="#{autoCompleteView.completeQuery}" var="query"
itemLabel="#{query.displayName}" itemValue="#{query}"
converter="queryConverter" forceSelection="true" />
<p:commandButton value="search" oncomplete="PF('dlg').show()"/>
</h:panelGrid>
</h:form>
I have three questions for this:
1) completeMethod="#{autoCompleteView.completeQuery}": completeQuery method is called without passing a parameter, but it's defined as completeQuery(String query). How does this work?
2) value="#{autoCompleteView.query}". Query is an object defined in AutoCompleteBean. How can this Query object take user input string as its value? Usually InputText's value is good for taking user's input, which is a String value.
3) Can I still add an attribute "action=..." to the p:autoComplete componenet?
The converter class that you omitted here plays the real game.... Lets see your questions
As you see converter class overrides 2 methods
getAsString and getAsObject
1)the value
completeMethod="#{autoCompleteView.completeQuery}
gets refactred to
autoCompleteView.completeQuery(autoCompleteView.query);
as you can find to string method in Query class.
2).as converter is defined for autocomplete it calls getAsString method to render on screen. when selected getAsObject method is called to convert string value to object(Query).
3)you can use ajax select event
<p:ajax event="select" listener="#{autoCompleteView.someMethod}">
or call a remoteCommand by onSelect attribute in p:autoComplete
<p:autoComplete id="queryPojo" value="#{autoCompleteView.query}" onSelect="someRemoteCommand();"
completeMethod="#{autoCompleteView.completeQuery}" var="query"
itemLabel="#{query.displayName}" itemValue="#{query}"
converter="queryConverter" forceSelection="true" />
<p:remoteCommand name="someRemoteCommand" update="queryPojo" actionListener="#{autoCompleteView.execute}" />

jsf primefaces download file in dilogue box is not working

I want to download file in my jsf page, and below is my jsf page
<h:form id="MyListForm">
<p:commandButton value="Attachments" icon="ui-icon-transferthick-e-w" actionListener="#{myTeam.downloadImageDialogue}"
style="font-size: 10px;font-weight: bolder;vertical-align: text-bottom;width: 80px;" >
</p:commandButton>
</h:form>
and my bean code is:
public void downloadImageDialogue() {
RequestContext.getCurrentInstance().openDialog("AttachmentDialog");
}
and my dilogue xhtml page is:
<h:body>
<h:form>
<p:dataTable var="Attachment" value="#{attachmentDialogView.attachmentList}" rows="10">
<p:column headerText="File Name">
<h:outputText value="#{Attachment.fileName}" />
</p:column>
<p:column headerText="Download Attachment">
<p:commandLink ajax="false" id="dwldLink" action="#{attachmentDialogView.downloadImage}">
<f:setPropertyActionListener value="#{Attachment.id.itemId}" target="#{attachmentDialogView.imageItemId}" />
<f:setPropertyActionListener value="#{Attachment.fileName}" target="#{attachmentDialogView.fileName}" />
<f:setPropertyActionListener value="#{Attachment.id.callId}" target="#{attachmentDialogView.callID}" />
<p:graphicImage value="images/dnld1.png" width="25" height="25"/>
<p:fileDownload value="#{attachmentDialogView.file}"/>
</p:commandLink>
</p:column>
</p:dataTable>
</h:form>
</h:body>
and bean code is:
#ManagedBean(name = "attachmentDialogView")
#ViewScoped
public class AttachmentDialogView implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
private List<Attachment> attachmentList;
private String imageItemId;
private String fileName;
private DefaultStreamedContent file;
String callID;
#ManagedProperty("#{myTeamService}")
private MyTeamService service;
#PostConstruct
public void init() {
attachmentList = service.getAttachmentList(service.getCallId());
}
public void downloadImage() {
Session session = HibernateUtil.getSessionFactory().openSession();
Attachment attachment = null;
byte[] bImage;
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
try {
if (getCallID() == null || getCallID().equals("")) {
RequestContext.getCurrentInstance().execute("PF('check_dialog').show()");
} else {
attachment = (Attachment) session.createCriteria(Attachment.class).add(Restrictions.eq("id.itemId", getImageItemId())).add(Restrictions.eq("id.callId", getCallID())).uniqueResult();
bImage = attachment.getFileData();
InputStream stream = new ByteArrayInputStream(bImage);
file = new DefaultStreamedContent(stream,externalContext.getMimeType(getFileName()),getFileName());
}
} catch (Exception ex) {
ex.printStackTrace();
}finally {
session.close();
}
}
public List<Attachment> getAttachmentList() {
return attachmentList;
}
public void setAttachmentList(List<Attachment> attachmentList) {
this.attachmentList = attachmentList;
}
public MyTeamService getService() {
return service;
}
public void setService(MyTeamService service) {
this.service = service;
}
public String getImageItemId() {
return imageItemId;
}
public void setImageItemId(String imageItemId) {
this.imageItemId = imageItemId;
}
public String getFileName() {
return fileName;
}
public void setFileName(String fileName) {
this.fileName = fileName;
}
public DefaultStreamedContent getFile() {
return file;
}
public void setFile(DefaultStreamedContent file) {
this.file = file;
}
public String getCallID() {
return callID;
}
public void setCallID(String callID) {
this.callID = callID;
}
}
here dilogue opens correctly but image will not opened please help me.

Primefaces InputText passing empty value to the backing bean

I am using JSF template with top, left and content views of a chat application. On the left is a list of discussions, displayed using composite components. When I select one discussion, every conversation in the selected discussion is required to the displayed in the content. There is a create button in the content pane which allows to create a new text within the selected discussion. On click of create, a dialog opens to input the message text.
The issue is, when I select a discussion on the left, and then click on the create in the content, the text message from the dialog is passing blank values to the backing bean. The setter method is getting called, but the value passed is blank. I observed that, if I click on create when the page is loaded, without selecting a discussion, it is sending the message with correct value. Every subsequent creates even after selecting a discussion continues to pass the same value.
I am using Primefaces 3.4.2 and glassfish 4.
Below is the center pane xhtml
<h:body>
<h:form id="newForm">
<p:commandLink id="test" value="Create Bubble" />
<p:overlayPanel id="panel" for="test" >
<p:commandButton id="map" icon="ui-icon-map" onclick="map_dlg.show();"/>
<p:commandButton id="map1" icon="ui-icon-document" onclick="survey_dlgcreate.show();"/>
<p:commandButton id="map2" icon="ui-icon-folder" onclick="txt_dlg.show();"/>
</p:overlayPanel>
<a:discussionComp discussion="#{displayDiscussionBean}"/>
</h:form>
<p:focus id="focus" context="textdlg"/>
<p:dialog id="textdlg" modal="true" header="Text bubble" appendToBody="true" hideEffect="fade" widgetVar="txt_dlg">
<h:form id="t3">
<p:outputLabel value="Enter your message"/><p:inputText value="#{displayDiscussionBean.txtMsg}"/>
<p:commandButton icon="Post" action="#{displayDiscussionBean.createTextBubble()}" oncomplete="txt_dlg.hide();"/>
</h:form>
</p:dialog>
</h:body>
Here is what my left panel is.
<!--IMPLEMENTATION-->
<cc:implementation>
<h:form id="leftPanel">
<p:dataTable id="disc" value="#{cc.attrs.discussionModel}" var="discussion" style="margin-top: 2px;height: 100%" selectionMode="single" selection="#{discussionBean.selectedDiscussion}" >
<p:ajax event="rowSelect" update=":detail_panel" />
<f:facet name="header">
Discussions
<h:commandLink action="#{discussionBean.createDiscussion()}">
<p:graphicImage id="add" url="/resources/images/plus.png" style="height: 25px;float: right" />
<p:tooltip for="add" value="Add Discussion" style="font-size: 12px" hideEffect="fade"/>
</h:commandLink>
</f:facet>
<p:column style="font-size: 12px;">
#{discussion.title}
</p:column>
</p:dataTable>
</h:form>
</cc:implementation>
My backing bean (displayDiscussionBean) for the create is a SessionScoped bean, and has get and set methods for the txtMsg. However on submit, set method gets fired, but with blank value. Below is the backing bean.
#Named
#SessionScoped
public class DisplayDiscussionBean implements Serializable {
private static final long serialVersionUID = 1L;
#EJB
private DiscussionEJB discussionEJB;
private TextEJB textEJB;
private DiscussionEntity de;
private HashMap<Integer, TextEntity> textMap;
private String selectedOption;
#Inject
private DiscussionBean discussionBean;
private String msg;
private Integer currentBubbleId;
private Integer currentBubbleType = 55;
#Inject
private Locations loc;
private String txtMsg;
private TreeNode root;
private Integer did;
public Integer getDid() {
return did;
}
public void setDid(Integer did) {
this.did = did;
setDetails();
}
public DisplayDiscussionBean() {
}
public DisplayDiscussionBean(Integer id) {
}
private void setDetails() {
de = discussionEJB.getDiscussionDetails(did);
textMap = new HashMap<>();
root = new DefaultTreeNode("Root", null);
Map<Integer, TreeNode> nodeMap = new HashMap<>();
for (BubbleEntity b : de.getBubbleList()) {
TreeNode node = new DefaultTreeNode(b, null);
nodeMap.put(b.getBubbleId(), node);
TextEntity te = (TextEntity) b;
textMap.put(te.getBubbleId(), te);
}
for (BubbleEntity b : de.getBubbleList()) {
if (b.getParentId() != null) {
TreeNode currNode = nodeMap.get(b.getBubbleId());
TreeNode parentNode = nodeMap.get(b.getParentId());
currNode.setParent(parentNode);
} else {
TreeNode currNode = nodeMap.get(b.getBubbleId());
currNode.setParent(root);
}
}
}
public void createTextBubble() {
if (did == null){
did=discussionBean.getSelectedDiscussion().getDiscussionId();
}
textEJB.createTextBubble(txtMsg, did, null);
}
public DiscussionEntity getDe() {
return de;
}
public void setDe(DiscussionEntity de) {
this.de = de;
}
public TreeNode getRoot() {
return root;
}
public void setRoot(TreeNode root) {
this.root = root;
}
public HashMap<Integer, TextEntity> getTextMap() {
return textMap;
}
public void setTextMap(HashMap<Integer, TextEntity> textMap) {
this.textMap = textMap;
}
public String getSelectedOption() {
return selectedOption;
}
public void setSelectedOption(String selectedOption) {
this.selectedOption = selectedOption;
}
public Integer getCurrentBubbleId() {
return currentBubbleId;
}
public void setCurrentBubbleId(Integer currentBubbleId) {
this.currentBubbleId = currentBubbleId;
}
public Integer getCurrentBubbleType() {
return currentBubbleType;
}
public void setCurrentBubbleType(Integer currentBubbleType) {
this.currentBubbleType = currentBubbleType;
}
public String getTxtMsg() {
return txtMsg;
}
public void setTxtMsg(String txtMsg) {
this.txtMsg = txtMsg;
System.out.println("set text msg is "+txtMsg);
}
}
Any suggestioins what am I doing wrong here?
Try using only one form instead. Remove the inner form. I too had a similar issue and removing inner form worked for me.
If that doesn't work try adding 'process' or 'execute' attribute to your button which calls your bean method

JSF UIRepeat and PostBack

I have a simple page where a I use <ui:repeat> and it gets the value from a backing bean.
The initial request will give it an empty list. The postback then will invoke an action that will change the model behind the <ui:repeat> but it is not rendered?!
I debugged through it and I saw that the <ui:repeat> evaluates the value at restore view phase but thats it. When it reaches render response it does not use the latest value from my bean. Is that the expected behavior?
How can I make that work? Do I have to write my own repeat tag?
I can't really tell what could be the problem without some of your code, but these are the basics:
Backing bean:
public class ObjectService{
private DataModel objectDataModel;
private List<Object> objectList;
private Pagination paginationHelper;
private ObjectDao objectDao = new ObjectDao();
private String queryOption;
public void setQueryOption(String queryOption){
this.queryOption = queryOption;
}
public String getQueryOption(){
return this.queryOption;
}
public <E> PaginationHelper getPagination(final List<E> list) {
pagination = new PaginationHelper(10) {
#Override
public int getItemsCount() {
return list.size();
}
#Override
public DataModel createPageDataModel() {
return new ListDataModel(list);
}
};
return pagination;
}
public void setPagination(PaginationHelper pagination) {
this.pagination = pagination;
}
public List<Object> getObjectList(){
this.objectList = objectDao.readObjectsWhere(queryOption);
return this.objectList;
}
public void setObjectList(List<Object> objectList){
this.objectList = objectList;
}
public DataModel getObjectDataModel(){
if (objectDataModel == null) {
objectDataModel = getPagination(getObjectList()).createPageDataModel();
}
return objectDataModel;
}
public void setObjectDataModel(DataModel objectDataModel){
this.objectDataModel = objectDataModel
}
public String changeModel(){
objectDataModel = null;
return null;
}
}
XHTML page:
...
<h:form>
<fieldset>
<label>
<span>Option:</span>
<h:inputText value="#{objectService.queryOption}" />
</label>
<h:commandButton action="#{objectService.changeModel}" value="request data" />
</fieldset>
<ui:repeat value="#{objectService.objectDataModel}" var="objectVar">
<h:outputLabel value="#{objectVar.property1}" />
<h:outputLabel value="#{objectVar.property2}" />
<h:outputLabel value="#{objectVar.property3}" />
</ui:repeat>
</h:form>
...

Resources