i'm having some questions here. I will appreciate all of your helps.
I'm making some dynamic multilevel menu in primefaces, and i did it. There are parents, sub menus, and the menu items.
I want to give some CRUD action for each component via context menu, so I can edit the value/text for each level just with right-click.
I make the menu with bean called MenussBean.java, and you can see it below (just the correspond code).
public Submenu subMenus(Submenu parentMenus,String i, int id)
{
if(i==""&&parentMenus==null)
{
subList = menusdao.getRootMenu();
for(int a=0;a<subList.size();a++){
parentMenus = new Submenu();
parentMenus.setLabel(subList.get(a).getMenu());
model.addSubmenu(parentMenus);
i=subList.get(a).getMenu();
subMen = null;
id = a+1;
subList2 = subKategori(id);
for(Menus k:subList2){
if(String.valueOf(parentMenus.getLabel().toString()).equals(i)){
subMen = new Submenu();
subMen.setId("_"+k.getId());
subMen.setLabel(k.getMenu());
parentMenus.getChildren().add(subMen);
subMenus(subMen,k.getMenu(),k.getId());
}
}
}
}else{
subMen = null;
subList2 = subKategori(id);
for(Menus k:subList2){
if(String.valueOf(parentMenus.getLabel().toString()).equals(i)){
subList3=subKategori(k.getId());
if(subList3.size()==0)
{
UIParameter uiParam = new UIParameter();
UIParameter menuParam = new UIParameter();
UIParameter idParentParam = new UIParameter();
uiParam.setName("idParam");
uiParam.setValue(k.getId());
menuParam.setName("menuParam");
menuParam.setValue(k.getMenu());
idParentParam.setName("idParentParam");
idParentParam.setValue(k.getId_parent());
MenuItem mi = new MenuItem();
mi.setId("_"+k.getId());
Application app = FacesContext.getCurrentInstance().getApplication();
MethodExpression methodExpr = app.getExpressionFactory().createMethodExpression
(FacesContext.getCurrentInstance().getELContext(), "#{menussBean.onItemClick}", null ,new Class[]{ javax.faces.event.ActionEvent.class});
mi.addActionListener(new MethodExpressionActionListener(methodExpr));
mi.setOncomplete("");
mi.setValue(k.getMenu());
mi.setTarget("_self");
mi.setTitle(k.getLink());
mi.setAjax(false);
mi.getChildren().add(uiParam);
mi.getChildren().add(menuParam);
mi.getChildren().add(idParentParam);
mi.setProcess("#all");
parentMenus.getChildren().add(mi);
}
else if (subList3.size()!=0)
{
subMen = new Submenu();
subMen.setId("_"+k.getId());
subMen.setLabel(k.getMenu());
parentMenus.getChildren().add(subMen);
subMenus(subMen,k.getMenu(),k.getId());
}
}
}
}
return parentMenus;
}
public List<Menus> subKategori(int i)
{
arayList=new ArrayList<Menus>();
for(Menus k:getList()){
if(k.getId_parent()==i){
arayList.add(k);
}
}
return arayList;
}
public static List<Menus> getList() {
return list;
}
This is the value-getter method:
public void onItemClick() {
FacesContext context = FacesContext.getCurrentInstance();
idItem = context.getExternalContext().getRequestParameterMap().get("idParam");
menuItem = context.getExternalContext().getRequestParameterMap().get("menuParam");
idParentItem = context.getExternalContext().getRequestParameterMap().get("idParentParam");
}
And I want to use context menu to give the CRUD operations, so the user can right-click on the component he wants to edit. Here is my xhtml files.
<h:form>
<p:panelMenu id="panel" style="width:400px;font-size:12px"
model="#{menussBean.model}" var="detail" selectionMode="single" ajax="true"
widgetVar = "panelMen" styleClass="myMeineClass">
</p:panelMenu>
<p:contextMenu for="panel" style="font-size:12px">
<p:menuitem value="View" icon="ui-icon-search"
oncomplete="menuDialog.show()" update="display">
<f:param name="id_barangbaru" value="#{detail}" />
</p:menuitem>
<p:menuitem value="Add" icon="ui-icon-plus" />
<p:menuitem value="Edit" icon="ui-icon-pencil" />
<p:menuitem value="Delete" icon="ui-icon-close" />
</p:contextMenu>
<p:dialog header="Menu Detail" widgetVar="menuDialog"
resizable="false" width="200" showEffect="clip" hideEffect="fold"
id="dialog" appendToBody="true" modal="true">
<h:panelGrid id="display" columns="2" cellpadding="4" style="font-size:12px">
<h:outputText value="ID:" />
<h:outputText value="#{menussBean.idItem}"
style="font-weight:bold" />
<h:outputText value="Label:" />
<h:outputText value="#{menussBean.menuItem}"
style="font-weight:bold" />
<h:outputText value="Parent:" />
<h:outputText value="#{menussBean.idParentItem}"
style="font-weight:bold" />
</h:panelGrid>
</p:dialog>
</h:form>
Right now, I'm still getting the value into the context menu output text, but it needs to be left-clicked first. I need to pass the value directly just with right-click.
So, how can I get the value with actionListener with right-click? Please help...
I want to show the screenshot but I'm new here, so I haven't got any reputation.
Related
I need to solve this issue.
I am using jsf primefaces with c:foreach here is my code. but this code is not running.
<p:tab id="catagoryTab" title="#{hardvalue['tutor.reg.tab2']}">
<p:panel header="#{hardvalue['tutor.reg.tab2']}" id="rowCreator">
<h:outputLabel value="#{hardvalue['tutor.reg.selectStmt']}"></h:outputLabel>
<h:panelGrid columns="3" style="width:100%;">
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.collection']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.level']}"/>
<p:outputLabel value="#{hardvalue['tutor.reg.category.table.subject']}"/>
</h:panelGrid>
<c:forEach begin="0" end="#{Registerbean.size -1}" varStatus="loop" var="row">
<h:panelGrid columns="3"
style="width:100%; border: 1px solid #d4f1ff; border-radius: 3px 3px 3px 3px; background:#F7FDFF 50% 50% repeat-x ;">
<p:selectOneMenu
value="#{Registerbean.selectedtutorialType[loop.index]}"
style="font-size:15px !important; width:100px;">
<p:ajax process="#this" update="levellist1_#{loop.index}, levellist2_#{loop.index}, subjectlist_#{loop.index}" event="change"
listener="#{Registerbean.updateRecords(loop.index)}" />
<f:selectItem itemLabel="#{hardvalue['tutor.tutorial']}"
itemValue="tutorial" />
<f:selectItem itemLabel="#{hardvalue['tutor.conversaion']}"
itemValue="conversation" />
<f:selectItem itemLabel="#{hardvalue['tutor.music']}"
itemValue="music" />
<f:selectItem itemLabel="#{hardvalue['tutor.other']}"
itemValue="other" />
</p:selectOneMenu>
<h:panelGrid columns="3" >
<p:selectOneMenu style="width:230px" id="levellist1_#{loop.index}" value="#{Registerbean.selectedtutorialLevelFrom[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
<p:outputLabel value=" #{hardvalue['tutor.reg.to']} " />
<p:selectOneMenu style="width:230px" id="levellist2_#{loop.index}" value="#{Registerbean.selectedtutorialLevelTo[loop.index]}"
>
<f:selectItems value="#{Registerbean.levellist}" />
</p:selectOneMenu>
</h:panelGrid>
<p:selectOneMenu id="subjectlist_#{loop.index}" value="#{Registerbean.selectedtutorialSubject[loop.index]}"
style="width:230px;"
label="#{hardvalue['tutorsearch.select']}" filter="true" filterMatchMode="startsWith"
panelStyle="width:383px">
<f:selectItems value="#{Registerbean.subjectslist}" />
</p:selectOneMenu>
</h:panelGrid>
</c:forEach>
<p:commandButton id="moreButton" value="#{hardvalue['tutor.reg.addmore']}" update="rowCreator" process="#this" actionListener="#{Registerbean.addNewRow}" />
</p:panel>
</p:tab>
The above code is a tab in wizard. So I need to move on the next page after this one.
But I am not able to get the values as it do not let me assign to the array variables using indexes. Here is my backingbean
bean name: #ManagedBean(name="Registerbean")
private Tutor tutor= new Tutor();
private String[] selectedtutorialType= new String[size];
private String[] selectedtutorialLevelFrom= new String[size];
private String[] selectedtutorialLevelTo= new String[size];
private String[] selectedtutorialSubject= new String[size];
public void addNewRow(){
System.out.println("In add row");
size++;
selectedtutorialSubject=selectedtutorialLevelTo= selectedtutorialLevelFrom=selectedtutorialType=new String[size];
}
Here is my flowlistner through which I am just checking about the values of this tab. flowListener="#{Registerbean.onFlowProcess}"
public String onFlowProcess(FlowEvent event) {
System.out.println("tab id is:"+event.getOldStep());
if(event.getOldStep().equalsIgnoreCase("catagoryTab")){
for(int i=0;i<selectedtutorialType.length;i++){
System.out.println("selectedtutorialType : "+selectedtutorialType[i]);
System.out.println("selectedtutorialLevelFrom : "+selectedtutorialLevelFrom[i]);
System.out.println("selectedtutorialLevelTo : "+selectedtutorialLevelTo[i]);
System.out.println("selectedtutorialSubject : "+selectedtutorialSubject[i]);
}
}
return event.getNewStep();
}
What I want is : I want to draw components. on add row A component line will be added here. first one of the component's value changes, it reflacts the values of other two in that row only. but I is not doing the same. As the next button of p:wizard is not allowing me to move upword.
for updates it uses this function of backing bean.
public void updateRecords(int index) {
System.out.println("In update records: "+index);
levellist = new ArrayList<String>();
if (selectedtutorialType[index].equals("tutorial")) {
subjectslist = Arrays.asList(tutorialSubject);
levellist = Arrays.asList(tutorialLevel);
System.out.println("tutorial selection done..");
return;
} else if (selectedtutorialType[index].equals("conversation")) {
subjectslist = Arrays.asList(conversationSubject);
levellist = Arrays.asList(conversationLevel);
System.out.println("Conversation selection done..");
return;
} else if (selectedtutorialType[index].equals("music")) {
subjectslist = Arrays.asList(musicSubject);
levellist = Arrays.asList(musicLevel);
System.out.println("Music selection done..");
return;
} else {
subjectslist = Arrays.asList(otherSubject);
levellist = Arrays.asList(otherLevel);
System.out.println("Other selection done..");
return;
}
}
What to do. Plz help. Any other detail for this, if I am missing, let me know.
Thanks
I have jsf page :
<p:contextMenu for="treeProfileSetEvent"
nodeType="PROFILESET">
<p:menuitem value="#{lang['common.button.add']}"
icon="ui-icon-plus"
update="#([id$=editPanel_event])"
actionListener="#{profileSetEventController.prepareAdd()}">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}" value="#{vpcrfConst.BTN_ADD}" />
</p:menuitem>
<p:menuitem value="#{lang['common.button.delete']}"
icon="ui-icon-close"
update="#([id$=btnPanel]) #([id$=treeProfileSetEvent]) #([id$=msgInfo])"
actionListener="#{profileSetEventController.prepareDelete()}"
oncomplete="PF('deleteDialog').show()">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_DELETE}" />
</p:menuitem>
</p:contextMenu>
<p:contextMenu for="treeProfileSetEvent"
nodeType="PARENT">
<p:menuitem value="#{lang['common.button.edit']}"
icon="ui-icon-pencil"
update="#([id$=editPanel_profileSetEvent])"
actionListener="#{profileSetEventController.prepareEdit()}">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_EDIT}" />
</p:menuitem>
<p:menuitem value="#{lang['common.button.delete']}"
icon="ui-icon-close"
update="#([id$=btnPanel]) #([id$=treeProfileSetEvent]) #([id$=msgInfo])"
actionListener="#{profileSetEventController.prepareDelete()}"
oncomplete="PF('deleteDialog').show()">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_DELETE}" />
</p:menuitem>
</p:contextMenu>
<p:contextMenu for="treeProfileSetEvent"
nodeType="PARENT_HAS_CHILD">
<p:menuitem value="#{lang['common.button.delete']}"
icon="ui-icon-close"
ajax="true"
update="#([id$=btnPanel]) #([id$=treeProfileSetEvent]) #([id$=msgInfo])"
actionListener="#{profileSetEventController.prepareDelete()}"
oncomplete="PF('deleteDialog').show()">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_DELETE}" />
</p:menuitem>
</p:contextMenu>
<p:contextMenu for="treeProfileSetEvent"
nodeType="CHILD">
<p:menuitem value="#{lang['common.button.edit']}"
icon="ui-icon-pencil"
update="#([id$=editPanel_profileSetEvent])"
actionListener="#{profileSetEventController.prepareEdit()}">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_EDIT}" />
</p:menuitem>
<p:menuitem value="#{lang['common.button.delete']}"
icon="ui-icon-close"
update="#([id$=btnPanel]) #([id$=treeProfileSetEvent]) #([id$=msgInfo])"
actionListener="#{profileSetEventController.prepareDelete()}"
oncomplete="PF('deleteDialog').show()">
<f:setPropertyActionListener target="#{profileSetEventController.formStatus}"
value="#{vpcrfConst.BTN_DELETE}" />
</p:menuitem>
</p:contextMenu>
<p:tree id="treeProfileSetEvent"
value="#{profileSetEventController.root}"
selection="#{profileSetEventController.selectedNode}"
dynamic="true"
selectionMode="single"
animate="true"
cache="true"
var="ps"
styleClass="vpcrf-tree-50pc">
<p:ajax event="select" listener="#{profileSetEventController.onNodeSelectListener}" update="#([id$=btnPanel]) #([id$=dlgProfileSetEvent])" />
<p:ajax event="expand" listener="#{profileSetEventController.onNodeExpandListener}" update="#([id$=btnPanel]) #([id$=dlgProfileSetEvent])" />
<p:treeNode id="parentNode"
icon="vpcrf-icon-profile"
type = "PROFILESET">
<h:outputText value="#{ps}" title="#{ps}"
styleClass="vpcrf-txt-400" />
</p:treeNode>
<p:treeNode id="eventParent" icon="vpcrf-icon-event-parent" type = "PARENT">
<h:outputText value="#{ps}" title="#{ps}"
styleClass="vpcrf-txt-400" />
</p:treeNode>
<p:treeNode id="eventParentHasChild" icon="vpcrf-icon-event-parent" type = "PARENT_HAS_CHILD">
<h:outputText value="#{ps}" title="#{ps}"
styleClass="vpcrf-txt-400" />
</p:treeNode>
<p:treeNode icon="vpcrf-icon-event-child" type = "CHILD">
<h:outputText value="#{ps}" title="#{ps}"
styleClass="vpcrf-txt-400" />
</p:treeNode>
</p:tree>
And the controller :
public void onNodeSelectListener(NodeSelectEvent e) {
try {
selectedNode = e.getTreeNode();
if (selectedNode.getData() instanceof ProfileSetDTO) {
selectedProfileSet = (ProfileSetDTO) selectedNode.getData();
} else {
event = (EventDTO) selectedNode.getData();
System.out.println(event.getEventName());
}
profileSet = null;
formStatus = Const.CLEAR;
} catch (Exception ex) {
reportError("msgInfo", "msg.error.unknown");
logger.error(ex, ex);
}
}
The problem is ajax event select only fire when I left-click on treenode, when right-click it doesn't work. Is there any way to make it work when I right-click on node ? Any help would be great.
On Primefaces 5.x (I'm using 5.1, but should work also on newer versions), you should be able to solve your issue by adding an ajax event related to contextMenu in the JSF page, as follows:
<p:ajax event="contextMenu" listener="#{profileSetEventController.onNodeSelectListener}" update="#([id$=btnPanel]) #([id$=dlgProfileSetEvent])" />
I tend to prefer this solution to the one already posted (the one that "overrides" the Primefaces onRightClick function) for three reasons.
First, there is no need to modify the Primefaces javascript (what if a newer version changes something about it? It's likely that, in this case, you have to modify your custom script!)
Second, you may want to separate the behavior of the listener onNodeSelectListener depending on which click (left or right) is fired by using e.isContextMenu() in the backing bean, so the controller may become something like:
public void onNodeSelectListener(NodeSelectEvent e) {
if (e.isContextMenu()) {
// right click has been fired
} else {
// left click has been fired
}
}
The second parameter true in this.selectNode(d, true) of the Primefaces script nodeRightClick serves exactly this purpose. In other words, by using this.selectNode(d) (as the overriding script does), it will be not possible to decide whether the listener has been invoked by a left or a right click.
Last, you may want to use a different listener (onRightClickSelectListener) for the two events (select and contextMenu) in the JSF page, as follows:
<p:ajax event="select" listener="#{profileSetEventController.onNodeSelectListener}" update="#([id$=btnPanel]) #([id$=dlgProfileSetEvent])" />
<p:ajax event="contextMenu" listener="#{profileSetEventController.onRightClickSelectListener}" update="#([id$=btnPanel]) #([id$=dlgProfileSetEvent])" />
and consequentely in the backing bean, as:
public void onNodeSelectListener(NodeSelectEvent e) {
// called when a select event occurs
}
public void onRightClickSelectListener(NodeSelectEvent e) {
// called when a contextMenu event occurs
}
Therefore using a contextMenu event only for the right click, instead of using select event for both clicks, may be a cleaner approach anyway.
Hope that helps.
I think you are facing the same problem I was having. I still don't get why this is working in the PrimeFaces showcase, but I was able to fix it by replacing PrimeFaces' nodeRightClick handler (JavaScript):
PrimeFaces.widget.BaseTree.prototype.nodeRightClick = function(e, a) {
PrimeFaces.clearSelection();
if ($(e.target).is(":not(.ui-tree-toggler)")) {
var d = a.parent(), b = a.hasClass("ui-tree-selectable");
if (b && this.cfg.selectionMode) {
var c = this.isNodeSelected(d);
if (!c) {
if (this.isCheckboxSelection()) {
this.toggleCheckboxNode(d)
} else {
this.unselectAllNodes();
// Fixed right click selecting
// original code: this.selectNode(d, true)
this.selectNode(d); // <-- Fix
}
}
this.fireContextMenuEvent(d)
}
}
}
I'm working with JSF Primefaces and I want to make a search and show results in but results won't show, I'm doing this with Result type and had implemented like this in JSF 2.1 whith MyFaces tomahawk, but now with primefaces this doesn't work, here is my code
<h:form id="buscar_sucursal">
<p:panel style="width: 800px">
<h:panelGrid columns="5">
<h:outputText value="Criterio: " />
<p:selectOneMenu id="citerio" value="#{SucursalesBean.criterio}">
<f:selectItem itemValue="1" itemLabel="CVE SUCURSAL"></f:selectItem>
<f:selectItem itemValue="2" itemLabel="NOMBRE"></f:selectItem>
</p:selectOneMenu>
<h:outputText value="Valor: " />
<p:inputText id="valor" value="#{SucursalesBean.valor}"></p:inputText>
<p:commandButton action="#{SucursalesBean.buscar}" value="Buscar"></p:commandButton>
</h:panelGrid>
</p:panel>
<p:dataTable id="sucursalesTable" var="suc" value="#{SucursalesBean.sucursalesTable}">
<p:column headerText="Id">
<h:outputText value=""></h:outputText>
</p:column>
<p:column headerText="Cve">
<h:outputText value="#{suc.cve_sucursal}"></h:outputText>
</p:column>
<p:column headerText="Sucursal">
<h:outputText value="#{suc.sucursal}"></h:outputText>
</p:column>
<p:column headerText="Domicilio">
</p:column>
<p:column headerText="ContraseƱa">
</p:column>
<p:column headerText="Accion">
<h:commandLink value="Editar"></h:commandLink> /
<h:commandLink value="Eliminar"></h:commandLink>
</p:column>
</p:dataTable>
</h:form>
And the code of my ManagedBean
public Result getSucursalesTable()
{
return this.sucursalesTable;
}
public void setSucursalesTable(Result sucursalesTable)
{
this.sucursalesTable = sucursalesTable;
}
public void buscar() throws ClassNotFoundException
{
HttpServletRequest request = (HttpServletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
this.valor = request.getParameter("buscar_sucursal:valor");
try
{
LoginBean loginBean = (LoginBean) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("LoginBean");
Connection conn = loginBean.getConectar_db();
//int id_empresa = loginBean.getId_empresa();
ArrayList<SucursalesBean> al = new ArrayList<SucursalesBean>();
st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
//ResultSet rs = st.executeQuery("SELECT *FROM clientes WHERE id_cliente='"+request.getParameter("id_cliente")+"';"); // AND id_contribuyente='' AND id_empresa=''
//if(request.getParameter("sucursales:id_sucursal") != null)
//rs = st.executeQuery("SELECT *FROM sucursales WHERE id_sucursal='"+request.getParameter("sucursales:id_sucursal")+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';"); // AND id_contribuyente='' AND id_empresa=''
if(getCriterio().toString() != null)
{
if(getCriterio().toString().equals("1"))
rs = st.executeQuery("SELECT cve_sucursal,sucursal FROM sucursales WHERE cve_sucursal='"+this.valor+"' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
if(getCriterio().toString().equals("2"))
rs = st.executeQuery("SELECT *FROM sucursales WHERE sucursal LIKE '%"+this.valor+"%' AND id_empresa='"+loginBean.getId_empresa()+"' AND id_contribuyente='"+loginBean.getId_contribuyente()+"';");
}
this.sucursalesTable = ResultSupport.toResult(rs);
//this.sucursalesTable = rs;
//setSucursalesTable(ResultSupport.toResult(rs));
/*while(rs.next())
{
//out.println("<tr><td>"+rs.getString("sucursal")+"</td><td>"+rs.getString("cve_sucursal")+"</td><td>"+rs.getString("telefono")+"</td><td>"+rs.getString("e_mail")+"</td><td>"+rs.getString("calle")+"</td><td><a href='sucursales.jsp?accion=editar&id_sucursal="+rs.getString("id_sucursal")+"'>Editar</a></td><td></td></tr>");
//setId_sucursal(String.valueOf(rs.getInt("id_sucursal")));
setCve_sucursal(rs.getString("cve_sucursal"));
setSucursal(rs.getString("sucursal"));
al.add(this);
}
this.sucursalesTable = al;*/
}
catch(SQLException ex)
{
}
}
I don't want to use serialized objects in order to use List type because I think it's to much code for doing something that supposed to be simple, even if this it's not the best aproach.
My doubt it's if Primefaces has support for Result type or am I lost with this and maybe that's why this aproach isn't working.
Any help I really appreciate thank in advance
It looks to me as you've converted a h:commandButton to p:commandButton. The first by default uses non-ajax request, but the latter uses an ajax request. If correct, you just need to tell the button which components to process during and update after the request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
process="criterio valor"
update="sucursalesTable" />
Or use a non-ajax request:
<p:commandButton action="#{SucursalesBean.buscar}"
value="Buscar"
ajax="false" />
I try to update my PanelGrid from my CommandButton with update attribute, but it doesn't work:
<h:body>
<p:dialog id="dialog" header="Add Memo" widgetVar="dialogMemo" resizable="false" >
<h:form id="formDialog">
<h:panelGrid columns="2" cellpadding="5">
<h:outputLabel for="commentInput" value="Comment:" />
<p:inputTextarea id="commentInput" value="#{dashboardBean.currentComment}" rows="6" cols="25" label="commentInput" required="true"/>
<p:watermark for="commentInput" value="Enter your memo..."/>
<h:outputLabel for="selectShare" value="Share Memo: " />
<p:selectBooleanCheckbox id="selectShare" />
<h:outputLabel for="choosePriority" value="Priority:" />
<p:selectOneMenu id="choosePriority" value="#{dashboardBean.currentPriority}" label="choosePriority">
<f:selectItem itemLabel="Low Priority" itemValue="1" />
<f:selectItem itemLabel="Medium Priority" itemValue="2" />
<f:selectItem itemLabel="High Priority" itemValue="3" />
</p:selectOneMenu>
<p:commandButton id="submitDialog" icon="ui-icon-check" value="Confirm" update=":formPanel:myPanelGrid" oncomplete="dialogMemo.hide();" type="submit">
</p:commandButton>
<p:commandButton icon="ui-icon-close" onclick="dialogMemo.hide();" value="Cancel"/>
</h:panelGrid>
</h:form>
</p:dialog>
<p:layout fullPage="true">
<p:layoutUnit id="leftPanel" position="west" size="250" header="My Memos" resizable="false" closable="false" collapsible="false">
<h:form id="formPanel">
<p:commandButton id="addMemo" icon="ui-icon-plus" onclick="dialogMemo.show();" type="submit" actionListener="#{dashboardBean.getEditControl}"/>
<h:panelGrid id="myPanelGrid" columns="1" width="100%" >
</h:panelGrid>
</h:form>
</p:layoutUnit>
</h:body>
I set the actionListener of my commandButton("submitDialog") dynamically, when i click to commandButton("addMemo").
The method is properly called, but the panelGrid("myPanelgrid") is not updated.
When i reload the page all components are properly displayed. But for me the update attribute of "submitDialog" is correctly set.
My methods to add panels dynamically,the first is called in postConstruct method(component is displayed correctly) and the second is called in commandButton("SubmitDialog") actionListener(Panelgrid is not Updated):
public void createMemoList()
{
if (panelGridUI != null && _countMemos > 0)
{
for (int i = 0; _countMemos > i; i++)
{
int u = _memosId.get(i);
Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
AjaxBehavior ajaxBehavior = new AjaxBehavior();
Draggable draggable = new Draggable();
panel.setId("mymemo_" + String.valueOf(u));
panel.setHeader(_userNames.get(i));
panel.setClosable(true);
panel.setToggleable(true);
HtmlOutputText memo = new HtmlOutputText();
memo.setValue(_userMemos.get(i));
memo.setId("text_" + String.valueOf(u));
panel.getChildren().add(memo);
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId("group_" + u);
CommandButton button = new CommandButton();
button.setIcon("ui-icon-pencil");
button.addActionListener(new MethodExpressionActionListener(editExpression));
button.setOnclick("dialogMemo.show()");
button.setStyle("width:20px;height:20px;margin-right:5px;");
HtmlOutputText header = new HtmlOutputText();
header.setValue(_userNames.get(i));
header.setStyle("font-size:15px;");
panelGroup.getChildren().add(button);
panelGroup.getChildren().add(header);
panel.getFacets().put("header", panelGroup);
ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));
panel.addClientBehavior("close", ajaxBehavior);
draggable.setFor("mymemo_" + String.valueOf(u));
draggable.setRevert(true);
draggable.setHandle(".ui-panel-titlebar");
draggable.setStack(".ui-panel");
getPanelGrid().getChildren().add(panel);
getPanelGrid().getChildren().add(draggable);
}
}
}
public void createLastMemo()
{
if (panelGridUI != null && _countMemos > 0)
{
int u = _memosId.get(_countMemos - 1);
Panel panel = (Panel)_application.createComponent(FacesContext.getCurrentInstance(), "org.primefaces.component.Panel", "org.primefaces.component.PanelRenderer");
MethodExpression editExpression = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleEdit}", Void.class, new Class[]{ActionEvent.class});
MethodExpression me = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{panelListener.handleClose}", null, new Class[]{AjaxBehaviorEvent.class});
AjaxBehavior ajaxBehavior = new AjaxBehavior();
Draggable draggable = new Draggable();
panel.setId("mymemo_" + String.valueOf(u));
panel.setHeader(_userNames.get(_countMemos - 1));
panel.setClosable(true);
panel.setToggleable(true);
HtmlOutputText memo = new HtmlOutputText();
memo.setValue(_userMemos.get(_countMemos - 1));
memo.setId("text_" + String.valueOf(u));
panel.getChildren().add(memo);
HtmlPanelGroup panelGroup = new HtmlPanelGroup();
panelGroup.setId("group_" + String.valueOf(u));
CommandButton button = new CommandButton();
button.setIcon("ui-icon-pencil");
button.addActionListener(new MethodExpressionActionListener(editExpression));
button.setOnclick("dialogMemo.show()");
button.setStyle("width:20px;height:20px;margin-right:5px;");
HtmlOutputText header = new HtmlOutputText();
header.setValue(_userNames.get(_countMemos - 1));
header.setStyle("font-size:15px;");
panelGroup.getChildren().add(button);
panelGroup.getChildren().add(header);
panel.getFacets().put("header", panelGroup);
ajaxBehavior.addAjaxBehaviorListener(new AjaxBehaviorListenerImpl(me, me));
panel.addClientBehavior("close", ajaxBehavior);
draggable.setFor("mymemo_" + String.valueOf(u));
draggable.setRevert(true);
draggable.setHandle(".ui-panel-titlebar");
draggable.setStack(".ui-panel");
getPanelGrid().getChildren().add(panel);
getPanelGrid().getChildren().add(draggable);
}
}
And this method is where i set the actionListener to my commandButton("addMemo")
:
public void getEditControl()
{
System.out.println("I am in getEditContol!!!");
UIViewRoot view = FacesContext.getCurrentInstance().getViewRoot();
CommandButton button = (CommandButton) view.findComponent("formDialog:submitDialog");
for(ActionListener act : button.getActionListeners()) {
button.removeActionListener(act);
}
MethodExpression getLastmemo = _ef.createMethodExpression(FacesContext.getCurrentInstance().getELContext(), "#{dashboardBean.getLastMemo}", Void.class, new Class[]{ActionEvent.class});
button.addActionListener(new MethodExpressionActionListener(getLastmemo));
}
My MethodExpression("getLastMemo") call my method createLastmemo. ActionListener is correctly called, but the view is not updated. I am in ViewScoped.
I have a jsf page that I can't update the value of some checkboxes in a list of userDamain objects, in fact this is a part of my jsf page :
<h:outputText value="USER's rights list: "></h:outputText>
<p:dataTable id="userss" var="userr" value="#{userMB.userListe}">
<p:column>
<f:facet name="header"><h:outputText value="FirstName" /></f:facet>
<h:outputText value="#{userr.firstName}" />
</p:column>
<p:column>
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Basic Usage: " />
<p:selectBooleanCheckbox value="#{userr.deletee}" immediate="true" actionListener="#{userr.deletee}" />
</h:panelGrid>
<p:commandButton value="Submit" update="display" oncomplete="dlg.show()" />
<p:dialog header="Selected Values" modal="true" showEffect="fade" hideEffect="fade" widgetVar="dlg">
<h:panelGrid columns="1" id="display">
<h:outputText value="Value 1: #{userr.deletee}" />
</h:panelGrid>
</p:dialog>
</p:column>
when I click on the boolean button 'Submit', the value of the userr.deletee is always false ( the default value ) and it's not updated anyway, I tried to use the Listner and actionListener in the booleanButton but it doesn't work, I also tried the postValidate event, so if someone has any idea of that, I would be graceful.
this is a part of my managed bean:
private List<UserDomain> userListe ;
public List<UserDomain> getUserListe() {
return this.userListe;
}
public void loadUserListe(){
this.userListe = new ArrayList<UserDomain>();
this.userListe.addAll(getUserServicee().getAll());
}
public void setUserListe(List<UserDomain> userListe) {
this.userListe = userListe;
}
a part of the userDomain bean:
...
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
#Transient
private boolean deletee;
public boolean isDeletee() {
return deletee;
}
public void setDeletee(boolean deletee) {
this.deletee = deletee;
}
I found out a solution which seems logic to me, I added to my checkbox an ajax behavior to execute a method and an attribute which called in this method to get the whole userDomain object, so on I can get the user.deletee value, here is a part of the code I m talking about:
<h:panelGrid columns="1" style="margin-bottom:10px" cellpadding="5">
<h:outputText value="Delete Right: " />
<p:selectBooleanCheckbox value="#{userr.deletee}">
<f:ajax execute="#this" listener="#{userMB.saveUserRights}" />
<f:attribute name="user" value="#{userr}" />
</p:selectBooleanCheckbox>
</h:panelGrid>
I hope this will be helpful for you