I'm using selectOneMenu for displaying some pictures and Strings, the pictures is for displaying purposes only i have (i.e. i have nothing to do with them on submitting) i want only to set the string next to the image, i have a conflict in setting the itemValue of the f:selectItems to the String required, when i do that the images doesn't appear at all, in a word i want to only submit the value of the string in the chosen selectItem without using converter:
JSF Code:
<p:selectOneMenu id="SkinChooser" value="#{personBean.ObjectDTO.personDescription.skin}"
panelStyle="width:150px" effect="fade" var="s"
style="width:160px" converter="#{personBean.converter}">
<f:selectItem itemLabel="Select One" itemValue="" />
<f:selectItems value="#{missedPersonBean.selectedSkins}"
var="skin" itemLabel="#{skin.skinType}" itemValue="#{skin}" />
<p:column>
<p:graphicImage value="/resources/images/skin/#{s.skinPhoto}"
width="40" height="50" />
</p:column>
<p:column>
#{s.skinType}
</p:column>
</p:selectOneMenu>
Skin.Java
public class Skin {
String skinPhoto;
String skinType;
public Skin() {
}
public Skin(String photo, String type) {
this.skinPhoto = photo;
this.skinType = type;
}
public String getSkinPhoto() {
return skinPhoto;
}
public void setSkinPhoto(String skinPhoto) {
this.skinPhoto = skinPhoto;
}
public String getSkinType() {
return skinType;
}
public void setSkinType(String skinType) {
this.skinType = skinType;
}
}
personBean.Java
#ManagedBean(name = "personBean")
#SessionScoped
public class ReportPerson {
private Skin skin;
private static List<Skin> selectedSkins;
static {
System.err.println("Array is filled");
selectedSkins = new ArrayList<Skin>();
selectedSkins.add(new Skin("1", "Pale white"));
selectedSkins.add(new Skin("2", "Fair white"));
selectedSkins.add(new Skin("3", "Light brown"));
selectedSkins.add(new Skin("4", "Moderate brown"));
selectedSkins.add(new Skin("5", "Dark brown"));
selectedSkins.add(new Skin("6", "Deeply pigmented"));
System.err.println("Finished Filling");
}
public List<Skin> getSelectedSkins() {
return selectedSkins;
}
public void setSelectedSkins(List<Skin> selectedSkins) {
this.selectedSkins = selectedSkins;
}
public Skin getSkin() {
return skin;
}
public void setSkin(Skin skin) {this.skin = skin;}
}
Related
this is my code in xhtml and code in backing bean. How can i set the item label ALL value to search all the values.
<h:selectOneRadio value="#{faPrincipiaCntrprtyList.activeFlag}">
<f:selectItem itemLabel="Active" itemValue="1"/>
<f:selectItem itemLabel="InActive" itemValue="0" />
<f:selectItem itemLabel="All" itemValue="????"/>
</h:selectOneRadio>
The below is backing bean
public class FaPrincipiaCntrprtyList extends
FaPrincipiaCntrprtyQuery<FaPrincipiaCntrprty> {
static Logger logger = Logger.getLogger(FaPrincipiaCntrprtyList.class.getName());
private static final long serialVersionUID = 1L;
private byte activeFlag = 1;
/*List<Byte> activeFlagList = new ArrayList<Byte>();
public List<Byte> getActiveFlagList() {
return activeFlagList;
}
public void setActiveFlagList(List<Byte> activeFlagList) {
this.activeFlagList = activeFlagList;
}*/
private static final String EJBQL = "select faPrincipiaCntrprty from FaPrincipiaCntrprty faPrincipiaCntrprty";
private static final String[] RESTRICTIONS = {"lower(faPrincipiaCntrprty.cntrprtyCode) like lower(concat(#{faPrincipiaCntrprtyList.faPrincipiaCntrprty.cntrprtyCode},'%'))",
"faPrincipiaCntrprty.activeFlag = #{faPrincipiaCntrprtyList.activeFlag}",};
private FaPrincipiaCntrprty faPrincipiaCntrprty = new FaPrincipiaCntrprty();
public FaPrincipiaCntrprtyList() {
setEjbql(EJBQL);
setRestrictionExpressionStrings(Arrays.asList(RESTRICTIONS));
setMaxResults(10);
}
public byte getActiveFlag() {
return activeFlag;
}
public void setActiveFlag(byte activeFlag) {
if (activeFlag == 2) {
activeFlag = (Byte) null;
}
/*if (activeFlag == 2) {
activeFlagList.add((byte) 0);
activeFlagList.add((byte) 1);
setActiveFlagList(activeFlagList);
}else{
activeFlagList.add((byte) activeFlag);
setActiveFlagList(activeFlagList);
}*/
this.activeFlag = activeFlag;
}
public FaPrincipiaCntrprty getFaPrincipiaCntrprty() {
return faPrincipiaCntrprty;
}
}
You can set any value to selectAll. Ultimately you are going to match exact value and fetch all records.
Let's say, I have assigned it to value 2,
xhtml
<h:form>
<h:selectOneRadio value="#{faPrincipiaCntrprtyList.activeFlag}">
<f:selectItem itemLabel="Active" itemValue="1"/>
<f:selectItem itemLabel="InActive" itemValue="0" />
<f:selectItem itemLabel="All" itemValue="2"/>
<f:ajax listener="#{faPrincipiaCntrprtyList.processFlagSelection()}" render=":searchResult"/>
</h:selectOneRadio>
</h:form>
<h:panelGroup id="searchResult">
#{faPrincipiaCntrprtyList.searchResult}
</h:panelGroup>
Bean
#ManagedBean
#ViewScoped
public class FaPrincipiaCntrprtyList {
private long activeFlag = 0;
private String searchResult;
public void processFlagSelection() {
if (activeFlag == 2) {
searchResult = "Featch all result from database.";
} else {
searchResult = "Fetch result based on active/inactive";
}
}
//getter and setters
}
Note : This is just for demonstration. Change searchResult type according to your need.
I have a dataTable, containing Package objects with id and phaseList attributes. I would like this dataTable to display package id and its five phases status with some graphicImages like colored circles.
For example: If a package's phase one is completed, the first circle rendered in a progress column is a green one, other four are red ones.
So basically I need to render a circle based on a value from phaseList element attribute. I already accomplished all of this, but it seems to me that there should be some other way. The problem is that I must have five phase color attributes in a backing bean and five getters and setters for those attributes (see code below). In those getters there is very similar code for all five attributes, so I thought I should have just one color attribute and one getter and there should somehow get an information which circle is currently rendered.
Is there any other way (with less duplicated code) to render those circles?
public class Package implements Serializable {
private static final long serialVersionUID = 1L;
private BigDecimal id;
private List<PhaseStatus> phaseList;
public BigDecimal getId() {
return id;
}
public void setId(BigDecimal id) {
this.id = id;
}
public void setPhaseList(List<PhaseStatus> phaseList) {
this.phaseList= phaseList;
}
public List<PhaseStatus> getPhaseList() {
return phaseList;
}
}
PhaseStatus class:
public class PhaseStatus implements Serializable {
private static final long serialVersionUID = 1L;
private BigDecimal phaseId;
private BigDecimal phaseStatus;
private String hint;
public void setPhaseId(BigDecimal phaseId) {
this.phaseId = phaseId;
}
public BigDecimal getPhaseId() {
return phaseId;
}
public void setPhaseStatus(BigDecimal phaseStatus) {
this.phaseStatus = phaseStatus;
}
public BigDecimal getPhaseStatus() {
return phaseStatus;
}
public void setHint(String hint) {
this.hint = hint;
}
public String getHint() {
return hint;
}
}
Xhtml code:
<p:column headerText="Id">
<p:outputLabel value="#{item.id}" />
</p:column>
<p:column headerText="Progress">
<p:commandLink id="lnkPhase1">
<p:graphicImage library="icons" name="#{bean.phaseOneColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint1" for="lnkPhase1" value="#{bean.phaseOneHint}" />
<p:commandLink id="lnkPhase2">
<p:graphicImage library="icons" name="#{bean.phaseTwoColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint2" for="lnkPhase2" value="#{bean.phaseTwoHint}" />
<p:commandLink id="lnkPhase3">
<p:graphicImage library="icons" name="#{bean.phaseThreeColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint3" for="lnkPhase3" value="#{bean.phaseThreeHint}" />
<p:commandLink id="lnkPhase4">
<p:graphicImage library="icons" name="#{bean.phaseFourColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint4" for="lnkPhase4" value="#{bean.phaseFourHint}" />
<p:commandLink id="lnkPhase5">
<p:graphicImage library="icons" name="#{bean.phaseFiveColor}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint5" for="lnkPhase5" value="#{bean.phaseFiveHint}" />
</p:column>
Part of my backing bean:
private String phaseOneColor;
private String phaseTwoColor;
private String phaseThreeColor;
private String phaseFourColor;
private String phaseFiveColor;
private DataTable dtPackages;
one of the getter's:
public String getPhaseOneColor() {
Package myPackage = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = myPackage.getPhaseList();
BigDecimal status = list.get(0).getPhaseStatus();
if (status != null) {
switch (status.intValue()) {
case 1:
phaseOneColor = "green.png";
break;
default:
phaseOneColor = "red.png";
break;
}
} else {
phaseOneColor = "red.png";
}
return phaseOneColor;
}
I'm using PrimeFaces 5.1.
What about something like this
public String getPhaseColor(int phase) {
Package package = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = package.getPhaseList();
BigDecimal status = list.get(phase).getPhaseStatus();
if (status != null) {
switch (status.intValue()) {
case 1:
phaseColor = "green.png";
break;
default:
phaseColor = "red.png";
break;
}
} else {
phaseColor = "red.png";
}
return phaseColor;
}
Similar for tooltips
public String getPhaseTooltip(int phase) {
Package package = (Package) getDtPackages().getRowData();
List<PhaseStatus> list = package.getPhaseList();
BigDecimal status = list.get(phase).getPhaseStatus();
String tooltip = null;
if (status != null) {
switch (status.intValue()) {
case n:
tooltip = "Phase " + phase + " tooltip";
break;
default:
}
} else {
tooltip = "probably error";
}
return tooltip;
}
And you use this in page like this
<p:column headerText="Progress">
<ui:repeat var="phase" value="#{item.phaseList}" varStatus="status">
<p:commandLink id="lnkPhase#{status.index + 1}">
<p:graphicImage library="icons" name="#{bean.getPhaseColor(status.index + 1)}" width="24px" height="24px" />
</p:commandLink>
<p:tooltip id="hint#{status.index + 1}" for="lnkPhase#{status.index + 1}" value="#{bean.getPhaseTooltip(status.index + 1)}" />
</ui:repeat>
</p:column>
There might be some errors in the code since I'm typing it in here directly, but you'll get the idea.
UPDATE
For Java 5 (method invocations with parameters doesn't work), you could do something like this
public Map<Integer, String> getPhaseColors() {
Package package = (Package) getDtPackages().getRowData();
Map<Integer, String> phaseColors = new HashMap<Integer, String>();
if (package != null) {
List<PhaseStatus> list = package.getPhaseList();
for (int i = 0; i < list.size(); i++;) {
BigDecimal ps = list.get(i).getPhaseStatus();
if (ps != null) {
phaseColors.put(i, ps.intValue() == 1 ? "green.png" : "red.png");
} else {
phaseColors.put(i, "red.png");
}
}
}
return phaseColor;
}
<p:graphicImage library="icons" name="#{bean.phaseColors[status.index + 1]}" width="24px" height="24px" />
Similar for tooltips.
I'm using primefaces 4.0.7 .I used selectonemenu,this menu showed the variables however value was null in Bean.Is there any configuration can i do?
Here is part of xhtml code;
<h:outputText value="#{etiketler.kullaniciTipi} : " />
<p:selectOneMenu id="kullaniciTipi" style="width:200px" value="#{kullaniciIslemleriBean.userRole}" >
<f:selectItems value="#{enumBean.kullaniciTipiValues}" var="kullaniciTipi"
itemLabel="#{kullaniciTipi.name}" itemValue="#{kullaniciTipi}" />
</p:selectOneMenu>
here is part of kullaniciIslemleriBean code;
private EnumBase.KullaniciTipi userRole;
public void Kaydet() {
if (userRole == null) {
System.out.println("null value");
return;
}
...
}
public EnumBase.KullaniciTipi getUserRole() {
return userRole;
}
public void setUserRole(EnumBase.KullaniciTipi userRole) {
this.userRole = userRole;
}
Try storing it as String, it will work fine. If you want to store it
as Enum then try converter
<h:outputText value="#{etiketler.kullaniciTipi} : " />
<p:selectOneMenu id="kullaniciTipi" style="width:200px" value="#{kullaniciIslemleriBean.userRole}" >
<f:selectItems value="#{enumBean.kullaniciTipiValues}" var="kullaniciTipi"
itemLabel="#{kullaniciTipi.name}" itemValue="#{kullaniciTipi.name}" />
</p:selectOneMenu>
private String userRole;
public void Kaydet() {
if (userRole == null) {
System.out.println("null value");
return;
}
...
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
Using -Primefaces 3.4 + JSF 2.0-
I am displaying some drop down values from database and the Postconstruct initialize method is not getting invoke implicitly.
Its working when I am calling the init method from other bean.
xhtml code:
<p:panelGrid style="width:50%" styleClass="panelgrid">
<p:row>
<p:column styleClass="columnA" style="width:10%">#{msgs.partTypeTitle}</p:column>
<p:column styleClass="columnB">
<h:selectOneMenu id="partTypeDpDnId" value="#{ppcrDetails.newPpcr.selectedPartType}" style="width:150px;font-size:13px;" >
<f:selectItems value="#{ppcrDetails.newPpcr.partsType}" />
</h:selectOneMenu>
</p:column>
</p:row>
<p:row>
<p:column styleClass="columnA" style="width:25%">#{msgs.familyTitle}</p:column>
<p:column styleClass="columnB">
<h:selectOneMenu id="familyDpDnId" value="#{ppcrDetails.newPpcr.selectedFamilyValues}" style="width:150px;font-size:13px;">
<f:selectItems value="#{ppcrDetails.newPpcr.familyValues}" />
</h:selectOneMenu>
</p:column>
</p:row>
</p:panelGrid>
-Bean:
#ManagedBean(name = "newPpcr" , eager = true)
#SessionScoped
public class NewPpcr implements Serializable {
#PostConstruct
public void initialize() throws QtException {
LOGGER.log(Level.DEBUG, "QuotationTool: NewPpcr initilize.");
partsType.clear();
List<MdPartsType> partList = partsTypeFacade.findAll();
int partSequence = 0;
for (MdPartsType part : partList) {
partsType.add(new SelectItem(partSequence++, part.getPartType()));
}
familyValues.clear();
List<MdFamily> familyList = familyFacade.findAll();
int familySequence = 0;
for (MdFamily family : familyList) {
familyValues.add(new SelectItem(familySequence++, family.getFamily()));
}
}
But this is not working, So I am calling initialize method from other bean then drop down is populating:
#ManagedBean(name = "ppcrDetails", eager = true)
#SessionScoped
public class PpcrDetails implements Serializable{
private List<SelectItem> partType = new ArrayList<SelectItem>();
private List<SelectItem> familyValues = new ArrayList<SelectItem>();
public List<SelectItem> getPartType() {
try {
partType.clear();
if (partType == null || partType.isEmpty()) {
newPpcr.initialize();
this.partType = newPpcr.getPartsType();
}
} catch (QtException e) {
LOGGER.error(e.getMessage(), e);
}
return partType;
}
public void setPartType(List<SelectItem> partType) {
this.partType = partType;
}
public List<SelectItem> getFamilyValues() {
try {
familyValues.clear();
if (familyValues == null || familyValues.isEmpty()) {
newPpcr.initialize();
this.familyValues = newPpcr.getFamilyValues();
}
} catch (QtException e) {
LOGGER.error(e.getMessage(), e);
}
return familyValues;
}
public void setFamilyValues(List<SelectItem> familyValues) {
this.familyValues = familyValues;
}
From this approach I am able to display the values but it is breaking the some functionality.
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